Skip to content

Commit 00af1b1

Browse files
committed
including function call
1 parent 5ba14a9 commit 00af1b1

File tree

3 files changed

+38
-10
lines changed

3 files changed

+38
-10
lines changed

README.rdoc

+4
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,8 @@ route.add('^\\d{1,2}\\-\\d{1,2}\-\\d{4}$', function(day){
2121

2222
There are no known issues at the time.
2323

24+
== Change Log
25+
26+
0.2.0: Added a new function "call" to force an execution of a specific route
27+
2428

jsRoute.js

+14-8
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,26 @@ var route = {
2626
}
2727
},
2828

29-
_update: function(){
30-
var hash = location.hash.slice(1);
31-
32-
for(i=0; i< this.routes.length; i++){
29+
_findAndExecute: function(route){
30+
for(var i=0; i< this.routes.length; i++){
3331
var re = new RegExp(this.routes[i]);
34-
var match = hash.match(re);
32+
var match = route.match(re);
3533

3634
if(match){
3735
this.funcs[i](match[0]);
3836
return true;
3937
}
4038
}
41-
42-
console.log("404 - Route not found!");
39+
return false;
40+
},
41+
42+
_update: function(){
43+
var hash = location.hash.slice(1);
44+
45+
this._findAndExecute(hash);
46+
},
47+
48+
call: function(route){
49+
this._findAndExecute(route);
4350
}
4451
};
45-

tests/jasmine/spec/jsRouteSpec.js

+20-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
describe("jsRoute", function() {
22

33
beforeEach(function() {
4-
//route.routes = [];
5-
//route.funcs = [];
4+
65
});
76

87
it("should be able to add routes", function() {
@@ -30,4 +29,23 @@ describe("jsRoute", function() {
3029
});
3130

3231
});
32+
33+
it("should be able to force a route", function() {
34+
route.add('^\\d{1,2}\\-\\d{1,2}\-\\d{4}$', function(x){
35+
if(x==='23-10-2012'){
36+
location.hash='#alterado';
37+
}
38+
});
39+
40+
runs(function(){
41+
route.call('#23-10-2012');
42+
});
43+
44+
waits(1000);
45+
46+
runs(function(){
47+
expect(location.hash).toEqual('#alterado');
48+
});
49+
50+
});
3351
});

0 commit comments

Comments
 (0)