Skip to content

Instantly share code, notes, and snippets.

@b-ma
Created March 4, 2014 20:41
Show Gist options
  • Save b-ma/9355180 to your computer and use it in GitHub Desktop.
Save b-ma/9355180 to your computer and use it in GitHub Desktop.
allow to trigger multiple callback with 1 route using a route separator
Backbone.History.prototype.multiRouteSeparator = '|';
Backbone.History.prototype.loadUrl = function(fragment) {
fragment = this.fragment = this.getFragment(fragment);
// split the fragment according to the defined separator
var fragments = fragment.split(this.multiRouteSeparator);
// test handlers with each fragments
// the function doesn't return anything like the real one
// but it doesn't seems to create problems
_.forEach(fragments, function(fragment) {
_.any(this.handlers, function(handler) {
if (handler.route.test(fragment)) {
// execute the callback
handler.callback(fragment);
return true;
}
});
}, this);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment