1jQuery(function ($) { 2 3 /*----------------------------------------------------------- 4 * Run the countdown logic once for **every** .fancy-timer box 5 *-----------------------------------------------------------*/ 6 $('.fancy-timer').each(function () { 7 /*â 1. Scope everything to the current timer â*/ 8 const $timer = $(this); 9 const endTime = new Date($timer.data('end-date')).getTime(); 10 11 /*â 2. Cache <span> placeholders â*/ 12 const $daysVal = $timer.find('[data-time="days"]'); 13 const $hoursVal = $timer.find('[data-time="hours"]'); 14 const $minutesVal = $timer.find('[data-time="minutes"]'); 15 const $secondsVal = $timer.find('[data-time="seconds"]'); 16 17 /*â 3. Helper: create the coloured SVG ring â*/ 18 function createCircle($container, color) { 19 const svgNS = 'http://www.w3.org/2000/svg'; 20 21 const svg = document.createElementNS(svgNS, 'svg'); 22 const circle = document.createElementNS(svgNS, 'circle'); 23 24 $(svg).attr({ width: 70, height: 70 }) 25 .css({ position: 'absolute', top: 0, left: 0 }); 26 27 $(circle).attr({ 28 cx: 35, cy: 35, r: 30, 29 stroke: color, 'stroke-width': 8, fill: 'transparent' 30 }).css({ transform: 'rotate(-90deg)', transformOrigin: '50% 50%' }); 31 32 svg.appendChild(circle); 33 $container.css('position', 'relative').append(svg); 34 35 const circumference = 2 * Math.PI * 30; 36 $(circle).attr({ 'stroke-dasharray': circumference, 'stroke-dashoffset': 0 }); 37 38 return { $circle: $(circle), circumference }; 39 } 40 41 /*â 4. Build a ring for each segment â*/ 42 const days = createCircle($timer.find('[data-segment="days"]'), '#ff0f13'); 43 const hours = createCircle($timer.find('[data-segment="hours"]'), '#ff5f0f'); 44 const mins = createCircle($timer.find('[data-segment="minutes"]'), '#0f53ff'); 45 const secs = createCircle($timer.find('[data-segment="seconds"]'), '#47ff0f'); 46 47 /*â 5. Tick-tock â*/ 48 function update() { 49 const now = Date.now(); 50 const diff = Math.max(0, endTime - now); 51 52 if (diff === 0) { 53 $timer.html('<span style="font-size:30px;font-weight:bold;color:red;">Sale has ended</span>'); 54 clearInterval(tick); 55 return; 56 } 57 58 const s = Math.floor((diff / 1000) % 60); 59 const m = Math.floor((diff / (1000 * 60)) % 60); 60 const h = Math.floor((diff / (1000 * 60 * 60)) % 24); 61 const d = Math.floor(diff / (1000 * 60 * 60 * 24)); 62 63 $daysVal.text(String(d).padStart(2, '0')); 64 $hoursVal.text(String(h).padStart(2, '0')); 65 $minutesVal.text(String(m).padStart(2, '0')); 66 $secondsVal.text(String(s).padStart(2, '0')); 67 68 days .$circle.attr('stroke-dashoffset', -days .circumference * (1 - d / 30)); 69 hours.$circle.attr('stroke-dashoffset', -hours.circumference * (1 - h / 24)); 70 mins .$circle.attr('stroke-dashoffset', -mins .circumference * (1 - m / 60)); 71 secs .$circle.attr('stroke-dashoffset', -secs .circumference * (1 - s / 60)); 72 } 73 74 update(); // immediate first paint 75 const tick = setInterval(update, 1000); // store per-timer interval 76 }); 77});
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.