1/* eslint-disable */
vendor: 9,372 bytes, lines 2-278
2"use strict"; 3 4function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } 5 6function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } 7 8function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } 9 10function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } 11 12var FlipDown = function () { 13 function FlipDown(uts) { 14 var el = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "flipdown"; 15 var opt = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; 16 17 _classCallCheck(this, FlipDown); 18 19 if (typeof uts !== "number") { 20 throw new Error("FlipDown: Constructor expected unix timestamp, got ".concat(_typeof(uts), " instead.")); 21 } 22 23 if (_typeof(el) === "object") { 24 opt = el; 25 el = "flipdown"; 26 } 27 28 this.version = "0.3.2"; 29 this.initialised = false; 30 this.now = this._getTime(); 31 this.epoch = uts; 32 this.countdownEnded = false; 33 this.hasEndedCallback = null; 34 this.element = document.getElementById(el); 35 this.rotors = []; 36 this.rotorLeafFront = []; 37 this.rotorLeafRear = []; 38 this.rotorTops = []; 39 this.rotorBottoms = []; 40 this.countdown = null; 41 this.daysRemaining = 0; 42 this.clockValues = {}; 43 this.clockStrings = {}; 44 this.clockValuesAsString = []; 45 this.prevClockValuesAsString = []; 46 this.opts = this._parseOptions(opt); 47 48 this._setOptions(); 49 50 console.log("FlipDown ".concat(this.version, " (Theme: ").concat(this.opts.theme, ")")); 51 } 52 53 _createClass(FlipDown, [{ 54 key: "start", 55 value: function start() { 56 if (!this.initialised) this._init(); 57 this.countdown = setInterval(this._tick.bind(this), 1000); 58 return this; 59 } 60 }, { 61 key: "ifEnded", 62 value: function ifEnded(cb) { 63 this.hasEndedCallback = function () { 64 cb(); 65 this.hasEndedCallback = null; 66 }; 67 68 return this; 69 } 70 }, { 71 key: "_getTime", 72 value: function _getTime() { 73 return new Date().getTime() / 1000; 74 } 75 }, { 76 key: "_hasCountdownEnded", 77 value: function _hasCountdownEnded() { 78 if (this.epoch - this.now < 0) { 79 this.countdownEnded = true; 80 81 if (this.hasEndedCallback != null) { 82 this.hasEndedCallback(); 83 this.hasEndedCallback = null; 84 } 85 86 return true; 87 } else { 88 this.countdownEnded = false; 89 return false; 90 } 91 } 92 }, { 93 key: "_parseOptions", 94 value: function _parseOptions(opt) { 95 var headings = ["Days", "Hours", "Minutes", "Seconds"]; 96 97 if (opt.headings && opt.headings.length === 4) { 98 headings = opt.headings; 99 } 100 101 return { 102 theme: opt.hasOwnProperty("theme") ? opt.theme : "dark", 103 headings: headings 104 }; 105 } 106 }, { 107 key: "_setOptions", 108 value: function _setOptions() { 109 this.element.classList.add("flipdown__theme-".concat(this.opts.theme)); 110 } 111 }, { 112 key: "_init", 113 value: function _init() { 114 this.initialised = true; 115 116 if (this._hasCountdownEnded()) { 117 this.daysremaining = 0; 118 } else { 119 this.daysremaining = Math.floor((this.epoch - this.now) / 86400).toString().length; 120 } 121 122 var dayRotorCount = this.daysremaining <= 2 ? 2 : this.daysremaining; 123 124 for (var i = 0; i < dayRotorCount + 6; i++) { 125 this.rotors.push(this._createRotor(0)); 126 } 127 128 var dayRotors = []; 129 130 for (var i = 0; i < dayRotorCount; i++) { 131 dayRotors.push(this.rotors[i]); 132 } 133 134 this.element.appendChild(this._createRotorGroup(dayRotors, 0)); 135 var count = dayRotorCount; 136 137 for (var i = 0; i < 3; i++) { 138 var otherRotors = []; 139 140 for (var j = 0; j < 2; j++) { 141 otherRotors.push(this.rotors[count]); 142 count++; 143 } 144 145 this.element.appendChild(this._createRotorGroup(otherRotors, i + 1)); 146 } 147 148 this.rotorLeafFront = Array.prototype.slice.call(this.element.getElementsByClassName("rotor-leaf-front")); 149 this.rotorLeafRear = Array.prototype.slice.call(this.element.getElementsByClassName("rotor-leaf-rear")); 150 this.rotorTop = Array.prototype.slice.call(this.element.getElementsByClassName("rotor-top")); 151 this.rotorBottom = Array.prototype.slice.call(this.element.getElementsByClassName("rotor-bottom")); 152 153 this._tick(); 154 155 this._updateClockValues(true); 156 157 return this; 158 } 159 }, { 160 key: "_createRotorGroup", 161 value: function _createRotorGroup(rotors, rotorIndex) { 162 var rotorGroup = document.createElement("div"); 163 rotorGroup.className = "rotor-group"; 164 var dayRotorGroupHeading = document.createElement("div"); 165 dayRotorGroupHeading.className = "rotor-group-heading"; 166 dayRotorGroupHeading.setAttribute("data-before", this.opts.headings[rotorIndex]); 167 rotorGroup.appendChild(dayRotorGroupHeading); 168 appendChildren(rotorGroup, rotors); 169 return rotorGroup; 170 } 171 }, { 172 key: "_createRotor", 173 value: function _createRotor() { 174 var v = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; 175 var rotor = document.createElement("div"); 176 var rotorLeaf = document.createElement("div"); 177 var rotorLeafRear = document.createElement("figure"); 178 var rotorLeafFront = document.createElement("figure"); 179 var rotorTop = document.createElement("div"); 180 var rotorBottom = document.createElement("div"); 181 rotor.className = "rotor"; 182 rotorLeaf.className = "rotor-leaf"; 183 rotorLeafRear.className = "rotor-leaf-rear"; 184 rotorLeafFront.className = "rotor-leaf-front"; 185 rotorTop.className = "rotor-top"; 186 rotorBottom.className = "rotor-bottom"; 187 rotorLeafRear.textContent = v; 188 rotorTop.textContent = v; 189 rotorBottom.textContent = v; 190 appendChildren(rotor, [rotorLeaf, rotorTop, rotorBottom]); 191 appendChildren(rotorLeaf, [rotorLeafRear, rotorLeafFront]); 192 return rotor; 193 } 194 }, { 195 key: "_tick", 196 value: function _tick() { 197 this.now = this._getTime(); 198 var diff = this.epoch - this.now <= 0 ? 0 : this.epoch - this.now; 199 this.clockValues.d = Math.floor(diff / 86400); 200 diff -= this.clockValues.d * 86400; 201 this.clockValues.h = Math.floor(diff / 3600); 202 diff -= this.clockValues.h * 3600; 203 this.clockValues.m = Math.floor(diff / 60); 204 diff -= this.clockValues.m * 60; 205 this.clockValues.s = Math.floor(diff); 206 207 this._updateClockValues(); 208 209 this._hasCountdownEnded(); 210 } 211 }, { 212 key: "_updateClockValues", 213 value: function _updateClockValues() { 214 var _this = this; 215 216 var init = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false; 217 this.clockStrings.d = pad(this.clockValues.d, 2); 218 this.clockStrings.h = pad(this.clockValues.h, 2); 219 this.clockStrings.m = pad(this.clockValues.m, 2); 220 this.clockStrings.s = pad(this.clockValues.s, 2); 221 this.clockValuesAsString = (this.clockStrings.d + this.clockStrings.h + this.clockStrings.m + this.clockStrings.s).split(""); 222 this.rotorLeafFront.forEach(function (el, i) { 223 el.textContent = _this.prevClockValuesAsString[i]; 224 }); 225 this.rotorBottom.forEach(function (el, i) { 226 el.textContent = _this.prevClockValuesAsString[i]; 227 }); 228 229 function rotorTopFlip() { 230 var _this2 = this; 231 232 this.rotorTop.forEach(function (el, i) { 233 if (el.textContent != _this2.clockValuesAsString[i]) { 234 el.textContent = _this2.clockValuesAsString[i]; 235 } 236 }); 237 } 238 239 function rotorLeafRearFlip() { 240 var _this3 = this; 241 242 this.rotorLeafRear.forEach(function (el, i) { 243 if (el.textContent != _this3.clockValuesAsString[i]) { 244 el.textContent = _this3.clockValuesAsString[i]; 245 el.parentElement.classList.add("flipped"); 246 var flip = setInterval(function () { 247 el.parentElement.classList.remove("flipped"); 248 clearInterval(flip); 249 }.bind(_this3), 500); 250 } 251 }); 252 } 253 254 if (!init) { 255 setTimeout(rotorTopFlip.bind(this), 500); 256 setTimeout(rotorLeafRearFlip.bind(this), 500); 257 } else { 258 rotorTopFlip.call(this); 259 rotorLeafRearFlip.call(this); 260 } 261 262 this.prevClockValuesAsString = this.clockValuesAsString; 263 } 264 }]); 265 266 return FlipDown; 267}(); 268 269function pad(n, len) { 270 n = n.toString(); 271 return n.length < len ? pad("0" + n, len) : n; 272} 273 274function appendChildren(parent, children) { 275 children.forEach(function (el) { 276 parent.appendChild(el); 277 }); 278}
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.