| 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 |
|