1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235: 236: 237: 238: 239: 240: 241: 242: 243: 244: 245: 246: 247: 248: 249: 250: 251: 252: 253: 254: 255: 256: 257: 258: 259: 260: 261: 262: 263: 264: 265: 266: 267: 268: 269: 270: 271: 272: 273: 274: 275: 276: 277: 278: 279: 280: 281: 282: 283: 284: 285:
|
(function (exports) { 'use strict';
var extend, createElements, createCountdownElt, simplyCountdown;
extend = function (out) { var i, obj, key; out = out || {};
for (i = 1; i < arguments.length; i += 1) { obj = arguments[i];
if (obj) { for (key in obj) { if (obj.hasOwnProperty(key)) { if (typeof obj[key] === 'object') { extend(out[key], obj[key]); } else { out[key] = obj[key]; } } } } }
return out; };
createCountdownElt = function (countdown, parameters, typeClass) { var innerSectionTag, sectionTag, amountTag, wordTag;
sectionTag = document.createElement('div'); amountTag = document.createElement('span'); wordTag = document.createElement('span'); innerSectionTag = document.createElement('div');
innerSectionTag.appendChild(amountTag); innerSectionTag.appendChild(wordTag); sectionTag.appendChild(innerSectionTag);
sectionTag.classList.add(parameters.sectionClass); sectionTag.classList.add(typeClass); amountTag.classList.add(parameters.amountClass); wordTag.classList.add(parameters.wordClass);
countdown.appendChild(sectionTag);
return { full: sectionTag, amount: amountTag, word: wordTag }; };
createElements = function (parameters, countdown) { var spanTag;
if (!parameters.inline) { return { days: createCountdownElt(countdown, parameters, 'simply-days-section'), hours: createCountdownElt(countdown, parameters, 'simply-hours-section'), minutes: createCountdownElt(countdown, parameters, 'simply-minutes-section'), seconds: createCountdownElt(countdown, parameters, 'simply-seconds-section') }; }
spanTag = document.createElement('span'); spanTag.classList.add(parameters.inlineClass); return spanTag; };
simplyCountdown = function (elt, args) { var parameters = extend({ year: 2019, month: 6, day: 1, hours: 14, minutes: 0, seconds: 0, words: { days: 'Tage', hours: 'Stunde', minutes: 'Minute', seconds: 'Sekunde', pluralLetter: 'n' }, plural: true, inline: false, enableUtc: true, onEnd: function () { return; }, refresh: 1000, inlineClass: 'simply-countdown-inline', sectionClass: 'simply-section', amountClass: 'simply-amount', wordClass: 'simply-word', zeroPad: false }, args), interval, targetDate, targetTmpDate, now, nowUtc, secondsLeft, days, hours, minutes, seconds, cd = document.querySelectorAll(elt);
targetTmpDate = new Date( parameters.year, parameters.month - 1, parameters.day, parameters.hours, parameters.minutes, parameters.seconds );
if (parameters.enableUtc) { targetDate = new Date( targetTmpDate.getUTCFullYear(), targetTmpDate.getUTCMonth(), targetTmpDate.getUTCDate(), targetTmpDate.getUTCHours(), targetTmpDate.getUTCMinutes(), targetTmpDate.getUTCSeconds() ); } else { targetDate = targetTmpDate; }
Array.prototype.forEach.call(cd, function (countdown) { var fullCountDown = createElements(parameters, countdown), refresh;
refresh = function () { var dayWord, hourWord, minuteWord, secondWord;
now = new Date(); if (parameters.enableUtc) { nowUtc = new Date(now.getFullYear(), now.getMonth(), now.getDate(), now.getHours(), now.getMinutes(), now.getSeconds()); secondsLeft = (targetDate - nowUtc.getTime()) / 1000;
} else { secondsLeft = (targetDate - now.getTime()) / 1000; }
if (secondsLeft > 0) { days = parseInt(secondsLeft / 86400, 10); secondsLeft = secondsLeft % 86400;
hours = parseInt(secondsLeft / 3600, 10); secondsLeft = secondsLeft % 3600;
minutes = parseInt(secondsLeft / 60, 10); seconds = parseInt(secondsLeft % 60, 10); } else { days = 0; hours = 0; minutes = 0; seconds = 0; window.clearInterval(interval); parameters.onEnd(); }
if (parameters.plural) { dayWord = days > 1 ? parameters.words.days + parameters.words.pluralLetter : parameters.words.days;
hourWord = hours > 1 ? parameters.words.hours + parameters.words.pluralLetter : parameters.words.hours;
minuteWord = minutes > 1 ? parameters.words.minutes + parameters.words.pluralLetter : parameters.words.minutes;
secondWord = seconds > 1 ? parameters.words.seconds + parameters.words.pluralLetter : parameters.words.seconds;
} else { dayWord = parameters.words.days; hourWord = parameters.words.hours; minuteWord = parameters.words.minutes; secondWord = parameters.words.seconds; }
/* display an inline countdown into a span tag */ if (parameters.inline) { countdown.innerHTML = days + ' ' + dayWord + ', ' + hours + ' ' + hourWord + ', ' + minutes + ' ' + minuteWord + ', ' + seconds + ' ' + secondWord + '.';
} else { fullCountDown.days.amount.textContent = (parameters.zeroPad && days.toString().length < 2 ? '0' : '') + days; fullCountDown.days.word.textContent = dayWord;
fullCountDown.hours.amount.textContent = (parameters.zeroPad && hours.toString().length < 2 ? '0' : '') + hours; fullCountDown.hours.word.textContent = hourWord;
fullCountDown.minutes.amount.textContent = (parameters.zeroPad && minutes.toString().length < 2 ? '0' : '') + minutes; fullCountDown.minutes.word.textContent = minuteWord;
fullCountDown.seconds.amount.textContent = (parameters.zeroPad && seconds.toString().length < 2 ? '0' : '') + seconds; fullCountDown.seconds.word.textContent = secondWord; } };
// Refresh immediately to prevent a Flash of Unstyled Content refresh(); interval = window.setInterval(refresh, parameters.refresh); }); };
exports.simplyCountdown = simplyCountdown; }(window));
/*global $, jQuery, simplyCountdown*/ if (window.jQuery) { (function ($, simplyCountdown) { 'use strict';
function simplyCountdownify(el, options) { simplyCountdown(el, options); }
$.fn.simplyCountdown = function (options) { return simplyCountdownify(this.selector, options); }; }(jQuery, simplyCountdown)); } |