PluginProbe
King Addons for Elementor – 80+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce, Mega Menu, Popup Builder / 51.1.49
King Addons for Elementor – 80+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce, Mega Menu, Popup Builder v51.1.49
51.1.83 51.1.82 51.1.81 51.1.79 51.1.78 51.1.77 51.1.76 51.1.74 51.1.75 51.1.65 51.1.64 51.1.63 trunk 51.1.14 51.1.2 51.1.35 51.1.36 51.1.37 51.1.38 51.1.39 51.1.44 51.1.45 51.1.46 51.1.47 51.1.49 All 37 releases
king-addons / includes / widgets / Facet_Meta / script.js

script.js in King Addons for Elementor – 80+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce, Mega Menu, Popup Builder 51.1.49, at includes/widgets/Facet_Meta/script.js

102 lines 2.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * Facet Meta/ACF widget behavior.
3 *
4 * Dispatches filter changes through a custom event consumed by the faceted
5 * filters system.
6 */
7 (function ($) {
8 "use strict";
9
10 const FLAG = "kingAddonsFacetMetaBound";
11
12 /**
13 * Dispatch filter updates.
14 *
15 * @param {string} queryId Query identifier.
16 * @param {Object} payload Filters payload.
17 * @returns {void}
18 */
19 const dispatch = (queryId, payload) => {
20 const event = new CustomEvent("kingaddons:filters:apply", {
21 detail: {
22 queryId,
23 filters: payload,
24 },
25 });
26 document.dispatchEvent(event);
27 window.dispatchEvent(event);
28 };
29
30 /**
31 * Bind delegated listeners once per page.
32 *
33 * @returns {void}
34 */
35 const bindOnce = () => {
36 if (window[FLAG]) {
37 return;
38 }
39 window[FLAG] = true;
40
41 document.addEventListener("input", (event) => {
42 const target = event.target;
43 if (!(target instanceof Element)) {
44 return;
45 }
46
47 const wrapper = target.closest(".ka-facet-meta");
48 if (!wrapper) {
49 return;
50 }
51
52 const queryId = wrapper.dataset.kaFiltersQueryId || "";
53 const key = wrapper.dataset.kaMetaKey || "";
54 if (!queryId || !key) {
55 return;
56 }
57
58 if (
59 target.classList.contains("ka-facet-meta__input") ||
60 target.classList.contains("ka-facet-meta__select")
61 ) {
62 dispatch(queryId, {
63 meta: { [key]: target.value ? [target.value] : [] },
64 });
65 return;
66 }
67
68 if (
69 target.classList.contains("ka-facet-meta__range-min") ||
70 target.classList.contains("ka-facet-meta__range-max")
71 ) {
72 const minEl = wrapper.querySelector(".ka-facet-meta__range-min");
73 const maxEl = wrapper.querySelector(".ka-facet-meta__range-max");
74 dispatch(queryId, {
75 meta: {
76 [key]: {
77 min: minEl ? minEl.value : "",
78 max: maxEl ? maxEl.value : "",
79 },
80 },
81 });
82 }
83 });
84 };
85
86 $(window).on("elementor/frontend/init", function () {
87 elementorFrontend.hooks.addAction(
88 "frontend/element_ready/facet_meta.default",
89 function () {
90 bindOnce();
91 }
92 );
93 });
94
95 document.addEventListener("DOMContentLoaded", bindOnce);
96 })(jQuery);
97
98
99
100
101
102