Commit 1470dfc0 authored by Thomas Lechauve's avatar Thomas Lechauve

Fix: search method in routing plugin

parent bbabfa06
...@@ -47,7 +47,7 @@ $.extend({ ...@@ -47,7 +47,7 @@ $.extend({
this.list = this.list.slice(0, 0); this.list = this.list.slice(0, 0);
}, },
search: function (hash, level) { search: function (hash, level, failcallback, context) {
var stop = false, var stop = false,
i, j, i, j,
regex, regex,
...@@ -70,17 +70,29 @@ $.extend({ ...@@ -70,17 +70,29 @@ $.extend({
} }
this.current = this.list[i][j]; this.current = this.list[i][j];
this.clean(this.list[i][j].level + 1); this.clean(this.list[i][j].level + 1);
console.log(this.list[i][j].route);
this.list[i][j].callback(hash); this.list[i][j].callback(hash);
} }
j += 1; j += 1;
} }
i -= 1; i -= 1;
} }
if (stop === false && failcallback !== undefined) {
if (context === undefined) {
failcallback();
} else {
failcallback.call(context);
}
}
}, },
isLastLevel: function () { isLastLevel: function () {
return this.current.level === (this.list.length - 1); return this.current.level === (this.list.length - 1);
},
isCurrent: function (hash) {
var extracted = $.router.extractKeys(this.current.route),
regex = new RegExp('^' + extracted.regex + '$');
return regex.test(hash);
} }
}, },
......
...@@ -73,7 +73,6 @@ $(function () { ...@@ -73,7 +73,6 @@ $(function () {
var spy = sinon.spy(), var spy = sinon.spy(),
i = 0, i = 0,
callback = function (params) { callback = function (params) {
console.log(params)
$.router.routes.add('/first', 1, spy) $.router.routes.add('/first', 1, spy)
$.router.start(params.route); $.router.start(params.route);
} }
...@@ -82,6 +81,13 @@ $(function () { ...@@ -82,6 +81,13 @@ $(function () {
ok(spy.calledOnce); ok(spy.calledOnce);
}); });
test('no routes found', function () {
var callback = function () {
ok(true, "should be call");
};
$.router.routes.search({'route': '/nonexist'}, 0, callback, $(this));
});
module('router methods tests', { module('router methods tests', {
}); });
......
...@@ -76,8 +76,12 @@ $.extend({ ...@@ -76,8 +76,12 @@ $.extend({
} }
i -= 1; i -= 1;
} }
if (stop === false) { if (stop === false && failcallback !== undefined) {
failcallback.call(context); if (context === undefined) {
failcallback();
} else {
failcallback.call(context);
}
} }
}, },
......
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