Sha256: 12aad090f4c8fc3a736855fa2372462a7fe8321a0f5b324f87d6954e7bedec8c

Contents?: true

Size: 696 Bytes

Versions: 1

Compression:

Stored size: 696 Bytes

Contents

up.history = (->

  replace = (url) ->
    manipulate "replace", url

  push = (url) ->
    manipulate "push", url

  manipulate = (method, url) ->
    method += "State" # resulting in either pushState or replaceState
    window.history[method]({ fromUp: true }, '', url)

  pop = (event) ->
    state = event.originalEvent.state
    console.log "popping state", state
    console.log "current href", currentUrl()
    if state?.fromUp
      up.visit currentUrl(), history: { method: 'replace' }
    else
      console.log "null state"

  currentUrl = ->
    location.href

  setTimeout (->
    $(window).on "popstate", pop
    replace(currentUrl())
  ), 200

  push: push
  replace: replace

)()

Version data entries

1 entries across 1 versions & 1 rubygems

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