Skip to content

Instantly share code, notes, and snippets.

@leonardorb
Created April 26, 2013 22:11
Show Gist options
  • Select an option

  • Save leonardorb/5470797 to your computer and use it in GitHub Desktop.

Select an option

Save leonardorb/5470797 to your computer and use it in GitHub Desktop.

Revisions

  1. leonardorb created this gist Apr 26, 2013.
    26 changes: 26 additions & 0 deletions thorax.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    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)));
    }
    }