Commit a7997708 authored by Ivan Tyagov's avatar Ivan Tyagov

Make sure Gadget's ready event works. Add test for it.

Use ready event in example instead of hard coded timeouts.
parent c72fbd99
......@@ -35,12 +35,8 @@
<script type="text/javascript" language="javascript">
//<![CDATA[
$(document).ready(function() {
// XXX: using setTimeout is ugly, see non working example below to be fixed
window.setTimeout(function () {
RenderJs.InteractionGadget.bind($("#main-interactor"));}, 1000);
// RenderJs.GadgetIndex.getRootGadget().getDom().bind("ready", function () {
// RenderJs.InteractionGadget.bind($("#main-interactor"));});
RenderJs.GadgetIndex.getRootGadget().getDom().bind("ready", function () {
RenderJs.InteractionGadget.bind($("#main-interactor"));});
});
//]]>
......
......@@ -28,7 +28,11 @@ var RenderJs = (function () {
return {
bootstrap: function (root) {
/* initial load application gadget */
gadget_id = root.attr("id");
if (gadget_id!==undefined) {
// bootstart root gadget only if it is indeed a gadget
RenderJs.loadGadgetFromUrl(root);
}
RenderJs.load(root);
},
......@@ -55,7 +59,6 @@ var RenderJs = (function () {
app_cache, data, gadget_js;
url = gadget.attr("data-gadget");
gadget_id = gadget.attr("id");
// register gadget in javascript namespace
gadget_js = new RenderJs.Gadget(gadget_id, gadget);
RenderJs.GadgetIndex.registerGadget(gadget_js);
......@@ -152,7 +155,6 @@ var RenderJs = (function () {
trigger("ready");
RenderJs.setReady(true);
}
//is_ready = true;
}
return is_gadget_list_loaded;
},
......
......@@ -77,7 +77,7 @@ function setupRenderJSTest(){
stop();
// we need to wait for all gadgets loading ...
window.setTimeout(function () {
RenderJs.GadgetIndex.getRootGadget().getDom().bind("ready", function () {
RenderJs.InteractionGadget.bind($("#main-interactor"));
start();
equal(0, counter);
......@@ -87,7 +87,22 @@ function setupRenderJSTest(){
// fire pure HTML event on A and test it calls respective B method
$('#A').trigger('htmlEvent1');
equal(3, counter);
}, 500);
});
});
module("GadgetReadyEvent");
test('GadgetReadyEvent', function () {
cleanUp();
RenderJs.addGadget("qunit-fixture", "interactions/index.html", "", "");
stop();
// we need to wait for all gadgets loading ...
RenderJs.GadgetIndex.getRootGadget().getDom().bind("ready", function () {
start();
equal(true, RenderJs.GadgetIndex.isGadgetListLoaded());
equal(true, RenderJs.isReady());
});
});
};
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