All Downloads are FREE. Search and download functionalities are using the official Maven repository.

package.src.staticMethods.bindClickHandler.js Maven / Gradle / Ivy

Go to download

A beautiful, responsive, customizable and accessible (WAI-ARIA) replacement for JavaScript's popup boxes, supported fork of sweetalert

The newest version!
let bodyClickListenerAdded = false
const clickHandlers = {}

/**
 * @param {string} attr
 */
export function bindClickHandler(attr = 'data-swal-template') {
  clickHandlers[attr] = this

  if (!bodyClickListenerAdded) {
    document.body.addEventListener('click', bodyClickListener)
    bodyClickListenerAdded = true
  }
}

const bodyClickListener = (event) => {
  for (let el = event.target; el && el !== document; el = el.parentNode) {
    for (const attr in clickHandlers) {
      const template = el.getAttribute(attr)
      if (template) {
        clickHandlers[attr].fire({ template })
        return
      }
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy