Commit a8f1951c authored by Ivan Tyagov's avatar Ivan Tyagov

Factorize code. Make sure a JSON gadget can contain child nodes.

parent d1919ba0
......@@ -28,6 +28,13 @@ var RenderJs = (function () {
// a variable indicating if current gadget loading is over or not
var is_ready = false, current_gadget;
function setSelfGadget (gadget) {
/*
* Only used internally to set current gadget being executed.
*/
current_gadget = gadget;
}
return {
init: function () {
......@@ -103,10 +110,10 @@ var RenderJs = (function () {
* gadgets.
*/
// set current gadget as being loaded so gadget instance itself knows which gadget it is
current_gadget = RenderJs.GadgetIndex.getGadgetById(gadget.attr("id"));
setSelfGadget(RenderJs.GadgetIndex.getGadgetById(gadget.attr("id")));
gadget.append(data);
// reset as no longer current gadget
current_gadget = undefined;
setSelfGadget(undefined);
// a gadget may contain sub gadgets
RenderJs.loadRecursiveGadget(gadget);
},
......@@ -680,15 +687,16 @@ var RenderJs = (function () {
/*
* Inspect DOM and initialize this gadget
*/
var dom_list;
var dom_list, gadget_id;
if (force===1) {
// we explicitly want to re-init elements even if already this is done before
dom_list = $("div[data-gadget-connection]");
}
else {
// XXX: improve and save 'bound' on javascript representation of a gadget not DOM
dom_list = $("div[data-gadget-connection]")
.filter(function() { return $(this).data("bound") !== true; })
.data('bound', true )
.data('bound', true );
}
dom_list.each(function (index, element) {
RenderJs.InteractionGadget.bind($(element));});
......@@ -811,10 +819,10 @@ var RenderJs = (function () {
method_id = gadget_route.destination.split('.')[1],
gadget = RenderJs.GadgetIndex.getGadgetById(gadget_id);
// set gadget value so getSelfGadget can work
current_gadget = gadget;
setSelfGadget(gadget);
gadget[method_id].apply(null, arguments);
// reset as no longer needed
current_gadget = undefined;
setSelfGadget(undefined);
};
// add route itself
priority = gadget_route.priority;
......
......@@ -200,7 +200,7 @@ function setupRenderJSTest(){
module("GadgetDataHandler");
test('GadgetDataHandler', function () {
cleanUp();
$("#qunit-fixture").append('<div data-gadget="" id="json-gadget" data-gadget-source = "json/json_file.json" data-gadget-handler="parseJSONAndUpdateNameSpace"></div>');
$("#qunit-fixture").append('<div data-gadget="" id="json-gadget" data-gadget-source = "json/json_file.json" data-gadget-handler="parseJSONAndUpdateNameSpace"><p>some content</p></div>');
RenderJs.bootstrap($("#qunit-fixture"));
equal('', first_name);
equal('', last_name);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment