Created
August 17, 2012 02:33
-
-
Save rjz/3375413 to your computer and use it in GitHub Desktop.
Monkey-patch Backbone.History to add route filtering
This file contains hidden or 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
| # Monkey-patch Backbone.History to filter/rewrite/inject routes | |
| # see: http://blog.rjzaworski.com/2012/08/filtering-backbone-routes/ | |
| do (History = Backbone.History) -> | |
| _navigate = History::navigate | |
| methods = | |
| filter: (fragment) -> | |
| if fragment == 'NOOP' | |
| return null | |
| fragment | |
| navigate: (fragment, options) -> | |
| fragment = @filter(fragment) | |
| if filter? | |
| _navigate.call @, fragment, options | |
| _.extend History::, methods |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment