Sha256: 618473c9dc1954360b8de5b64e96b29c1b8de6a9165337ee4a41b999b0a70809

Contents?: true

Size: 1.44 KB

Versions: 16

Compression:

Stored size: 1.44 KB

Contents

class Turbolinks.History
  constructor: (@delegate) ->

  start: ->
    unless @started
      addEventListener("popstate", @onPopState, false)
      addEventListener("load", @onPageLoad, false)
      @started = true

  stop: ->
    if @started
      removeEventListener("popstate", @onPopState, false)
      removeEventListener("load", @onPageLoad, false)
      @started = false

  push: (location, restorationIdentifier) ->
    location = Turbolinks.Location.wrap(location)
    @update("push", location, restorationIdentifier)

  replace: (location, restorationIdentifier) ->
    location = Turbolinks.Location.wrap(location)
    @update("replace", location, restorationIdentifier)

  # Event handlers

  onPopState: (event) =>
    if @shouldHandlePopState()
      if turbolinks = event.state?.turbolinks
        location = Turbolinks.Location.wrap(window.location)
        restorationIdentifier = turbolinks.restorationIdentifier
        @delegate.historyPoppedToLocationWithRestorationIdentifier(location, restorationIdentifier)

  onPageLoad: (event) =>
    Turbolinks.defer =>
      @pageLoaded = true

  # Private

  shouldHandlePopState: ->
    # Safari dispatches a popstate event after window's load event, ignore it
    @pageIsLoaded()

  pageIsLoaded: ->
    @pageLoaded or document.readyState is "complete"

  update: (method, location, restorationIdentifier) ->
    state = turbolinks: {restorationIdentifier}
    history[method + "State"](state, null, location)

Version data entries

16 entries across 15 versions & 7 rubygems

Version Path
optimacms-0.1.61 spec/dummy/node_modules/turbolinks/src/turbolinks/history.coffee
groonga-client-model-6.0.0 test/apps/rails6.0.3.5/node_modules/turbolinks/src/turbolinks/history.coffee
groonga-client-model-6.0.0 test/apps/rails6.1.3/node_modules/turbolinks/src/turbolinks/history.coffee
ruby2js-4.0.4 lib/tasks/testrails/node_modules/turbolinks/src/turbolinks/history.coffee
ruby2js-4.0.3 lib/tasks/testrails/node_modules/turbolinks/src/turbolinks/history.coffee
jester-data-8.0.0 node_modules/turbolinks/src/turbolinks/history.coffee
ezii-os-5.2.1 node_modules/turbolinks/src/turbolinks/history.coffee
ezii-os-2.0.1 node_modules/turbolinks/src/turbolinks/history.coffee
ezii-os-1.1.0 node_modules/turbolinks/src/turbolinks/history.coffee
ezii-os-1.0.0 node_modules/turbolinks/src/turbolinks/history.coffee
ezii-os-0.0.0.1.0 node_modules/turbolinks/src/turbolinks/history.coffee
ezii-os-0.0.0.0.1 node_modules/turbolinks/src/turbolinks/history.coffee
rails_auth-1.0.6 test/dummy/node_modules/turbolinks/src/turbolinks/history.coffee
rails_auth-1.0.5 test/dummy/node_modules/turbolinks/src/turbolinks/history.coffee
rails_auth-1.0.4 test/dummy/node_modules/turbolinks/src/turbolinks/history.coffee
jekyll-theme-chalk-0.1.1 _assets/yarn/turbolinks/src/turbolinks/history.coffee