Skip to content

Commit

Permalink
+ Bind now accepts an array of urls aswell as just a single url string.
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Hurst authored and Robert Hurst committed Feb 8, 2012
1 parent 2cc1c72 commit 291c607
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions origin.js
Expand Up @@ -323,14 +323,22 @@
* @param tearDownCallbacks (optional)
*/
function bindRoute(url, setupCallbacks, tearDownCallbacks) {
var matchedRoute, rGK, rI, enI, exI, uris, route;
var matchedRoute, rGK, rI, enI, exI, uris, route, uI;

if(typeof setupCallbacks === 'function') { setupCallbacks = [setupCallbacks]; }
if(typeof tearDownCallbacks === 'function') { tearDownCallbacks = [tearDownCallbacks]; }

setupCallbacks = setupCallbacks || [];
tearDownCallbacks = tearDownCallbacks || [];

//if the url is actually a array the loop through and bind each
if(typeof url === 'object' && typeof url.push === 'function') {
for(uI = 0; uI < url.length; uI += 1) {
bindRoute(url[uI], setupCallbacks, tearDownCallbacks);
}
return;
}

//make sure the url and callback is defined
if(typeof url !== 'string') {
throw new Error('Cannot bind route. Requires a valid route url string.');
Expand Down Expand Up @@ -387,8 +395,6 @@

routes[uris.length].push(route);
}

return true;
}

/**
Expand Down

0 comments on commit 291c607

Please sign in to comment.