Sha256: 518b51a2e30c22ef2f65f216e3656fa8aa46f873e656af1c4093c7b0b20b3575

Contents?: true

Size: 1.12 KB

Versions: 205

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

205 entries across 200 versions & 23 rubygems

Version Path
activestorage-6.1.7.8 app/javascript/activestorage/helpers.js
activestorage-7.2.0.beta1 app/javascript/activestorage/helpers.js
optimacms-0.1.61 spec/dummy/node_modules/@rails/activestorage/src/helpers.js
activestorage-7.1.3.2 app/javascript/activestorage/helpers.js
activestorage-7.1.3.1 app/javascript/activestorage/helpers.js
activestorage-7.0.8.1 app/javascript/activestorage/helpers.js
activestorage-6.1.7.7 app/javascript/activestorage/helpers.js
activestorage-7.1.3 app/javascript/activestorage/helpers.js
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/activestorage-7.0.2.3/app/javascript/activestorage/helpers.js
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/activestorage-6.1.6.1/app/javascript/activestorage/helpers.js
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/activestorage-7.0.3.1/app/javascript/activestorage/helpers.js
activestorage-7.1.2 app/javascript/activestorage/helpers.js
activestorage-7.1.1 app/javascript/activestorage/helpers.js
activestorage-7.1.0 app/javascript/activestorage/helpers.js
activestorage-7.1.0.rc2 app/javascript/activestorage/helpers.js
activestorage-7.1.0.rc1 app/javascript/activestorage/helpers.js
activestorage-7.1.0.beta1 app/javascript/activestorage/helpers.js
activestorage-7.0.8 app/javascript/activestorage/helpers.js
activestorage-7.0.7.2 app/javascript/activestorage/helpers.js
activestorage-6.1.7.6 app/javascript/activestorage/helpers.js