PageSourceSearch

https://www.pci-lab.fr/templates/rt_requiem/js/odometer.js

js pci-lab.fr collected 2026-10-02 09:57:40 UTC 20,445 bytes, 632 lines download raw bytes

vendor: 8,929 bytes, lines 1-281
1(function() {
2  var COUNT_FRAMERATE, COUNT_MS_PER_FRAME, DIGIT_FORMAT, DIGIT_HTML, DIGIT_SPEEDBOOST, DURATION, FORMAT_MARK_HTML, FORMAT_PARSER, FRAMERATE, FRAMES_PER_VALUE, MS_PER_FRAME, MutationObserver, Odometer, RIBBON_HTML, TRANSITION_END_EVENTS, TRANSITION_SUPPORT, VALUE_HTML, addClass, createFromHTML, fractionalPart, now, removeClass, requestAnimationFrame, round, transitionCheckStyles, trigger, truncate, wrapJQuery, _jQueryWrapped, _old, _ref, _ref1,
3    __slice = [].slice;
4
5  VALUE_HTML = '<span class="odometer-value"></span>';
6
7  RIBBON_HTML = '<span class="odometer-ribbon"><span class="odometer-ribbon-inner">' + VALUE_HTML + '</span></span>';
8
9  DIGIT_HTML = '<span class="odometer-digit"><span class="odometer-digit-spacer">8</span><span class="odometer-digit-inner">' + RIBBON_HTML + '</span></span>';
10
11  FORMAT_MARK_HTML = '<span class="odometer-formatting-mark"></span>';
12
13  DIGIT_FORMAT = '(,ddd).dd';
14
15  FORMAT_PARSER = /^\(?([^)]*)\)?(?:(.)(d+))?$/;
16
17  FRAMERATE = 30;
18
19  DURATION = 2000;
20
21  COUNT_FRAMERATE = 20;
22
23  FRAMES_PER_VALUE = 2;
24
25  DIGIT_SPEEDBOOST = .5;
26
27  MS_PER_FRAME = 1000 / FRAMERATE;
28
29  COUNT_MS_PER_FRAME = 1000 / COUNT_FRAMERATE;
30
31  TRANSITION_END_EVENTS = 'transitionend webkitTransitionEnd oTransitionEnd otransitionend MSTransitionEnd';
32
33  transitionCheckStyles = document.createElement('div').style;
34
35  TRANSITION_SUPPORT = (transitionCheckStyles.transition != null) || (transitionCheckStyles.webkitTransition != null) || (transitionCheckStyles.mozTransition != null) || (transitionCheckStyles.oTransition != null);
36
37  requestAnimationFrame = window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || window.msRequestAnimationFrame;
38
39  MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver;
40
41  createFromHTML = function(html) {
42    var el;
43    el = document.createElement('div');
44    el.innerHTML = html;
45    return el.children[0];
46  };
47
48  removeClass = function(el, name) {
49    return el.className = el.className.replace(new RegExp("(^| )" + (name.split(' ').join('|')) + "( |$)", 'gi'), ' ');
50  };
51
52  addClass = function(el, name) {
53    removeClass(el, name);
54    return el.className += " " + name;
55  };
56
57  trigger = function(el, name) {
58    var evt;
59    if (document.createEvent != null) {
60      evt = document.createEvent('HTMLEvents');
61      evt.initEvent(name, true, true);
62      return el.dispatchEvent(evt);
63    }
64  };
65
66  now = function() {
67    var _ref, _ref1;
68    return (_ref = (_ref1 = window.performance) != null ? typeof _ref1.now === "function" ? _ref1.now() : void 0 : void 0) != null ? _ref : +(new Date);
69  };
70
71  round = function(val, precision) {
72    if (precision == null) {
73      precision = 0;
74    }
75    if (!precision) {
76      return Math.round(val);
77    }
78    val *= Math.pow(10, precision);
79    val += 0.5;
80    val = Math.floor(val);
81    return val /= Math.pow(10, precision);
82  };
83
84  truncate = function(val) {
85    if (val < 0) {
86      return Math.ceil(val);
87    } else {
88      return Math.floor(val);
89    }
90  };
91
92  fractionalPart = function(val) {
93    return val - round(val);
94  };
95
96  _jQueryWrapped = false;
97
98  (wrapJQuery = function() {
99    var property, _i, _len, _ref, _results;
100    if (_jQueryWrapped) {
101      return;
102    }
103    if (window.jQuery != null) {
104      _jQueryWrapped = true;
105      _ref = ['html', 'text'];
106      _results = [];
107      for (_i = 0, _len = _ref.length; _i < _len; _i++) {
108        property = _ref[_i];
109        _results.push((function(property) {
110          var old;
111          old = window.jQuery.fn[property];
112          return window.jQuery.fn[property] = function(val) {
113            var _ref1;
114            if ((val == null) || (((_ref1 = this[0]) != null ? _ref1.odometer : void 0) == null)) {
115              return old.apply(this, arguments);
116            }
117            return this[0].odometer.update(val);
118          };
119        })(property));
120      }
121      return _results;
122    }
123  })();
124
125  setTimeout(wrapJQuery, 0);
126
127  Odometer = (function() {
128    function Odometer(options) {
129      var e, k, property, v, _base, _i, _len, _ref, _ref1, _ref2,
130        _this = this;
131      this.options = options;
132      this.el = this.options.el;
133      if (this.el.odometer != null) {
134        return this.el.odometer;
135      }
136      this.el.odometer = this;
137      _ref = Odometer.options;
138      for (k in _ref) {
139        v = _ref[k];
140        if (this.options[k] == null) {
141          this.options[k] = v;
142        }
143      }
144      if ((_base = this.options).duration == null) {
145        _base.duration = DURATION;
146      }
147      this.MAX_VALUES = ((this.options.duration / MS_PER_FRAME) / FRAMES_PER_VALUE) | 0;
148      this.resetFormat();
149      this.value = this.cleanValue((_ref1 = this.options.value) != null ? _ref1 : '');
150      this.renderInside();
151      this.render();
152      try {
153        _ref2 = ['innerHTML', 'innerText', 'textContent'];
154        for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
155          property = _ref2[_i];
156          if (this.el[property] != null) {
157            (function(property) {
158              return Object.defineProperty(_this.el, property, {
159                get: function() {
160                  var _ref3;
161                  if (property === 'innerHTML') {
162                    return _this.inside.outerHTML;
163                  } else {
164                    return (_ref3 = _this.inside.innerText) != null ? _ref3 : _this.inside.textContent;
165                  }
166                },
167                set: function(val) {
168                  return _this.update(val);
169                }
170              });
171            })(property);
172          }
173        }
174      } catch (_error) {
175        e = _error;
176        this.watchForMutations();
177      }
178      this;
179    }
180
181    Odometer.prototype.renderInside = function() {
182      this.inside = document.createElement('div');
183      this.inside.className = 'odometer-inside';
184      this.el.innerHTML = '';
185      return this.el.appendChild(this.inside);
186    };
187
188    Odometer.prototype.watchForMutations = function() {
189      var e,
190        _this = this;
191      if (MutationObserver == null) {
192        return;
193      }
194      try {
195        if (this.observer == null) {
196          this.observer = new MutationObserver(function(mutations) {
197            var newVal;
198            newVal = _this.el.innerText;
199            _this.renderInside();
200            _this.render(_this.value);
201            return _this.update(newVal);
202          });
203        }
204        this.watchMutations = true;
205        return this.startWatchingMutations();
206      } catch (_error) {
207        e = _error;
208      }
209    };
210
211    Odometer.prototype.startWatchingMutations = function() {
212      if (this.watchMutations) {
213        return this.observer.observe(this.el, {
214          childList: true
215        });
216      }
217    };
218
219    Odometer.prototype.stopWatchingMutations = function() {
220      var _ref;
221      return (_ref = this.observer) != null ? _ref.disconnect() : void 0;
222    };
223
224    Odometer.prototype.cleanValue = function(val) {
225      var _ref;
226      if (typeof val === 'string') {
227        val = val.replace((_ref = this.format.radix) != null ? _ref : '.', '<radix>');
228        val = val.replace(/[.,]/g, '');
229        val = val.replace('<radix>', '.');
230        val = parseFloat(val, 10) || 0;
231      }
232      return round(val, this.format.precision);
233    };
234
235    Odometer.prototype.bindTransitionEnd = function() {
236      var event, renderEnqueued, _i, _len, _ref, _results,
237        _this = this;
238      if (this.transitionEndBound) {
239        return;
240      }
241      this.transitionEndBound = true;
242      renderEnqueued = false;
243      _ref = TRANSITION_END_EVENTS.split(' ');
244      _results = [];
245      for (_i = 0, _len = _ref.length; _i < _len; _i++) {
246        event = _ref[_i];
247        _results.push(this.el.addEventListener(event, function() {
248          if (renderEnqueued) {
249            return true;
250          }
251          renderEnqueued = true;
252          setTimeout(function() {
253            _this.render();
254            renderEnqueued = false;
255            return trigger(_this.el, 'odometerdone');
256          }, 0);
257          return true;
258        }, false));
259      }
260      return _results;
261    };
262
263    Odometer.prototype.resetFormat = function() {
264      var format, fractional, parsed, precision, radix, repeating, _ref, _ref1;
265      format = (_ref = this.options.format) != null ? _ref : DIGIT_FORMAT;
266      format || (format = 'd');
267      parsed = FORMAT_PARSER.exec(format);
268      if (!parsed) {
269        throw new Error("Odometer: Unparsable digit format");
270      }
271      _ref1 = parsed.slice(1, 4), repeating = _ref1[0], radix = _ref1[1], fractional = _ref1[2];
272      precision = (fractional != null ? fractional.length : void 0) || 0;
273      return this.format = {
274        repeating: repeating,
275        radix: radix,
276        precision: precision
277      };
278    };
279
280    Odometer.prototype.render = function(value) {
281      var classes, cls, 
vendor: 11,516 bytes, lines 281-632
281digit, match, newClasses, theme, wholePart, _i, _j, _len, _len1, _ref;
282      if (value == null) {
283        value = this.value;
284      }
285      this.stopWatchingMutations();
286      this.resetFormat();
287      this.inside.innerHTML = '';
288      theme = this.options.theme;
289      classes = this.el.className.split(' ');
290      newClasses = [];
291      for (_i = 0, _len = classes.length; _i < _len; _i++) {
292        cls = classes[_i];
293        if (!cls.length) {
294          continue;
295        }
296        if (match = /^odometer-theme-(.+)$/.exec(cls)) {
297          theme = match[1];
298          continue;
299        }
300        if (/^odometer(-|$)/.test(cls)) {
301          continue;
302        }
303        newClasses.push(cls);
304      }
305      newClasses.push('odometer');
306      if (!TRANSITION_SUPPORT) {
307        newClasses.push('odometer-no-transitions');
308      }
309      if (theme) {
310        newClasses.push("odometer-theme-" + theme);
311      } else {
312        newClasses.push("odometer-auto-theme");
313      }
314      this.el.className = newClasses.join(' ');
315      this.ribbons = {};
316      this.digits = [];
317      wholePart = !this.format.precision || !fractionalPart(value) || false;
318      _ref = value.toString().split('').reverse();
319      for (_j = 0, _len1 = _ref.length; _j < _len1; _j++) {
320        digit = _ref[_j];
321        if (digit === '.') {
322          wholePart = true;
323        }
324        this.addDigit(digit, wholePart);
325      }
326      return this.startWatchingMutations();
327    };
328
329    Odometer.prototype.update = function(newValue) {
330      var diff,
331        _this = this;
332      newValue = this.cleanValue(newValue);
333      if (!(diff = newValue - this.value)) {
334        return;
335      }
336      removeClass(this.el, 'odometer-animating-up odometer-animating-down odometer-animating');
337      if (diff > 0) {
338        addClass(this.el, 'odometer-animating-up');
339      } else {
340        addClass(this.el, 'odometer-animating-down');
341      }
342      this.stopWatchingMutations();
343      this.animate(newValue);
344      this.startWatchingMutations();
345      setTimeout(function() {
346        _this.el.offsetHeight;
347        return addClass(_this.el, 'odometer-animating');
348      }, 0);
349      return this.value = newValue;
350    };
351
352    Odometer.prototype.renderDigit = function() {
353      return createFromHTML(DIGIT_HTML);
354    };
355
356    Odometer.prototype.insertDigit = function(digit, before) {
357      if (before != null) {
358        return this.inside.insertBefore(digit, before);
359      } else if (!this.inside.children.length) {
360        return this.inside.appendChild(digit);
361      } else {
362        return this.inside.insertBefore(digit, this.inside.children[0]);
363      }
364    };
365
366    Odometer.prototype.addSpacer = function(chr, before, extraClasses) {
367      var spacer;
368      spacer = createFromHTML(FORMAT_MARK_HTML);
369      spacer.innerHTML = chr;
370      if (extraClasses) {
371        addClass(spacer, extraClasses);
372      }
373      return this.insertDigit(spacer, before);
374    };
375
376    Odometer.prototype.addDigit = function(value, repeating) {
377      var chr, digit, resetted, _ref;
378      if (repeating == null) {
379        repeating = true;
380      }
381      if (value === '-') {
382        return this.addSpacer(value, null, 'odometer-negation-mark');
383      }
384      if (value === '.') {
385        return this.addSpacer((_ref = this.format.radix) != null ? _ref : '.', null, 'odometer-radix-mark');
386      }
387      if (repeating) {
388        resetted = false;
389        while (true) {
390          if (!this.format.repeating.length) {
391            if (resetted) {
392              throw new Error("Bad odometer format without digits");
393            }
394            this.resetFormat();
395            resetted = true;
396          }
397          chr = this.format.repeating[this.format.repeating.length - 1];
398          this.format.repeating = this.format.repeating.substring(0, this.format.repeating.length - 1);
399          if (chr === 'd') {
400            break;
401          }
402          this.addSpacer(chr);
403        }
404      }
405      digit = this.renderDigit();
406      digit.querySelector('.odometer-value').innerHTML = value;
407      this.digits.push(digit);
408      return this.insertDigit(digit);
409    };
410
411    Odometer.prototype.animate = function(newValue) {
412      if (!TRANSITION_SUPPORT || this.options.animation === 'count') {
413        return this.animateCount(newValue);
414      } else {
415        return this.animateSlide(newValue);
416      }
417    };
418
419    Odometer.prototype.animateCount = function(newValue) {
420      var cur, diff, last, start, tick,
421        _this = this;
422      if (!(diff = +newValue - this.value)) {
423        return;
424      }
425      start = last = now();
426      cur = this.value;
427      return (tick = function() {
428        var delta, dist, fraction;
429        if ((now() - start) > _this.options.duration) {
430          _this.value = newValue;
431          _this.render();
432          trigger(_this.el, 'odometerdone');
433          return;
434        }
435        delta = now() - last;
436        if (delta > COUNT_MS_PER_FRAME) {
437          last = now();
438          fraction = delta / _this.options.duration;
439          dist = diff * fraction;
440          cur += dist;
441          _this.render(Math.round(cur));
442        }
443        if (requestAnimationFrame != null) {
444          return requestAnimationFrame(tick);
445        } else {
446          return setTimeout(tick, COUNT_MS_PER_FRAME);
447        }
448      })();
449    };
450
451    Odometer.prototype.getDigitCount = function() {
452      var i, max, value, values, _i, _len;
453      values = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
454      for (i = _i = 0, _len = values.length; _i < _len; i = ++_i) {
455        value = values[i];
456        values[i] = Math.abs(value);
457      }
458      max = Math.max.apply(Math, values);
459      return Math.ceil(Math.log(max + 1) / Math.log(10));
460    };
461
462    Odometer.prototype.getFractionalDigitCount = function() {
463      var i, parser, parts, value, values, _i, _len;
464      values = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
465      parser = /^\-?\d*\.(\d*?)0*$/;
466      for (i = _i = 0, _len = values.length; _i < _len; i = ++_i) {
467        value = values[i];
468        values[i] = value.toString();
469        parts = parser.exec(values[i]);
470        if (parts == null) {
471          values[i] = 0;
472        } else {
473          values[i] = parts[1].length;
474        }
475      }
476      return Math.max.apply(Math, values);
477    };
478
479    Odometer.prototype.resetDigits = function() {
480      this.digits = [];
481      this.ribbons = [];
482      this.inside.innerHTML = '';
483      return this.resetFormat();
484    };
485
486    Odometer.prototype.animateSlide = function(newValue) {
487      var boosted, cur, diff, digitCount, digits, dist, end, fractionalCount, frame, frames, i, incr, j, mark, numEl, oldValue, start, _base, _i, _j, _k, _l, _len, _len1, _len2, _m, _ref, _results;
488      oldValue = this.value;
489      fractionalCount = this.getFractionalDigitCount(oldValue, newValue);
490      if (fractionalCount) {
491        newValue = newValue * Math.pow(10, fractionalCount);
492        oldValue = oldValue * Math.pow(10, fractionalCount);
493      }
494      if (!(diff = newValue - oldValue)) {
495        return;
496      }
497      this.bindTransitionEnd();
498      digitCount = this.getDigitCount(oldValue, newValue);
499      digits = [];
500      boosted = 0;
501      for (i = _i = 0; 0 <= digitCount ? _i < digitCount : _i > digitCount; i = 0 <= digitCount ? ++_i : --_i) {
502        start = truncate(oldValue / Math.pow(10, digitCount - i - 1));
503        end = truncate(newValue / Math.pow(10, digitCount - i - 1));
504        dist = end - start;
505        if (Math.abs(dist) > this.MAX_VALUES) {
506          frames = [];
507          incr = dist / (this.MAX_VALUES + this.MAX_VALUES * boosted * DIGIT_SPEEDBOOST);
508          cur = start;
509          while ((dist > 0 && cur < end) || (dist < 0 && cur > end)) {
510            frames.push(Math.round(cur));
511            cur += incr;
512          }
513          if (frames[frames.length - 1] !== end) {
514            frames.push(end);
515          }
516          boosted++;
517        } else {
518          frames = (function() {
519            _results = [];
520            for (var _j = start; start <= end ? _j <= end : _j >= end; start <= end ? _j++ : _j--){ _results.push(_j); }
521            return _results;
522          }).apply(this);
523        }
524        for (i = _k = 0, _len = frames.length; _k < _len; i = ++_k) {
525          frame = frames[i];
526          frames[i] = Math.abs(frame % 10);
527        }
528        digits.push(frames);
529      }
530      this.resetDigits();
531      _ref = digits.reverse();
532      for (i = _l = 0, _len1 = _ref.length; _l < _len1; i = ++_l) {
533        frames = _ref[i];
534        if (!this.digits[i]) {
535          this.addDigit(' ', i >= fractionalCount);
536        }
537        if ((_base = this.ribbons)[i] == null) {
538          _base[i] = this.digits[i].querySelector('.odometer-ribbon-inner');
539        }
540        this.ribbons[i].innerHTML = '';
541        if (diff < 0) {
542          frames = frames.reverse();
543        }
544        for (j = _m = 0, _len2 = frames.length; _m < _len2; j = ++_m) {
545          frame = frames[j];
546          numEl = document.createElement('div');
547          numEl.className = 'odometer-value';
548          numEl.innerHTML = frame;
549          this.ribbons[i].appendChild(numEl);
550          if (j === frames.length - 1) {
551            addClass(numEl, 'odometer-last-value');
552          }
553          if (j === 0) {
554            addClass(numEl, 'odometer-first-value');
555          }
556        }
557      }
558      if (start < 0) {
559        this.addDigit('-');
560      }
561      mark = this.inside.querySelector('.odometer-radix-mark');
562      if (mark != null) {
563        mark.parent.removeChild(mark);
564      }
565      if (fractionalCount) {
566        return this.addSpacer(this.format.radix, this.digits[fractionalCount - 1], 'odometer-radix-mark');
567      }
568    };
569
570    return Odometer;
571
572  })();
573
574  Odometer.options = (_ref = window.odometerOptions) != null ? _ref : {};
575
576  setTimeout(function() {
577    var k, v, _base, _ref1, _results;
578    if (window.odometerOptions) {
579      _ref1 = window.odometerOptions;
580      _results = [];
581      for (k in _ref1) {
582        v = _ref1[k];
583        _results.push((_base = Odometer.options)[k] != null ? (_base = Odometer.options)[k] : _base[k] = v);
584      }
585      return _results;
586    }
587  }, 0);
588
589  Odometer.init = function() {
590    var el, elements, _i, _len, _ref1, _results;
591    if (document.querySelectorAll == null) {
592      return;
593    }
594    elements = document.querySelectorAll(Odometer.options.selector || '.odometer');
595    _results = [];
596    for (_i = 0, _len = elements.length; _i < _len; _i++) {
597      el = elements[_i];
598      _results.push(el.odometer = new Odometer({
599        el: el,
600        value: (_ref1 = el.innerText) != null ? _ref1 : el.textContent
601      }));
602    }
603    return _results;
604  };
605
606  if ((((_ref1 = document.documentElement) != null ? _ref1.doScroll : void 0) != null) && (document.createEventObject != null)) {
607    _old = document.onreadystatechange;
608    document.onreadystatechange = function() {
609      if (document.readyState === 'complete' && Odometer.options.auto !== false) {
610        Odometer.init();
611      }
612      return _old != null ? _old.apply(this, arguments) : void 0;
613    };
614  } else {
615    document.addEventListener('DOMContentLoaded', function() {
616      if (Odometer.options.auto !== false) {
617        return Odometer.init();
618      }
619    }, false);
620  }
621
622  if (typeof define === 'function' && define.amd) {
623    define(['jquery'], function() {
624      return Odometer;
625    });
626  } else if (typeof exports === !'undefined') {
627    module.exports = Odometer;
628  } else {
629    window.Odometer = Odometer;
630  }
631
632}).call(this);

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.