Files
ares/public/assets/sweetalert2/src/staticMethods/bindClickHandler.js
Beyhan Oğur 4d92991817 first commit
2026-04-26 21:30:42 +03:00

32 lines
754 B
JavaScript

let bodyClickListenerAdded = false
/** @type {Record<string, any>} */
const clickHandlers = {}
/**
* @this {any}
* @param {string} attr
*/
export function bindClickHandler(attr = 'data-swal-template') {
clickHandlers[attr] = this
if (!bodyClickListenerAdded) {
document.body.addEventListener('click', bodyClickListener)
bodyClickListenerAdded = true
}
}
/**
* @param {MouseEvent} event
*/
const bodyClickListener = (event) => {
for (let el = /** @type {any} */ (event.target); el && el !== document; el = el.parentNode) {
for (const attr in clickHandlers) {
const template = el.getAttribute && el.getAttribute(attr)
if (template) {
clickHandlers[attr].fire({ template })
return
}
}
}
}