Skip to content

Instantly share code, notes, and snippets.

@marteinn
Created August 22, 2012 17:20
Show Gist options
  • Save marteinn/3427699 to your computer and use it in GitHub Desktop.
Save marteinn/3427699 to your computer and use it in GitHub Desktop.
Backbone.dryRun (Trigger route without effecting Backbone history)
/**
* 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