Created
October 29, 2014 19:55
-
-
Save flintinatux/ee911130d22cc161e217 to your computer and use it in GitHub Desktop.
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
module.exports = class SwappingRouter extends Backbone.Router | |
execute: (callback, args) -> | |
@params = @_parseParams args.pop() | |
callback?.apply this, args | |
navigate: (fragment, options={}) -> | |
url = new URI fragment.replace('#','') | |
url.query options.params if options.params? | |
super "##{url.toString()}", _.omit(options, 'params') | |
swap: (newView) -> | |
@currentView?.remove() | |
@currentView = newView | |
@$el.html @currentView.render().el | |
@currentView.swapped() | |
this | |
_parseParams: (params) -> | |
return {} unless params | |
new URI("?#{params}").query(true) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment