1jQuery(window).on("elementor/frontend/init", function () { 2 elementorFrontend.hooks.addAction( 3 "frontend/element_ready/rkit-countdown.default", 4 function ($scope, $) { 5 function formatDate(dateString) { 6 var parts = dateString.split(" "); 7 if (parts.length === 2) { 8 var datePart = parts[0]; 9 var timePart = parts[1]; 10 var timeParts = timePart.split(":"); 11 if (timeParts.length === 3 && timeParts[2].length === 1) { 12 timeParts[2] = "0" + timeParts[2]; 13 } 14 return datePart + "T" + timeParts.join(":"); 15 } 16 return ""; 17 } 18 19 function initFlipCountdown($countdown, endDate) { 20 if ($countdown.data("skin") !== "flip") return; 21 if (!endDate) return; 22 23 const formattedDate = formatDate(endDate); 24 const countDownDate = new Date(formattedDate).getTime(); 25 if (isNaN(countDownDate)) return; 26 27 const pieces = {}; 28 $countdown.find(".flip-clock__piece").each(function () { 29 const key = $(this).data("key"); 30 const el = this; 31 const top = el.querySelector(".card__top"); 32 const bottom = el.querySelector(".card__bottom"); 33 const back = el.querySelector(".card__back"); 34 const backBottom = el.querySelector(".card__back .card__bottom"); 35 36 pieces[key] = { 37 el, 38 update(val) { 39 val = val < 10 ? "0" + val : String(val); 40 if (val !== el.dataset.value) { 41 if (el.dataset.value) { 42 back.setAttribute("data-value", el.dataset.value); 43 bottom.setAttribute("data-value", el.dataset.value); 44 } 45 el.dataset.value = val; 46 top.innerText = val; 47 backBottom.setAttribute("data-value", val); 48 el.classList.remove("flip"); 49 void el.offsetWidth; 50 el.classList.add("flip"); 51 } 52 }, 53 }; 54 }); 55 56 const timer = setInterval(() => { 57 const now = new Date().getTime(); 58 const distance = countDownDate - now; 59 60 if (distance < 0) { 61 clearInterval(timer); 62 Object.values(pieces).forEach((p) => p.update(0)); 63 var expiredSection = $scope.find(".expired-time-section"); 64 var countdownWidget = $scope.find(".count"); 65 if (expiredSection.length && countdownWidget.length) { 66 expiredSection.show(); 67 countdownWidget.hide(); 68 } 69 return; 70 } 71 72 const days = Math.floor(distance / (1000 * 60 * 60 * 24)); 73 const hours = Math.floor((distance / (1000 * 60 * 60)) % 24); 74 const minutes = Math.floor((distance / (1000 * 60)) % 60); 75 const seconds = Math.floor((distance / 1000) % 60); 76 77 if (pieces.days) pieces.days.update(days); 78 if (pieces.hours) pieces.hours.update(hours); 79 if (pieces.minutes) pieces.minutes.update(minutes); 80 if (pieces.seconds) pieces.seconds.update(seconds); 81 }, 1000); 82 83 $countdown.data("interval", timer); 84 } 85 86 function updateCountdownNormal($element, endDate) { 87 if (!endDate) return; 88 var formattedDate = formatDate(endDate); 89 var countDownDate = new Date(formattedDate).getTime(); 90 if (isNaN(countDownDate)) return; 91 92 $element.find(".countdown-days").text("00"); 93 $element.find(".countdown-hours").text("00"); 94 $element.find(".countdown-minutes").text("00"); 95 $element.find(".countdown-seconds").text("00"); 96 97 var x = setInterval(function () { 98 var now = new Date().getTime(); 99 var distance = countDownDate - now; 100 101 var days = Math.floor(distance / (1000 * 60 * 60 * 24)); 102 var hours = Math.floor( 103 (distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60), 104 ); 105 var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60)); 106 var seconds = Math.floor((distance % (1000 * 60)) / 1000); 107 108 var daysStr = (days < 10 ? "0" + days : days).toString(); 109 var hoursStr = (hours < 10 ? "0" + hours : hours).toString(); 110 var minutesStr = (minutes < 10 ? "0" + minutes : minutes).toString(); 111 var secondsStr = (seconds < 10 ? "0" + seconds : seconds).toString(); 112 113 if ($element.find(".countdown-days").text() !== daysStr) 114 $element.find(".countdown-days").text(daysStr); 115 if ($element.find(".countdown-hours").text() !== hoursStr) 116 $element.find(".countdown-hours").text(hoursStr); 117 if ($element.find(".countdown-minutes").text() !== minutesStr) 118 $element.find(".countdown-minutes").text(minutesStr); 119 if ($element.find(".countdown-seconds").text() !== secondsStr) 120 $element.find(".countdown-seconds").text(secondsStr); 121 122 if (distance < 0) { 123 clearInterval(x); 124 $element.find(".countdown-days").text("00"); 125 $element.find(".countdown-hours").text("00"); 126 $element.find(".countdown-minutes").text("00"); 127 $element.find(".countdown-seconds").text("00"); 128 129 var expiredSection = $scope.find(".expired-time-section"); 130 var countdownWidget = $scope.find(".count"); 131 if (expiredSection.length && countdownWidget.length) { 132 expiredSection.show(); 133 countdownWidget.hide(); 134 } 135 } 136 }, 1000); 137 138 $element.data("interval", x); 139 } 140 141 const $countdown = $scope.find("#countdown"); 142 const endDate = $countdown.data("date"); 143 const skin = $countdown.data("skin"); 144 const useFlip = skin === "flip"; 145 146 const existingInterval = $countdown.data("interval"); 147 if (existingInterval) clearInterval(existingInterval); 148 149 if (useFlip) { 150 initFlipCountdown($countdown, endDate); 151 } else { 152 updateCountdownNormal($countdown, endDate); 153 } 154 155 $countdown.on("change", function () { 156 const newEndDate = $(this).data("date"); 157 const prevInterval = $(this).data("interval"); 158 if (prevInterval) clearInterval(prevInterval); 159 160 if (useFlip) { 161 initFlipCountdown($(this), newEndDate); 162 } else { 163 updateCountdownNormal($(this), newEndDate); 164 } 165 }); 166 }, 167 ); 168});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.