Created
August 22, 2012 17:20
-
-
Save marteinn/3427699 to your computer and use it in GitHub Desktop.
Backbone.dryRun (Trigger route without effecting Backbone history)
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
/** | |
* Licensed under the MIT License | |
* | |
* DryRun is a Backbone.js addon that allows you to trigger route handler by suppling a url segment. | |
* without effecting Backbone history. (For those rare occations.) | |
* | |
* Usage: | |
* var fragment = window.location.pathname.substr(1, window.location.pathname.length); | |
* Backbone.dryRun(fragment); | |
**/ | |
/*global _, Backbone */ | |
;(function(Backbone) { | |
var dryRun = function(fragment) | |
{ | |
var matched = _.any(Backbone.history.handlers, function(handler) { | |
if (handler.route.test(fragment)) { | |
handler.callback(fragment); | |
return true; | |
} | |
}); | |
return matched; | |
}; | |
Backbone.dryRun = dryRun; | |
})(Backbone); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment