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.0.4 app/javascript/alchemy_admin/utils/events.js
alchemy_cms-7.0.3 app/javascript/alchemy_admin/utils/events.js
alchemy_cms-6.1.9 package/src/utils/events.js
alchemy_cms-7.0.2 app/javascript/alchemy_admin/utils/events.js
alchemy_cms-6.1.8 package/src/utils/events.js
alchemy_cms-6.1.7 package/src/utils/events.js
alchemy_cms-7.0.1 app/javascript/alchemy_admin/utils/events.js
alchemy_cms-7.0.0 app/javascript/alchemy_admin/utils/events.js
alchemy_cms-7.0.0.pre.rc1 app/javascript/alchemy_admin/utils/events.js
alchemy_cms-6.1.6 package/src/utils/events.js
alchemy_cms-7.0.0.pre.c app/javascript/alchemy_admin/utils/events.js
alchemy_cms-7.0.0.pre.b package/src/utils/events.js
alchemy_cms-6.1.5 package/src/utils/events.js
alchemy_cms-6.0.14 package/src/utils/events.js
alchemy_cms-6.1.4 package/src/utils/events.js
alchemy_cms-7.0.0.pre.a package/src/utils/events.js
alchemy_cms-6.0.13 package/src/utils/events.js
alchemy_cms-6.1.3 package/src/utils/events.js
alchemy_cms-6.1.2 package/src/utils/events.js
alchemy_cms-6.1.1 package/src/utils/events.js