Skip to content

Commit

Permalink
Merge branch 'dev-maciej' of github.com:fightbulc/impala into dev-tino
Browse files Browse the repository at this point in the history
  • Loading branch information
Tino Ehrich committed May 4, 2013
2 parents 6a0683c + 8690d14 commit b388394
Showing 1 changed file with 32 additions and 5 deletions.
37 changes: 32 additions & 5 deletions abstract-router.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,34 @@ define (require) ->
initialize: ->
Imp.log [__private.moduleName(), 'init', Imp.getConfig()]

#
# Hashbang compatibility
#
window.location.hash = "##{window.location.hash.slice(3)}" if window.location.hash.slice(0, 3) is "#!/"

#
# Init history
#
Backbone.history.stop()
Backbone.history.start root: Imp.getConfigByKey('url').public
Backbone.history.start root: Imp.getConfigByKey('url').public, pushState: true

$(document).on "click", "a[href^='/']", (e) =>
href = $(e.currentTarget).attr('href')

# chain 'or's for other black list routes
# passThrough = href.indexOf('sign_out') >= 0

# Allow shift+click for new tabs, etc.
if not e.altKey and not e.ctrlKey and not e.metaKey and not e.shiftKey
e.preventDefault()

# Remove leading slashes and hash bangs (backward compatablility)
url = href.replace(/^\//,'').replace('\#\!\/','')

# Instruct Backbone to trigger routing events
Backbone.history.navigate url, { trigger: true }

return false

#
# listen for redirect requests
Expand All @@ -41,23 +64,27 @@ define (require) ->

redirect: (route, replace = false) ->
Imp.log [__private.moduleName(), 'redirect', route, replace]
Backbone.history.navigate "!/#{route}", trigger: true, replace: replace
Backbone.history.navigate route, trigger: true, replace: replace

# -------------------------------------------

updateUrl: (route) ->
Imp.log [__private.moduleName(), 'updateUrl', route]
Backbone.history.navigate "!/#{route}"
Backbone.history.navigate route

# -------------------------------------------

getCurrentRoute: ->
Imp.log [__private.moduleName(), 'getCurrentRoute']
window.location.hash.replace '#!/', ''
path = window.location.path
hashPath = window.location.hash.replace '#!/', ''

return hashPath if path is '' and hashPath isnt ''
return path

# -------------------------------------------

reloadPage: ->
Imp.log [__private.moduleName(), 'reloadPage']
route = @getCurrentRoute()
Backbone.history.loadUrl "!/#{route}"
Backbone.history.loadUrl route

0 comments on commit b388394

Please sign in to comment.