Sha256: 44f83c9d4a430cda4d56402482fd484e4129e25ae4dac48766eef0f0dbe14029

Contents?: true

Size: 1.14 KB

Versions: 47

Compression:

Stored size: 1.14 KB

Contents

m = Element.prototype.matches or
    Element.prototype.matchesSelector or
    Element.prototype.mozMatchesSelector or
    Element.prototype.msMatchesSelector or
    Element.prototype.oMatchesSelector or
    Element.prototype.webkitMatchesSelector

# Checks if the given native dom element matches the selector
# element::
#   native DOM element
# selector::
#   css selector string or
#   a javascript object with `selector` and `exclude` properties
#   Examples: "form", { selector: "form", exclude: "form[data-remote='true']"}
Rails.matches = (element, selector) ->
  if selector.exclude?
    m.call(element, selector.selector) and not m.call(element, selector.exclude)
  else
    m.call(element, selector)

# get and set data on a given element using "expando properties"
# See: https://developer.mozilla.org/en-US/docs/Glossary/Expando
expando = '_ujsData'

Rails.getData = (element, key) ->
  element[expando]?[key]

Rails.setData = (element, key, value) ->
  element[expando] ?= {}
  element[expando][key] = value

# a wrapper for document.querySelectorAll
# returns an Array
Rails.$ = (selector) ->
  Array.prototype.slice.call(document.querySelectorAll(selector))

Version data entries

47 entries across 47 versions & 1 rubygems

Version Path
jets-1.9.7 vendor/rails/actionview/app/assets/javascripts/rails-ujs/utils/dom.coffee
jets-1.9.6 vendor/rails/actionview/app/assets/javascripts/rails-ujs/utils/dom.coffee
jets-1.9.5 vendor/rails/actionview/app/assets/javascripts/rails-ujs/utils/dom.coffee
jets-1.9.4 vendor/rails/actionview/app/assets/javascripts/rails-ujs/utils/dom.coffee
jets-1.9.3 vendor/rails/actionview/app/assets/javascripts/rails-ujs/utils/dom.coffee
jets-1.9.2 vendor/rails/actionview/app/assets/javascripts/rails-ujs/utils/dom.coffee
jets-1.9.1 vendor/rails/actionview/app/assets/javascripts/rails-ujs/utils/dom.coffee
jets-1.9.0 vendor/rails/actionview/app/assets/javascripts/rails-ujs/utils/dom.coffee
jets-1.8.14 vendor/rails/actionview/app/assets/javascripts/rails-ujs/utils/dom.coffee
jets-1.8.13 vendor/rails/actionview/app/assets/javascripts/rails-ujs/utils/dom.coffee
jets-1.8.12 vendor/rails/actionview/app/assets/javascripts/rails-ujs/utils/dom.coffee
jets-1.8.11 vendor/rails/actionview/app/assets/javascripts/rails-ujs/utils/dom.coffee
jets-1.8.10 vendor/rails/actionview/app/assets/javascripts/rails-ujs/utils/dom.coffee
jets-1.8.9 vendor/rails/actionview/app/assets/javascripts/rails-ujs/utils/dom.coffee
jets-1.8.8 vendor/rails/actionview/app/assets/javascripts/rails-ujs/utils/dom.coffee
jets-1.8.7 vendor/rails/actionview/app/assets/javascripts/rails-ujs/utils/dom.coffee
jets-1.8.6 vendor/rails/actionview/app/assets/javascripts/rails-ujs/utils/dom.coffee
jets-1.8.5 vendor/rails/actionview/app/assets/javascripts/rails-ujs/utils/dom.coffee
jets-1.8.4 vendor/rails/actionview/app/assets/javascripts/rails-ujs/utils/dom.coffee
jets-1.8.3 vendor/rails/actionview/app/assets/javascripts/rails-ujs/utils/dom.coffee