PageSourceSearch

https://cancer.org.my/wp-content/themes/Total/assets/js/core/countUp-jquery.js?ver=4.6.1

js cancer.org.my collected 2026-10-02 10:26:28 UTC 8,117 bytes, 237 lines download raw bytes

vendor: 6,032 bytes, lines 1-161
1/*
2
3    countUp.js
4    by @inorganik
5    https://github.com/inorganik/CountUp.js
6
7*/
8
9// target = id of html element or var of previously selected html element where counting occurs
10// startVal = the value you want to begin at
11// endVal = the value you want to arrive at
12// decimals = number of decimal places, default 0
13// duration = duration of animation in seconds, default 2
14// options = optional object of options (see below)
15
16var CountUp = function(target, startVal, endVal, decimals, duration, options) {
17
18    // make sure requestAnimationFrame and cancelAnimationFrame are defined
19    // polyfill for browsers without native support
20    // by Opera engineer Erik Möller
21    var lastTime = 0;
22    var vendors = ['webkit', 'moz', 'ms', 'o'];
23    for(var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
24        window.requestAnimationFrame = window[vendors[x]+'RequestAnimationFrame'];
25        window.cancelAnimationFrame =
26          window[vendors[x]+'CancelAnimationFrame'] || window[vendors[x]+'CancelRequestAnimationFrame'];
27    }
28    if (!window.requestAnimationFrame) {
29        window.requestAnimationFrame = function(callback, element) {
30            var currTime = new Date().getTime();
31            var timeToCall = Math.max(0, 16 - (currTime - lastTime));
32            var id = window.setTimeout(function() { callback(currTime + timeToCall); },
33              timeToCall);
34            lastTime = currTime + timeToCall;
35            return id;
36        };
37    }
38    if (!window.cancelAnimationFrame) {
39        window.cancelAnimationFrame = function(id) {
40            clearTimeout(id);
41        };
42    }
43
44    var self = this;
45
46     // default options
47    self.options = {
48        useEasing : true, // toggle easing
49        useGrouping : true, // 1,000,000 vs 1000000
50        separator : ',', // character to use as a separator
51        decimal : '.', // character to use as a decimal
52        easingFn: null, // optional custom easing closure function, default is Robert Penner's easeOutExpo
53        formattingFn: null // optional custom formatting function, default is self.formatNumber below
54    };
55    // extend default options with passed options object
56    for (var key in options) {
57        if (options.hasOwnProperty(key)) {
58            self.options[key] = options[key];
59        }
60    }
61    if (self.options.separator === '') { self.options.useGrouping = false; }
62    if (!self.options.prefix) self.options.prefix = '';
63    if (!self.options.suffix) self.options.suffix = '';
64
65    self.d = (typeof target === 'string') ? document.getElementById(target) : target;
66    self.startVal = Number(startVal);
67    self.endVal = Number(endVal);
68    self.countDown = (self.startVal > self.endVal);
69    self.frameVal = self.startVal;
70    self.decimals = Math.max(0, decimals || 0);
71    self.dec = Math.pow(10, self.decimals);
72    self.duration = Number(duration) * 1000 || 2000;
73
74    self.formatNumber = function(nStr) {
75        nStr = nStr.toFixed(self.decimals);
76        nStr += '';
77        var x, x1, x2, rgx;
78        x = nStr.split('.');
79        x1 = x[0];
80        x2 = x.length > 1 ? self.options.decimal + x[1] : '';
81        rgx = /(\d+)(\d{3})/;
82        if (self.options.useGrouping) {
83            while (rgx.test(x1)) {
84                x1 = x1.replace(rgx, '$1' + self.options.separator + '$2');
85            }
86        }
87        return self.options.prefix + x1 + x2 + self.options.suffix;
88    };
89    // Robert Penner's easeOutExpo
90    self.easeOutExpo = function(t, b, c, d) {
91        return c * (-Math.pow(2, -10 * t / d) + 1) * 1024 / 1023 + b;
92    };
93
94    self.easingFn = self.options.easingFn ? self.options.easingFn : self.easeOutExpo;
95    self.formattingFn = self.options.formattingFn ? self.options.formattingFn : self.formatNumber;
96
97    self.version = function () { return '1.7.1'; };
98
99    // Print value to target
100    self.printValue = function(value) {
101        var result = self.formattingFn(value);
102
103        if (self.d.tagName === 'INPUT') {
104            this.d.value = result;
105        }
106        else if (self.d.tagName === 'text' || self.d.tagName === 'tspan') {
107            this.d.textContent = result;
108        }
109        else {
110            this.d.innerHTML = result;
111        }
112    };
113
114    self.count = function(timestamp) {
115
116        if (!self.startTime) { self.startTime = timestamp; }
117
118        self.timestamp = timestamp;
119        var progress = timestamp - self.startTime;
120        self.remaining = self.duration - progress;
121
122        // to ease or not to ease
123        if (self.options.useEasing) {
124            if (self.countDown) {
125                self.frameVal = self.startVal - self.easingFn(progress, 0, self.startVal - self.endVal, self.duration);
126            } else {
127                self.frameVal = self.easingFn(progress, self.startVal, self.endVal - self.startVal, self.duration);
128            }
129        } else {
130            if (self.countDown) {
131                self.frameVal = self.startVal - ((self.startVal - self.endVal) * (progress / self.duration));
132            } else {
133                self.frameVal = self.startVal + (self.endVal - self.startVal) * (progress / self.duration);
134            }
135        }
136
137        // don't go past endVal since progress can exceed duration in the last frame
138        if (self.countDown) {
139            self.frameVal = (self.frameVal < self.endVal) ? self.endVal : self.frameVal;
140        } else {
141            self.frameVal = (self.frameVal > self.endVal) ? self.endVal : self.frameVal;
142        }
143
144        // decimal
145        self.frameVal = Math.round(self.frameVal*self.dec)/self.dec;
146
147        // format and print value
148        self.printValue(self.frameVal);
149
150        // whether to continue
151        if (progress < self.duration) {
152            self.rAF = requestAnimationFrame(self.count);
153        } else {
154            if (self.callback) { self.callback(); }
155        }
156    };
157    // start your animation
158    self.start = function(callback) {
159        self.callback = callback;
160        self.rAF = requestAnimationFrame(self.count);
161        return false;
162    };
163    // toggles pause/resume animation
164    self.pauseResume = function() {
165        if (!self.paused) {
166            self.paused = true;
167            cancelAnimationFrame(self.rAF);
168        } else {
169            self.paused = false;
170            delete self.startTime;
171            self.duration = self.remaining;
172            self.startVal = self.frameVal;
173            requestAnimationFrame(self.count);
174        }
175    };
176    // reset to startVal so animation can be run again
177    self.reset = function() {
178        self.paused = false;
179        delete self.startTime;
180        self.startVal = startVal;
181        cancelAnimationFrame(self.rAF);
182        self.printValue(self.startVal);
183    };
184    // pass a new endVal and start animation
185    self.update = function (newEndVal) {
186        cancelAnimationFrame(self.rAF);
187        self.paused = false;
188        delete self.startTime;
189        self.startVal = self.frameVal;
190        self.endVal = Number(newEndVal);
191        self.countDown = (self.startVal > self.endVal);
192        self.rAF = requestAnimationFrame(self.count);
193    };
194
195    // format startVal on initialization
196    self.printValue(self.startVal);
197};
198
199(function($) {
200 
201    $.fn.countup = function(params) {
202 		// make sure dependency is present
203        if (typeof CountUp !== 'function') {
204        	console.error('countUp.js is a required dependency of countUp-jquery.js.');
205        	return;
206        }
207
208        var defaults = {
209        	startVal: 0,
210        	decimals: 0,
211        	duration: 2,
212        };
213
214        if (typeof params === 'number') {
215        	defaults.endVal = params;
216        }
217        else if (typeof params === 'object') {
218        	$.extend(defaults, params);
219        }
220        else {
221        	console.error('countUp-jquery requires its argument to be either an object or number');
222        	return;
223        } 
224
225        this.each(function(i, elem) {
226        	var countUp = new CountUp(elem, defaults.startVal, defaults.endVal, defaults.decimals, defaults.duration, defaults.options);
227
228        	countUp.start();
229        });
230
231
232
233        return this;
234 
235    };
236 
237}(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.