UNPKG

sweetalert2

Version:

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

32 lines (28 loc) 754 B
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 } } } }