Sha256: 7f4965745da485b4cb2b7311922ce48bd51c214fe680bdb1ce61980f4e97d320

Contents?: true

Size: 1.64 KB

Versions: 2

Compression:

Stored size: 1.64 KB

Contents

###*
Manipulating the browser history
=======
  
\#\#\# Incomplete documentation!
  
We need to work on this page:

- Explain how the other modules manipulate history
- Decide whether we want to expose these methods as public API
- Document methods and parameters
  
    
@class up.history
###
up.history = (->
  
  u = up.util
  
  isCurrentUrl = (url) ->
    u.normalizeUrl(url, hash: true) == u.normalizeUrl(up.browser.url(), hash: true)
    
  ###*
  @method up.history.replace
  @param {String} url
  @protected
  ###
  replace = (url, options) ->
    options = u.options(options, force: false)
    if options.force || !isCurrentUrl(url)
      manipulate("replace", url)

  ###*
  @method up.history.push  
  @param {String} url
  @protected
  ###
  push = (url) ->
    manipulate("push", url) unless isCurrentUrl(url)

  manipulate = (method, url) ->
    if up.browser.canPushState()
      method += "State" # resulting in either pushState or replaceState
      window.history[method]({ fromUp: true }, '', url)
    else
      u.error("This browser doesn't support history.pushState")

  pop = (event) ->
    state = event.originalEvent.state
    console.log "popping state", state
    console.log "current href", up.browser.url()
    if state?.fromUp
      up.visit up.browser.url(), historyMethod: 'replace'
    else
      console.log "strange state", state

  # Defeat an unnecessary popstate that some browsers trigger on pageload (Chrome?).
  # We should check in 2016 if we can remove this.
  if up.browser.canPushState()
    setTimeout (->
      $(window).on "popstate", pop
      replace(up.browser.url(), force: true)
    ), 200

  push: push
  replace: replace

)()

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
upjs-rails-0.3.3 lib/assets/javascripts/up/history.js.coffee
upjs-rails-0.3.2 lib/assets/javascripts/up/history.js.coffee