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

Fix: search method in routing plugin

parent bbabfa06
......@@ -47,7 +47,7 @@ $.extend({
this.list = this.list.slice(0, 0);
},
search: function (hash, level) {
search: function (hash, level, failcallback, context) {
var stop = false,
i, j,
regex,
......@@ -70,17 +70,29 @@ $.extend({
}
this.current = this.list[i][j];
this.clean(this.list[i][j].level + 1);
console.log(this.list[i][j].route);
this.list[i][j].callback(hash);
}
j += 1;
}
i -= 1;
}
if (stop === false && failcallback !== undefined) {
if (context === undefined) {
failcallback();
} else {
failcallback.call(context);
}
}
},
isLastLevel: function () {
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 () {
var spy = sinon.spy(),
i = 0,
callback = function (params) {
console.log(params)
$.router.routes.add('/first', 1, spy)
$.router.start(params.route);
}
......@@ -82,6 +81,13 @@ $(function () {
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', {
});
......
......@@ -76,8 +76,12 @@ $.extend({
}
i -= 1;
}
if (stop === false) {
failcallback.call(context);
if (stop === false && failcallback !== undefined) {
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