Sha256: c3cf0a0b80985ad63f10a6fcb61fa11c79d08dd24bcf4bf0151245a5121cbf6c

Contents?: true

Size: 1.96 KB

Versions: 15

Compression:

Stored size: 1.96 KB

Contents

Turbolinks.copyObject = (object) ->
  result = {}
  for key, value of object
    result[key] = value
  result


Turbolinks.closest = (element, selector) ->
  closest.call(element, selector)

closest = do ->
  html = document.documentElement
  html.closest ? (selector) ->
    node = this
    while node
      return node if node.nodeType is Node.ELEMENT_NODE and match.call(node, selector)
      node = node.parentNode


Turbolinks.defer = (callback) ->
  setTimeout(callback, 1)

Turbolinks.throttle = (fn) ->
  request = null
  (args...) ->
    request ?= requestAnimationFrame =>
      request = null
      fn.apply(this, args)


Turbolinks.dispatch = (eventName, {target, cancelable, data} = {}) ->
  event = document.createEvent("Events")
  event.initEvent(eventName, true, cancelable is true)
  event.data = data ? {}

  # Fix setting `defaultPrevented` when `preventDefault()` is called
  # http://stackoverflow.com/questions/23349191/event-preventdefault-is-not-working-in-ie-11-for-custom-events
  if event.cancelable and not preventDefaultSupported
    { preventDefault } = event
    event.preventDefault = ->
      unless this.defaultPrevented
        Object.defineProperty(this, "defaultPrevented", get: -> true)
      preventDefault.call(this)

  (target ? document).dispatchEvent(event)
  event

preventDefaultSupported = do ->
  event = document.createEvent("Events")
  event.initEvent("test", true, true)
  event.preventDefault()
  event.defaultPrevented


Turbolinks.match = (element, selector) ->
  match.call(element, selector)

match = do ->
  html = document.documentElement
  html.matchesSelector ? html.webkitMatchesSelector ? html.msMatchesSelector ? html.mozMatchesSelector


Turbolinks.uuid = ->
  result = ""
  for i in [1..36]
    if i in [9, 14, 19, 24]
      result += "-"
    else if i is 15
      result += "4"
    else if i is 20
      result += (Math.floor(Math.random() * 4) + 8).toString(16)
    else
      result += Math.floor(Math.random() * 15).toString(16)
  result

Version data entries

15 entries across 14 versions & 6 rubygems

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