Sha256: 518b51a2e30c22ef2f65f216e3656fa8aa46f873e656af1c4093c7b0b20b3575

Contents?: true

Size: 1.12 KB

Versions: 198

Compression:

Stored size: 1.12 KB

Contents

export function getMetaValue(name) {
  const element = findElement(document.head, `meta[name="${name}"]`)
  if (element) {
    return element.getAttribute("content")
  }
}

export function findElements(root, selector) {
  if (typeof root == "string") {
    selector = root
    root = document
  }
  const elements = root.querySelectorAll(selector)
  return toArray(elements)
}

export function findElement(root, selector) {
  if (typeof root == "string") {
    selector = root
    root = document
  }
  return root.querySelector(selector)
}

export function dispatchEvent(element, type, eventInit = {}) {
  const { disabled } = element
  const { bubbles, cancelable, detail } = eventInit
  const event = document.createEvent("Event")

  event.initEvent(type, bubbles || true, cancelable || true)
  event.detail = detail || {}

  try {
    element.disabled = false
    element.dispatchEvent(event)
  } finally {
    element.disabled = disabled
  }

  return event
}

export function toArray(value) {
  if (Array.isArray(value)) {
    return value
  } else if (Array.from) {
    return Array.from(value)
  } else {
    return [].slice.call(value)
  }
}

Version data entries

198 entries across 193 versions & 21 rubygems

Version Path
activestorage-8.0.0 app/javascript/activestorage/helpers.js
activestorage-7.2.2 app/javascript/activestorage/helpers.js
activestorage-7.1.5 app/javascript/activestorage/helpers.js
activestorage-8.0.0.rc2 app/javascript/activestorage/helpers.js
activestorage-7.2.1.2 app/javascript/activestorage/helpers.js
activestorage-7.1.4.2 app/javascript/activestorage/helpers.js
activestorage-7.0.8.6 app/javascript/activestorage/helpers.js
activestorage-6.1.7.10 app/javascript/activestorage/helpers.js
activestorage-8.0.0.rc1 app/javascript/activestorage/helpers.js
activestorage-6.1.7.9 app/javascript/activestorage/helpers.js
activestorage-7.2.1.1 app/javascript/activestorage/helpers.js
activestorage-7.1.4.1 app/javascript/activestorage/helpers.js
activestorage-7.0.8.5 app/javascript/activestorage/helpers.js
activestorage-8.0.0.beta1 app/javascript/activestorage/helpers.js
omg-activestorage-8.0.0.alpha9 app/javascript/activestorage/helpers.js
omg-activestorage-8.0.0.alpha8 app/javascript/activestorage/helpers.js
omg-activestorage-8.0.0.alpha7 app/javascript/activestorage/helpers.js
omg-activestorage-8.0.0.alpha4 app/javascript/activestorage/helpers.js
omg-activestorage-8.0.0.alpha3 app/javascript/activestorage/helpers.js
activestorage-7.1.4 app/javascript/activestorage/helpers.js