Sha256: 1d55c777355217ed55e275528cc5b289e4e3597614c098226c2b6160ccb4ef0b

Contents?: true

Size: 1011 Bytes

Versions: 1

Compression:

Stored size: 1011 Bytes

Contents

whenReady = (fn) ->
  if (if document.attachEvent then document.readyState == 'complete' else document.readyState != 'loading')
    fn()
  else
    document.addEventListener "DOMContentLoaded", ->
      fn()

eventListen = (event, handler) ->
  document.addEventListener event, (e) ->
    handler.call document, e

class NitrolinksLoadHelper
  constructor: (@window, @document) ->
    @active = false

  body: ->
    document.querySelector('body')

  markAsLoading: (from)->
    @active = true
    @body().classList.add('testing-visiting')

  markAsDoneLoading: ->
    @active = false
    @body().classList.remove('testing-visiting')

  listen: ->
    eventListen 'nitrolinks:visit', =>
      @markAsLoading('nitrolinks:visit')

    loads = (e) =>
      @markAsDoneLoading()

    eventListen 'nitrolinks:load', loads
    eventListen 'nitrolinks:load-blank', loads

whenReady =>
  @nitroLoadHelper = new NitrolinksLoadHelper(window, document)
  @nitroLoadHelper.listen()
  @nitroLoadHelper.markAsDoneLoading()


Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
nitrolinks-rails-0.3.0 app/assets/javascripts/nitrolinks/load-helper.coffee