Created
March 4, 2014 20:41
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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