PageSourceSearch

https://scoea.org/templates/scoea/js/jquery.incremental-counter.js

js scoea.org collected 2026-10-02 20:04:38 UTC 3,379 bytes, 101 lines download raw bytes

1/*
2 Plugin Name: jQuery plugin incremental counter
3 Plugin URI: https://github.com/MikhaelGerbet/jquery-incremental-counter
4 Description: jQuery plugin incremental counter is a simple counter animated
5 Author: GERBET Mikhael
6 Author URI: https://github.com/MikhaelGerbet
7 License: MIT
8 */
9
10(function($){
11    $.fn.incrementalCounter = function(options){
12        //default options
13        var defauts = {
14                "digits": 4
15            },
16            pad = function(n, width, z) {
17                z = z || '0';
18                n = n + '';
19                return n.length >= width ? n : new Array(width - n.length + 1).join(z) + n;
20            },
21            start = function(element){
22
23                var current_value = parseInt($(element).data('current_value')),
24                    end_value = parseInt($(element).data('end_value')),
25                    current_speed = 20;
26
27                if(end_value === 0) {
28                    return false;
29                }
30
31
32                if (end_value - current_value < 5){
33                    current_speed = 200;
34                    current_value += 1;
35                } else if(end_value - current_value < 15){
36                    current_speed = 50;
37                    current_value += 1
38                } else if(end_value - current_value < 50){
39                    current_speed = 25;
40                    current_value += 3
41                } else{
42                    current_speed = 25;
43                    current_value += parseInt((end_value - current_value)/24)
44                }
45
46                $(element).data({
47                    current_value:current_value
48                });
49
50                if(current_speed){
51                    setTimeout(function(){
52                        display($(element),current_value);
53                    },current_speed);
54                }else{
55                    display($(element),current_value);
56                }
57            },
58            display = function(element,value){
59                var padedNumber = pad(value, element.data('digits')),
60                    exp = padedNumber.split(""),
61                    end_value = $(element).data('end_value'),
62                    nums = $(element).find('.num');
63                $(exp).each(function(i,e){
64                    $(nums[i]).text(exp[i]);
65                });
66
67                if(end_value != value){
68                    start(element);
69                }
70            },
71            //merge options
72            options = $.extend(defauts, options);
73
74        this.each(function(index, element){
75
76            var default_digits = options.digits ,
77                digits =  element.getAttribute('data-digits') ?  element.getAttribute('data-digits') : default_digits ,
78                end_value = parseInt( element.getAttribute('data-value'));
79
80            digits = digits === 'auto' || digits < String(end_value).length ? String(end_value).length : digits;
81
82            //get value
83            $(element).data({
84                current_value : 0,
85                end_value : end_value,
86                digits : digits,
87                current_speed : 0
88            });
89
90            //add number container
91			
92            for(var i=0 ; i < digits ; i++){
93                $(element).append('<div class="num">0</div>');
94            }
95			
96            start($(element));
97
98        });
99        return this;
100    };
101})(jQuery);

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.