Commit 141f1e6e authored by Ivan Tyagov's avatar Ivan Tyagov

Rather than call a hard coded function allow RouteGadget to call any

executable function from RouteGadget.
Extend tests to follow change above. Add InteractionGadget to show how
RouteGadget works with InteractionGadget in example.
parent 1ea9d105
...@@ -15,8 +15,8 @@ ...@@ -15,8 +15,8 @@
<div data-gadget="" <div data-gadget=""
id="main-router" id="main-router"
data-gadget-route="[ data-gadget-route="[
{&quot;source&quot;: &quot;/gadget-one/&quot;, &quot;destination&quot;: &quot;gadget-one&quot;}, {&quot;source&quot;: &quot;/gadget-one/&quot;, &quot;destination&quot;: &quot;main-router.gadget_one&quot;},
{&quot;source&quot;: &quot;/gadget-two/&quot;, &quot;destination&quot;: &quot;gadget-two&quot;}]"> {&quot;source&quot;: &quot;/gadget-two/&quot;, &quot;destination&quot;: &quot;main-router.gadget_two&quot;}]">
</div> </div>
<div id="gadget-color-picker" <div id="gadget-color-picker"
...@@ -31,6 +31,13 @@ ...@@ -31,6 +31,13 @@
<div id="gadget-footer" <div id="gadget-footer"
data-gadget="gadget-footer.html"></div> data-gadget="gadget-footer.html"></div>
<div data-gadget=""
id="main-interactor"
data-gadget-connection="[
{&quot;source&quot;: &quot;main-router.gadget_one&quot;, &quot;destination&quot;: &quot;gadget-one.render&quot;},
{&quot;source&quot;: &quot;main-router.gadget_two&quot;, &quot;destination&quot;: &quot;gadget-two.render&quot;}]">
</div>
<noscript> <noscript>
Please enable Javascript Please enable Javascript
</noscript> </noscript>
......
...@@ -14,6 +14,22 @@ require.config({ ...@@ -14,6 +14,22 @@ require.config({
require([ "renderjs", "require-renderjs", "jquery", "route", "url" ], function(domReady) { require([ "renderjs", "require-renderjs", "jquery", "route", "url" ], function(domReady) {
RenderJs.bindReady(function (){ RenderJs.bindReady(function (){
// XXX: try to encapsulate this in router gadget
gadget = RenderJs.GadgetIndex.getGadgetById("main-router");
gadget.gadget_one = function (){
console.log("gadget-one");
// we use interactionGadget which will call proper gadgets' function
};
gadget = RenderJs.GadgetIndex.getGadgetById("main-router");
gadget.gadget_two = function (){
console.log("gadget-two");
// we use interactionGadget which will call proper gadgets' function
};
// XXX: fid why interaction gadget is not initialized proeprly yet
RenderJs.InteractionGadget.bind($("#main-interactor"))
var body = $("body"); var body = $("body");
RenderJs.GadgetIndex.getGadgetById("gadget-color-picker").render(); RenderJs.GadgetIndex.getGadgetById("gadget-color-picker").render();
$.url.onhashchange(function () { $.url.onhashchange(function () {
......
...@@ -775,7 +775,10 @@ var RenderJs = (function () { ...@@ -775,7 +775,10 @@ var RenderJs = (function () {
body body
.route("add", gadget_route.source, 1) .route("add", gadget_route.source, 1)
.done(function () { .done(function () {
RenderJs.GadgetIndex.getGadgetById(gadget_route.destination).render(); var gadget_id = gadget_route.destination.split('.')[0],
method_id = gadget_route.destination.split('.')[1];
gadget = RenderJs.GadgetIndex.getGadgetById(gadget_id);
gadget[method_id]();
}); });
}); });
} }
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
//<![CDATA[ //<![CDATA[
$(document).ready(function() { $(document).ready(function() {
gadget = RenderJs.GadgetIndex.getGadgetById("gadget-one"); gadget = RenderJs.GadgetIndex.getGadgetById("gadget-one");
gadget.render = function (){ gadget.gadget_one = function (){
route_changed=1; // so we can test this method was actually called from qunit route_changed=1; // so we can test this method was actually called from qunit
}; };
}); });
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
<div data-gadget="" <div data-gadget=""
id="main-router" id="main-router"
data-gadget-route="[ data-gadget-route="[
{&quot;source&quot;: &quot;/gadget-one/&quot;, &quot;destination&quot;: &quot;gadget-one&quot;}]"> {&quot;source&quot;: &quot;/gadget-one/&quot;, &quot;destination&quot;: &quot;gadget-one.gadget_one&quot;}]">
</div> </div>
<div id="gadget-one" <div id="gadget-one"
......
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