PageSourceSearch

https://emdep.vn/flipdown/flipdown.js

js emdep.vn collected 2026-10-02 03:02:30 UTC 9,671 bytes, 282 lines download raw bytes

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

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.