Commit 8d5df8ca authored by Ivan Tyagov's avatar Ivan Tyagov

Add a shorthand way to bind to Gadgets' ready event.

Use for this internally root dom element.
parent 4c1b743d
...@@ -149,6 +149,13 @@ var RenderJs = (function () { ...@@ -149,6 +149,13 @@ var RenderJs = (function () {
is_ready = value; is_ready = value;
}, },
bindReady: function (ready_function) {
/*
* Bind a function on ready gadget loading.
*/
$("body").one("ready", ready_function);
},
checkAndTriggerReady: function () { checkAndTriggerReady: function () {
/* /*
* Trigger "ready" event only if all gadgets were marked as "ready" * Trigger "ready" event only if all gadgets were marked as "ready"
...@@ -157,8 +164,11 @@ var RenderJs = (function () { ...@@ -157,8 +164,11 @@ var RenderJs = (function () {
is_gadget_list_loaded = RenderJs.GadgetIndex.isGadgetListLoaded(); is_gadget_list_loaded = RenderJs.GadgetIndex.isGadgetListLoaded();
if (is_gadget_list_loaded) { if (is_gadget_list_loaded) {
if (!RenderJs.isReady()) { if (!RenderJs.isReady()) {
// backwards compatability with already written code
RenderJs.GadgetIndex.getRootGadget().getDom(). RenderJs.GadgetIndex.getRootGadget().getDom().
trigger("ready"); trigger("ready");
// trigger ready on root body element
$("body").trigger("ready");
RenderJs.setReady(true); RenderJs.setReady(true);
} }
} }
...@@ -555,14 +565,13 @@ $(document).ready(function () { ...@@ -555,14 +565,13 @@ $(document).ready(function () {
// Be careful, right now we can be in this case because // Be careful, right now we can be in this case because
// asynchronous gadget loading is not finished // asynchronous gadget loading is not finished
if (root_gadget !== undefined) { if (root_gadget !== undefined) {
root_gadget.getDom().bind("ready", RenderJs.bindReady(
function () { function () {
// examine all Intaction Gadgets and bind accordingly // examine all Intaction Gadgets and bind accordingly
$("div[data-gadget-connection]").each( function(index, element) { $("div[data-gadget-connection]").each( function(index, element) {
RenderJs.InteractionGadget.bind($(element)); RenderJs.InteractionGadget.bind($(element));
}) })
} });
);
} }
} }
}); });
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