| 1 |
/** |
| 2 |
* Cookie Preferences Button behavior. |
| 3 |
* |
| 4 |
* Binds a delegated click handler to elements with [data-ka-cookie-manage]. |
| 5 |
* Uses Elementor frontend init hook when available. |
| 6 |
*/ |
| 7 |
(function () { |
| 8 |
const FLAG = "kingAddonsCookiePreferencesBound"; |
| 9 |
|
| 10 |
/** |
| 11 |
* Bind click handler once per page. |
| 12 |
* |
| 13 |
* @return void |
| 14 |
*/ |
| 15 |
const bindOnce = () => { |
| 16 |
if (window[FLAG]) { |
| 17 |
return; |
| 18 |
} |
| 19 |
window[FLAG] = true; |
| 20 |
|
| 21 |
document.addEventListener("click", (event) => { |
| 22 |
const target = event.target; |
| 23 |
if (!(target instanceof Element)) { |
| 24 |
return; |
| 25 |
} |
| 26 |
|
| 27 |
const trigger = target.closest("[data-ka-cookie-manage]"); |
| 28 |
if (!trigger) { |
| 29 |
return; |
| 30 |
} |
| 31 |
|
| 32 |
event.preventDefault(); |
| 33 |
|
| 34 |
if (typeof window.kingAddonsOpenConsent === "function") { |
| 35 |
window.kingAddonsOpenConsent(); |
| 36 |
return; |
| 37 |
} |
| 38 |
|
| 39 |
document.dispatchEvent( |
| 40 |
new CustomEvent("king-addons-open-cookie-settings") |
| 41 |
); |
| 42 |
}); |
| 43 |
}; |
| 44 |
|
| 45 |
document.addEventListener("DOMContentLoaded", bindOnce); |
| 46 |
|
| 47 |
// Elementor editor/frontend support. |
| 48 |
if (typeof jQuery !== "undefined") { |
| 49 |
jQuery(window).on("elementor/frontend/init", function () { |
| 50 |
if ( |
| 51 |
typeof elementorFrontend !== "undefined" && |
| 52 |
elementorFrontend.hooks && |
| 53 |
typeof elementorFrontend.hooks.addAction === "function" |
| 54 |
) { |
| 55 |
elementorFrontend.hooks.addAction( |
| 56 |
"frontend/element_ready/king-addons-cookie-preferences-button.default", |
| 57 |
function () { |
| 58 |
bindOnce(); |
| 59 |
} |
| 60 |
); |
| 61 |
} else { |
| 62 |
bindOnce(); |
| 63 |
} |
| 64 |
}); |
| 65 |
} |
| 66 |
})(); |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|