PageSourceSearch

https://azon.com/wp-content/themes/beadvices/inc/assets/js/jquery.countTo.js?ver=201481786

js azon.com collected 2026-10-03 22:11:53 UTC 3,798 bytes, 131 lines download raw bytes

vendor: 3,798 bytes, lines 1-131
1(function (factory) {
2"use strict"; // Start of use strict
3    if (typeof define === 'function' && define.amd) {
4        // AMD
5        define(['jquery'], factory);
6    } else if (typeof exports === 'object') {
7        // CommonJS
8        factory(require('jquery'));
9    } else {
10        // Browser globals
11        factory(jQuery);
12    }
13}(function ($) {
14  var CountTo = function (element, options) {
15    this.$element = $(element);
16    this.options  = $.extend({}, CountTo.DEFAULTS, this.dataOptions(), options);
17    this.init();
18  };
19
20  CountTo.DEFAULTS = {
21    from: 0,               // the number the element should start at
22    to: 0,                 // the number the element should end at
23    speed: 1000,           // how long it should take to count between the target numbers
24    refreshInterval: 100,  // how often the element should be updated
25    decimals: 0,           // the number of decimal places to show
26    formatter: formatter,  // handler for formatting the value before rendering
27    onUpdate: null,        // callback method for every time the element is updated
28    onComplete: null       // callback method for when the element finishes updating
29  };
30
31  CountTo.prototype.init = function () {
32    this.value     = this.options.from;
33    this.loops     = Math.ceil(this.options.speed / this.options.refreshInterval);
34    this.loopCount = 0;
35    this.increment = (this.options.to - this.options.from) / this.loops;
36  };
37
38  CountTo.prototype.dataOptions = function () {
39    var options = {
40      from:            this.$element.data('from'),
41      to:              this.$element.data('to'),
42      speed:           this.$element.data('speed'),
43      refreshInterval: this.$element.data('refresh-interval'),
44      decimals:        this.$element.data('decimals')
45    };
46
47    var keys = Object.keys(options);
48
49    for (var i in keys) {
50      var key = keys[i];
51
52      if (typeof(options[key]) === 'undefined') {
53        delete options[key];
54      }
55    }
56
57    return options;
58  };
59
60  CountTo.prototype.update = function () {
61    this.value += this.increment;
62    this.loopCount++;
63
64    this.render();
65
66    if (typeof(this.options.onUpdate) == 'function') {
67      this.options.onUpdate.call(this.$element, this.value);
68    }
69
70    if (this.loopCount >= this.loops) {
71      clearInterval(this.interval);
72      this.value = this.options.to;
73
74      if (typeof(this.options.onComplete) == 'function') {
75        this.options.onComplete.call(this.$element, this.value);
76      }
77    }
78  };
79
80  CountTo.prototype.render = function () {
81    var formattedValue = this.options.formatter.call(this.$element, this.value, this.options);
82    this.$element.text(formattedValue);
83  };
84
85  CountTo.prototype.restart = function () {
86    this.stop();
87    this.init();
88    this.start();
89  };
90
91  CountTo.prototype.start = function () {
92    this.stop();
93    this.render();
94    this.interval = setInterval(this.update.bind(this), this.options.refreshInterval);
95  };
96
97  CountTo.prototype.stop = function () {
98    if (this.interval) {
99      clearInterval(this.interval);
100    }
101  };
102
103  CountTo.prototype.toggle = function () {
104    if (this.interval) {
105      this.stop();
106    } else {
107      this.start();
108    }
109  };
110
111  function formatter(value, options) {
112    return value.toFixed(options.decimals);
113  }
114
115  $.fn.countTo = function (option) {
116    return this.each(function () {
117      var $this   = $(this);
118      var data    = $this.data('countTo');
119      var init    = !data || typeof(option) === 'object';
120      var options = typeof(option) === 'object' ? option : {};
121      var method  = typeof(option) === 'string' ? option : 'start';
122
123      if (init) {
124        if (data) data.stop();
125        $this.data('countTo', data = new CountTo(this, options));
126      }
127
128      data[method].call(data);
129    });
130  };
131}));

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.