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