1(function($, Drupal, drupalSettings) { 2 $(document).ready(function() { 3 4 // new countdown script to avoid breaking functionality of old countdown 5 // and possibility to use new date given from server (avoiding browser date) 6 7 "use strict"; 8 9 let startPercentage, // should be the custom post creation date (needed for percentage calculation) 10 countdownDate, 11 currentDate, 12 stopCount = false, 13 progressBar, 14 days, 15 hrs, 16 min, 17 sec, 18 percentage; 19 20 function timeToCountdown() { 21 22 // remove 1000 milliseconds from parsed date 23 currentDate += 1000; 24 25 let calcDiff = (currentDate - countdownDate)/1000; 26 let diff = Math.abs(Math.floor(calcDiff)); 27 28 percentage = Math.round((currentDate - startPercentage) / (+countdownDate - +startPercentage) * 100) / 100; // calculate from 0 to 1 leaving 2 decimals 29 30 31 if (calcDiff < 0) { 32 // Check number of days until target 33 days = Math.floor(diff/(24*60*60)); 34 sec = diff - days * 24*60*60; 35 36 // Check number of hours until target 37 hrs = Math.floor(sec/(60*60)); 38 sec = sec - hrs * 60*60; 39 40 // Check number of minutes until target 41 min = Math.floor(sec/(60)); 42 sec = sec - min * 60; 43 } else { 44 days = 0; 45 hrs = 0; 46 min = 0; 47 sec = 0; 48 percentage = 1; 49 stopCount = true; 50 } 51 } 52 53 function countDownTimer() { 54 // Recalculate time 55 timeToCountdown(); 56 57 // Write to countdown component 58 $( "#js-countdown-days .countdown__number" ).text(days > 9 ? days : '0' + days); 59 $( "#js-countdown-hours .countdown__number" ).text(hrs > 9 ? hrs : '0' + hrs); 60 $( "#js-countdown-minutes .countdown__number" ).text(min > 9 ? min : '0' + min); 61 // $( "#js-countdown-seconds .countdown__number" ).text(sec > 9 ? sec : '0' + sec); 62 progressBar.css("stroke-dashoffset", 100 - (percentage * 100)); 63 64 // Repeat the check every second 65 if (!stopCount) { 66 setTimeout(countDownTimer,1000); 67 } 68 } 69 70 function startCountdown() { 71 if ($("#js-countdown").length > 0) { 72 // SAFARI bug: use the date format with a "T" instead of a space between date and time (e.g.: 2024-05-25T14:44:24) or else the browser won't recognize it correctly 73 startPercentage = Date.parse($("#js-countdown").attr("data-startpercentage")); 74 countdownDate = Date.parse($("#js-countdown").attr("data-countdowndate")); 75 currentDate = Date.parse($("#js-countdown").attr("data-currentdate")); 76 progressBar = $("#js-countdown-progress"); 77 78 // Start countdown if container exists 79 countDownTimer(); 80 } 81 82 } 83 84 startCountdown(); 85 86 }); 87})(jQuery, Drupal, drupalSettings);
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.