Sha256: f8b4b852020aadabb0ab1eee047b0dc358c7e9cefbdbf7bfb1e6eb317a62c870

Contents?: true

Size: 1.41 KB

Versions: 15

Compression:

Stored size: 1.41 KB

Contents

#= require ./http_request
#= require ./progress_bar

class Turbolinks.BrowserAdapter
  {NETWORK_FAILURE, TIMEOUT_FAILURE} = Turbolinks.HttpRequest

  constructor: (@controller) ->
    @progressBar = new Turbolinks.ProgressBar

  visitProposedToLocationWithAction: (location, action) ->
    @controller.startVisitToLocationWithAction(location, action)

  visitStarted: (visit) ->
    visit.issueRequest()
    visit.changeHistory()
    visit.loadCachedSnapshot()

  visitRequestStarted: (visit) ->
    @progressBar.setValue(0)
    if visit.hasCachedSnapshot() or visit.action isnt "restore"
      @showProgressBarAfterDelay()
    else
      @showProgressBar()

  visitRequestProgressed: (visit) ->
    @progressBar.setValue(visit.progress)

  visitRequestCompleted: (visit) ->
    visit.loadResponse()

  visitRequestFailedWithStatusCode: (visit, statusCode) ->
    switch statusCode
      when NETWORK_FAILURE, TIMEOUT_FAILURE
        @reload()
      else
        visit.loadResponse()

  visitRequestFinished: (visit) ->
    @hideProgressBar()

  visitCompleted: (visit) ->
    visit.followRedirect()

  pageInvalidated: ->
    @reload()

  # Private

  showProgressBarAfterDelay: ->
    @progressBarTimeout = setTimeout(@showProgressBar, @controller.progressBarDelay)

  showProgressBar: =>
    @progressBar.show()

  hideProgressBar: ->
    @progressBar.hide()
    clearTimeout(@progressBarTimeout)

  reload: ->
    window.location.reload()

Version data entries

15 entries across 14 versions & 6 rubygems

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