Sha256: 95c921098461f66a01ee9a5925e47dc62d0c8f68250fd3015c6d894ef9b99f61

Contents?: true

Size: 527 Bytes

Versions: 135

Compression:

Stored size: 527 Bytes

Contents

export function on(eventName, baseSelector, targetSelector, callback) {
  document.querySelectorAll(baseSelector).forEach((baseNode) => {
    baseNode.addEventListener(eventName, (evt) => {
      const targets = Array.from(baseNode.querySelectorAll(targetSelector))
      let currentNode = evt.target

      while (currentNode !== baseNode) {
        if (targets.includes(currentNode)) {
          callback.call(currentNode, evt)
          return
        }
        currentNode = currentNode.parentElement
      }
    })
  })
}

Version data entries

135 entries across 135 versions & 1 rubygems

Version Path
alchemy_cms-7.3.4 app/javascript/alchemy_admin/utils/events.js
alchemy_cms-7.3.3 app/javascript/alchemy_admin/utils/events.js
alchemy_cms-7.3.2 app/javascript/alchemy_admin/utils/events.js
alchemy_cms-7.2.7 app/javascript/alchemy_admin/utils/events.js
alchemy_cms-7.3.1 app/javascript/alchemy_admin/utils/events.js
alchemy_cms-7.3.0 app/javascript/alchemy_admin/utils/events.js
alchemy_cms-7.2.6 app/javascript/alchemy_admin/utils/events.js
alchemy_cms-7.2.5 app/javascript/alchemy_admin/utils/events.js
alchemy_cms-7.1.12 app/javascript/alchemy_admin/utils/events.js
alchemy_cms-7.0.15 app/javascript/alchemy_admin/utils/events.js
alchemy_cms-6.1.10 package/src/utils/events.js
alchemy_cms-7.2.4 app/javascript/alchemy_admin/utils/events.js
alchemy_cms-7.1.11 app/javascript/alchemy_admin/utils/events.js
alchemy_cms-7.2.3 app/javascript/alchemy_admin/utils/events.js
alchemy_cms-7.1.10 app/javascript/alchemy_admin/utils/events.js
alchemy_cms-7.2.2 app/javascript/alchemy_admin/utils/events.js
alchemy_cms-7.1.9 app/javascript/alchemy_admin/utils/events.js
alchemy_cms-7.0.14 app/javascript/alchemy_admin/utils/events.js
alchemy_cms-7.2.1 app/javascript/alchemy_admin/utils/events.js
alchemy_cms-7.0.13 app/javascript/alchemy_admin/utils/events.js