1class CountdownPlus{ 2 constructor(uid) { 3 this.wrapper = false; 4 this.numbersWrapper = false; 5 6 this.seconds = 0 7 this.minutes = 0 8 this.hours = 0 9 this.days = 0 10 this.textBefore = false 11 this.textAfter = false 12 this.endDate = new Date().getTime(); 13 this.endTime = 14 this.interval = null 15 this.wrapper = false 16 this.uid = uid 17 this.selectors = { 18 wrapper:'[data-dzm-cdp-wrapper="'+uid+'"]', 19 numbersWrapper:'[data-dzm-cdp-numbers-wrapper="'+uid+'"]', 20 secondSelector:'[data-dzm-cdp-seconds="'+uid+'"]', 21 minuteSelector:'[data-dzm-cdp-minutes="'+uid+'"]', 22 hourSelector:'[data-dzm-cdp-hours="'+uid+'"]', 23 daySelector:'[data-dzm-cdp-days="'+uid+'"]', 24 textBefore:'[data-dzm-cdp-text-before="'+uid+'"]', 25 textAfter:'[data-dzm-cdp-text-after="'+uid+'"]', 26 } 27 } 28 29 init(options){ 30 console.log('init CountdownPlus',options); 31 if((this.wrapper = document.querySelector(this.selectors.wrapper)) == null){ 32 console.error('no countdown wrapper') 33 return 34 } 35 if((this.numbersWrapper = document.querySelector(this.selectors.numbersWrapper)) == null){ 36 console.error('no numbers wrapper') 37 return 38 } 39 if((this.seconds = document.querySelector(this.selectors.secondSelector)) == null){ 40 console.error('no seconds wrapper') 41 return 42 } 43 if((this.minutes = document.querySelector(this.selectors.minuteSelector)) == null){ 44 console.error('no minutes wrapper') 45 return 46 } 47 if((this.hours = document.querySelector(this.selectors.hourSelector)) == null){ 48 console.error('no hours wrapper') 49 return 50 } 51 if((this.days = document.querySelector(this.selectors.daySelector)) == null){ 52 console.error('no days wrapper') 53 return 54 } 55 56 if((this.textBefore = document.querySelector(this.selectors.textBefore)) == null){ 57 console.error('no days wrapper') 58 return 59 } 60 61 if((this.textAfter = document.querySelector(this.selectors.textAfter)) == null){ 62 console.error('no days wrapper') 63 return 64 } 65 66 if(!options.type){ 67 console.error('no type set',options) 68 return 69 } 70 71 let endDate = new Date(); 72 if(options.type === 'static'){ 73 if(!options.endDate ){ 74 console.error('No enddate set', options); 75 return 76 } 77 endDate = options.endDate 78 }else{ 79 if(!options.endTime ){ 80 console.error('No endTime set', options); 81 return 82 } 83 let today = endDate 84 console.log(today) 85 86 switch (today.getDay()){ 87 case 0: 88 if(options.repeatSunday == 0) 89 today=new Date(today.getDate() - 1) 90 break; 91 case 1: 92 if(options.repeatMonday == 0) 93 today=new Date(today.getDate() - 1) 94 break; 95 case 2: 96 if(options.repeatTuesday == 0) 97 today=new Date(today.getDate() - 1) 98 break; 99 case 3: 100 if(options.repeatWednesday == 0) 101 today=new Date(today.getDate() - 1) 102 break; 103 case 4: 104 if(options.repeatThursday == 0) 105 today=new Date(today.getDate() - 1) 106 break; 107 case 5: 108 if(options.repeatFriday == 0) 109 today=new Date(today.getDate() - 1) 110 break; 111 case 6: 112 if(options.repeatSaturday == 0) 113 today=new Date(today.getDate() - 1) 114 break; 115 default: 116 break; 117 118 119 } 120 console.log(today) 121 endDate = new Date(today.getFullYear()+'-'+((today.getMonth()+1) <=9 ? '0'+(today.getMonth()+1) : (today.getMonth()+1)) + '-' + ((today.getDate()) <=9 ? '0'+(today.getDate()) : (today.getDate())) + ' ' + options.endTime + ':00') 122 123 } 124 125 126 127 this.interval = setInterval(()=>{ 128 let now = new Date().getTime(); 129 130 131 //now += 60000 132 const distance = new Date(endDate)-now; 133 134 135 136 137 const days = Math.floor(distance / (1000 * 60 * 60 * 24)); 138 const hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)); 139 const minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60)); 140 const seconds = Math.floor((distance % (1000 * 60)) / 1000); 141 142 this.days.innerHTML = (days < 0 ? '00' : String(days).padStart(2, '0'))+options.daySuffix; 143 this.hours.innerHTML = (hours < 0 ? '00' : String(hours).padStart(2, '0'))+options.hourSuffix; 144 this.minutes.innerHTML = (minutes < 0 ? '00' : String(minutes).padStart(2, '0'))+options.minuteSuffix; 145 this.seconds.innerHTML = (seconds < 0 ? '00' : String(seconds).padStart(2, '0'))+options.secondSuffix; 146 147 // Hide elements if they are zero 148 if (days <= 0 && options.hideExpiredElements) { 149 this.days.style.display = 'none'; 150 } else { 151 this.days.style.display = 'inline'; 152 } 153 154 if (days <= 0 && hours <= 0 && options.hideExpiredElements) { 155 this.hours.style.display = 'none'; 156 } else { 157 this.hours.style.display = 'inline'; 158 } 159 160 if ( days <= 0 && hours <= 0 && minutes <= 0 && options.hideExpiredElements) { 161 this.minutes.style.display = 'none'; 162 } else { 163 this.minutes.style.display = 'inline'; 164 } 165 /*if (days <= 0 && hours <= 0 && minutes <= 0 && seconds <= 0 ) { 166 this.seconds.style.display = 'none'; 167 } else { 168 this.seconds.style.display = 'inline'; 169 }*/ 170 171 172 if(distance <= 0 ){ 173 // TIMER EXPIRED 174 if(options.expiredStyle === 'hide'){ 175 this.wrapper.style.display = 'none' 176 this.wrapper.classList.add('d-none') 177 this.wrapper.classList.remove('d-flex') 178 }else if(options.expiredStyle === 'hideTimer'){ 179 this.numbersWrapper.classList.add('d-none') 180 this.numbersWrapper.classList.remove('d-flex') 181 this.textAfter.style.display = 'none' 182 this.textBefore.innerText = options.textExpired 183 }else{ 184 this.textBefore.innerHTML = options.textBeforeExpired + ' ' 185 this.textAfter.innerHTML = ' ' + options.textAfterExpired 186 187 } 188 clearInterval(this.interval) 189 } 190 191 },100) 192 193 } 194}
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.