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.1.8 app/javascript/alchemy_admin/utils/events.js
alchemy_cms-7.1.7 app/javascript/alchemy_admin/utils/events.js
alchemy_cms-7.0.12 app/javascript/alchemy_admin/utils/events.js
alchemy_cms-7.0.11 app/javascript/alchemy_admin/utils/events.js
alchemy_cms-7.1.6 app/javascript/alchemy_admin/utils/events.js
alchemy_cms-7.1.5 app/javascript/alchemy_admin/utils/events.js
alchemy_cms-7.0.10 app/javascript/alchemy_admin/utils/events.js
alchemy_cms-7.1.4 app/javascript/alchemy_admin/utils/events.js
alchemy_cms-7.0.9 app/javascript/alchemy_admin/utils/events.js
alchemy_cms-7.1.3 app/javascript/alchemy_admin/utils/events.js
alchemy_cms-7.1.2 app/javascript/alchemy_admin/utils/events.js
alchemy_cms-7.1.1 app/javascript/alchemy_admin/utils/events.js
alchemy_cms-7.1.0 app/javascript/alchemy_admin/utils/events.js
alchemy_cms-7.1.0.pre.rc1 app/javascript/alchemy_admin/utils/events.js
alchemy_cms-7.1.0.pre.b2 app/javascript/alchemy_admin/utils/events.js
alchemy_cms-7.1.0.pre.b1 app/javascript/alchemy_admin/utils/events.js
alchemy_cms-7.0.8 app/javascript/alchemy_admin/utils/events.js
alchemy_cms-7.0.7 app/javascript/alchemy_admin/utils/events.js
alchemy_cms-7.0.6 app/javascript/alchemy_admin/utils/events.js
alchemy_cms-7.0.5 app/javascript/alchemy_admin/utils/events.js