Commit 4fdcc595 authored by Sven Franck's avatar Sven Franck

renderJS: add check to prevent gadgets from multiple insertions or not being loaded

parent 11d56a4b
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
</head> </head>
<body> <body>
<div data-role="page"> <div data-role="page" id="index">
<div data-role="header"> <div data-role="header">
<h1>Example 3</h1> <h1>Example 3</h1>
</div> </div>
......
...@@ -11,7 +11,6 @@ define([], function () { ...@@ -11,7 +11,6 @@ define([], function () {
$(document).on('pagebeforeshow','div:jqmData(role="page")', function () { $(document).on('pagebeforeshow','div:jqmData(role="page")', function () {
// renderJS handler
RenderJs.init(); RenderJs.init();
RenderJs.bindReady( RenderJs.bindReady(
function () { function () {
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
</head> </head>
<body> <body>
<div data-role="page"> <div data-role="page" id="page2">
<div data-role="header"> <div data-role="header">
<h1>Example 3 - Page 2</h1> <h1>Example 3 - Page 2</h1>
</div> </div>
......
...@@ -58,16 +58,19 @@ var RenderJs = (function () { ...@@ -58,16 +58,19 @@ var RenderJs = (function () {
* Load all gadgets for this DOM element * Load all gadgets for this DOM element
* (including recursively contained ones) * (including recursively contained ones)
*/ */
var gadget_id, is_gadget; var all_gadgets_on_root = root.find("[data-gadget]"), i,
gadget_id = root.attr("id"); gadget_id, gadget;
is_gadget = root.attr("data-gadget") !== undefined;
// this will make RenderJs fire "ready" event when all gadgets are loaded. // this will make RenderJs fire "ready" event when all gadgets are loaded.
RenderJs.setReady(false); RenderJs.setReady(false);
if (is_gadget && gadget_id !== undefined ) { for (i = 0; i < all_gadgets_on_root.length; i += 1) {
// bootstart root gadget only if it is indeed a gadget gadget = $(all_gadgets_on_root[i]);
RenderJs.loadGadget(root); gadget_id = gadget.attr("id");
if (gadget_id !== undefined) {
// bootstart root gadget only if it is indeed a gadget
RenderJs.loadGadget(gadget);
}
} }
RenderJs.loadRecursiveGadget(root);
}, },
loadRecursiveGadget: function (root) { loadRecursiveGadget: function (root) {
...@@ -106,11 +109,26 @@ var RenderJs = (function () { ...@@ -106,11 +109,26 @@ var RenderJs = (function () {
/* /*
* Load gadget's SPECs from URL * Load gadget's SPECs from URL
*/ */
var url, gadget_id, gadget_property, cacheable, cache_id, var url, gadget_id, gadget_property, cacheable, cache_id, i,
gadget_index, gadget_index_id,
app_cache, data, gadget_js, is_update_gadget_data_running; app_cache, data, gadget_js, is_update_gadget_data_running;
url = gadget.attr("data-gadget"); url = gadget.attr("data-gadget");
gadget_id = gadget.attr("id"); gadget_id = gadget.attr("id");
gadget_js = RenderJs.GadgetIndex.getGadgetById(gadget_id); gadget_js = RenderJs.GadgetIndex.getGadgetById(gadget_id);
gadget_index = RenderJs.GadgetIndex.getGadgetList();
for (i = 0; i < gadget_index.length; i += 1) {
gadget_index_id = gadget_index[i].id;
// stop here, if the gadget_id is already on the gadgetIndex
// but not when the gadget on the page has no childNodes
// (because it's back to unenhanced status = page reload)
if (gadget_index_id === gadget_id &&
document.getElementById(gadget_index_id).hasChildNodes()
) {
return;
}
}
if (gadget_js === undefined) { if (gadget_js === undefined) {
// register gadget in javascript namespace if not already registered // register gadget in javascript namespace if not already registered
gadget_js = new RenderJs.Gadget(gadget_id, gadget); gadget_js = new RenderJs.Gadget(gadget_id, gadget);
...@@ -179,6 +197,8 @@ var RenderJs = (function () { ...@@ -179,6 +197,8 @@ var RenderJs = (function () {
} }
}); });
} }
// labelled
gadget_js.status = "rendered";
} }
else { else {
// gadget is an inline (InteractorGadget or one using // gadget is an inline (InteractorGadget or one using
......
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