Skip to content

Instantly share code, notes, and snippets.

@leonardorb
Created April 26, 2013 22:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leonardorb/5470797 to your computer and use it in GitHub Desktop.
Save leonardorb/5470797 to your computer and use it in GitHub Desktop.
Thorax.Router = Backbone.Router.extend({
constructor: function() {
var response = Thorax.Router.__super__.constructor.apply(this, arguments);
initializeRouter.call(this);
return response;
},
route: function(route, name, callback) {
if (!callback) {
callback = this[name];
}
//add a route:before event that is fired before the callback is called
return Backbone.Router.prototype.route.call(this, route, name, function() {
this.trigger.apply(this, ['route:before', route, name].concat(Array.prototype.slice.call(arguments)));
return callback.apply(this, arguments);
});
}
});
Thorax.Routers = {};
createRegistryWrapper(Thorax.Router, Thorax.Routers);
function onRoute(router /* , name */) {
if (this === router) {
this.trigger.apply(this, ['route'].concat(Array.prototype.slice.call(arguments, 1)));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment