Commit 4e76428c authored by Ivan Tyagov's avatar Ivan Tyagov

Add some basic route introspection for RouteGadget.

parent efe5890c
......@@ -761,6 +761,7 @@ var RenderJs = (function () {
/*
* A gadget that defines possible routes (i.e. URL changes) between gadgets.
*/
var route_list = [];
return {
route: function (gadget_dom) {
......@@ -791,6 +792,10 @@ var RenderJs = (function () {
body
.route("add", path, 1)
.done(handler_func);
// save locally
route_list.push({"path": path,
"handler_func": handler_func,
"priority": priority});
},
go: function (path, handler_func, priority) {
......@@ -801,6 +806,21 @@ var RenderJs = (function () {
body
.route("go", path, priority)
.fail(handler_func);
},
remove: function (path) {
/*
* Remove a route.
*/
// XXX: implement remove a route when route.js supports it
},
getRouteList: function () {
/*
* Get list of all router
*/
return route_list;
}
};
}())
......
......@@ -257,6 +257,13 @@ function setupRenderJSTest(){
$("div[data-gadget-route]").each(function (index, element) {
RenderJs.RouteGadget.route($(element));
});
var path_list = [];
$.each(RenderJs.RouteGadget.getRouteList(),
function (index, value) {
path_list.push(value.path);
});
equal(3, RenderJs.RouteGadget.getRouteList().length);
deepEqual(["/gadget-one/", "/gadget-two/","/gadget-three/"], path_list);
// listen to event and do actual routing
$.url.onhashchange(function () {
......
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