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 / Promo_Bar / 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/Promo_Bar/script.js

82 lines 2.5 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 STORAGE_KEY = "king_addons_promo_bar_closed";
5
6 const matchConditions = (conditions) => {
7 if (!conditions) {
8 return true;
9 }
10 try {
11 const parsed = JSON.parse(conditions);
12 if (parsed.utms && Array.isArray(parsed.utms) && parsed.utms.length > 0) {
13 const urlParams = new URLSearchParams(window.location.search);
14 const utmMatch = parsed.utms.some((utm) => urlParams.get(utm.key) === utm.value);
15 if (!utmMatch) {
16 return false;
17 }
18 }
19 if (parsed.paths && Array.isArray(parsed.paths) && parsed.paths.length > 0) {
20 const currentPath = window.location.pathname.replace(/\/+$/, "");
21 const normalized = currentPath === "" ? "/" : currentPath;
22 const allowed = parsed.paths.includes(normalized);
23 if (!allowed) {
24 return false;
25 }
26 }
27 if (parsed.schedule) {
28 const now = Date.now();
29 const start = parsed.schedule.start ? Date.parse(parsed.schedule.start) : null;
30 const end = parsed.schedule.end ? Date.parse(parsed.schedule.end) : null;
31 if ((start && now < start) || (end && now > end)) {
32 return false;
33 }
34 }
35 } catch (e) {
36 // Fail-open for malformed data.
37 return true;
38 }
39 return true;
40 };
41
42 const initPromoBar = ($scope) => {
43 const $bar = $scope.find(".king-addons-promo-bar");
44 if (!$bar.length) {
45 return;
46 }
47
48 if (localStorage.getItem(STORAGE_KEY) === "1") {
49 $bar.addClass("is-hidden");
50 return;
51 }
52
53 const conditions = $bar.data("conditions");
54 if (!matchConditions(conditions)) {
55 $bar.addClass("is-hidden");
56 return;
57 }
58
59 const $close = $bar.find(".king-addons-promo-bar__close");
60 $close.on("click", function () {
61 localStorage.setItem(STORAGE_KEY, "1");
62 $bar.addClass("is-hidden");
63 });
64 };
65
66 $(window).on("elementor/frontend/init", function () {
67 elementorFrontend.hooks.addAction(
68 "frontend/element_ready/king-addons-promo-bar.default",
69 function ($scope) {
70 initPromoBar($scope);
71 }
72 );
73 });
74 })(jQuery);
75
76
77
78
79
80
81
82