Created
December 20, 2015 03:26
-
-
Save snelson/5813dedac997e06ebbda 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
class App.Router extends Backbone.Router | |
initialize: (options) -> | |
# keep track of the first route event so that | |
# loadNormally doesn't get stuck in an infinite | |
# redirect loop | |
@isFirstRoute = true | |
@once 'route', => | |
@isFirstRoute = false | |
routes: | |
# replace main view | |
'' : 'replaceMainView' | |
# load any url to the admin normally | |
'admin*path' : 'loadNormally' | |
# load all urls in an overlay by default | |
'*default' : 'presentOverlay' | |
loadNormally: -> | |
# Don't redirect if this is the first route event | |
# (the page has just loaded) | |
window.location = @getUrl() unless @isFirstRoute | |
replaceMainView: -> | |
@loadUrl @getUrl(), (data) -> | |
$('#main-view').html(data) | |
$('#overlay').hide() | |
presentOverlay: -> | |
@loadUrl @getUrl(), (data) -> | |
$('#overlay').html(data).show() | |
getUrl: -> | |
"/#{Backbone.history.fragment}" | |
loadUrl: (url, callback) -> | |
$.get url, { partial: true }, (data) => | |
callback(data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment