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-6.1.0 package/src/utils/events.js
alchemy_cms-6.0.12 package/src/utils/events.js
alchemy_cms-6.0.11 package/src/utils/events.js
alchemy_cms-6.0.10 package/src/utils/events.js
alchemy_cms-5.3.8 package/src/utils/events.js
alchemy_cms-6.0.9 package/src/utils/events.js
alchemy_cms-5.3.7 package/src/utils/events.js
alchemy_cms-6.0.8 package/src/utils/events.js
alchemy_cms-5.3.6 package/src/utils/events.js
alchemy_cms-6.0.7 package/src/utils/events.js
alchemy_cms-6.0.6 package/src/utils/events.js
alchemy_cms-6.0.5 package/src/utils/events.js
alchemy_cms-6.0.4 package/src/utils/events.js
alchemy_cms-6.0.3 package/src/utils/events.js
alchemy_cms-6.0.2 package/src/utils/events.js
alchemy_cms-6.0.1 package/src/utils/events.js
alchemy_cms-5.3.5 package/src/utils/events.js
alchemy_cms-6.0.0 package/src/utils/events.js
alchemy_cms-5.3.4 package/src/utils/events.js
alchemy_cms-6.0.0.pre.rc7 package/src/utils/events.js