PluginProbe
King Addons for Elementor – 80+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce, Mega Menu, Popup Builder / 51.1.65
King Addons for Elementor – 80+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce, Mega Menu, Popup Builder v51.1.65
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 / Event_Calendar / script.js

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

100 lines 3.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 "use strict";
2
3 (function ($) {
4 const parseDate = (value) => {
5 const ts = parseInt(value, 10);
6 if (Number.isNaN(ts)) {
7 return null;
8 }
9 return ts * 1000;
10 };
11
12 const matchSearch = (text, query) => {
13 if (!query) return true;
14 return text.toLowerCase().includes(query.toLowerCase());
15 };
16
17 const matchCategory = (category, selected) => {
18 if (!selected || selected === "all") return true;
19 return (category || "").toLowerCase() === selected.toLowerCase();
20 };
21
22 const matchUpcoming = (startTs) => {
23 if (!startTs) return true;
24 const now = Date.now();
25 return startTs >= now;
26 };
27
28 const matchDateRange = (startTs, fromTs, toTs) => {
29 if (!startTs) return true;
30 if (fromTs && startTs < fromTs) return false;
31 if (toTs && startTs > toTs) return false;
32 return true;
33 };
34
35 const applyFilters = ($scope) => {
36 const $wrapper = $scope.find(".king-addons-event-calendar");
37 if (!$wrapper.length || $wrapper.data("has-filters") !== "yes") {
38 return;
39 }
40
41 const $items = $wrapper.find(".king-addons-event-calendar__item");
42 const searchVal = ($wrapper.find('[data-filter="search"]').val() || "").trim();
43 const categoryVal = $wrapper.find('[data-filter="category"]').val() || "all";
44 const upcomingOnly = $wrapper.find('[data-filter="upcoming"]').is(":checked");
45 const fromVal = $wrapper.find('[data-filter="from"]').val();
46 const toVal = $wrapper.find('[data-filter="to"]').val();
47
48 const fromTs = fromVal ? Date.parse(fromVal) : null;
49 const toTs = toVal ? Date.parse(toVal) : null;
50
51 $items.each(function () {
52 const $item = $(this);
53 const start = parseDate($item.data("date-start"));
54 const title = ($item.data("title") || "").toString();
55 const category = ($item.data("category") || "").toString();
56
57 const passesSearch = matchSearch(title, searchVal);
58 const passesCategory = matchCategory(category, categoryVal);
59 const passesUpcoming = !upcomingOnly || matchUpcoming(start);
60 const passesRange = matchDateRange(start, fromTs, toTs);
61
62 if (passesSearch && passesCategory && passesUpcoming && passesRange) {
63 $item.show();
64 } else {
65 $item.hide();
66 }
67 });
68 };
69
70 const initEventCalendar = ($scope) => {
71 const $wrapper = $scope.find(".king-addons-event-calendar");
72 if (!$wrapper.length) {
73 return;
74 }
75
76 if ($wrapper.data("has-filters") === "yes") {
77 $wrapper.on("input change", "[data-filter]", function () {
78 applyFilters($scope);
79 });
80 applyFilters($scope);
81 }
82 };
83
84 $(window).on("elementor/frontend/init", function () {
85 elementorFrontend.hooks.addAction(
86 "frontend/element_ready/king-addons-event-calendar.default",
87 function ($scope) {
88 initEventCalendar($scope);
89 }
90 );
91 });
92 })(jQuery);
93
94
95
96
97
98
99
100