countup.js
Advanced tools
Comparing version 1.9.1 to 1.9.2
@@ -18,3 +18,3 @@ /* | ||
var self = this; | ||
self.version = function () { return '1.9.1'; }; | ||
self.version = function () { return '1.9.2'; }; | ||
@@ -43,3 +43,9 @@ // default options | ||
if (self.options.separator === '') self.options.useGrouping = false; | ||
if (self.options.separator === '') { | ||
self.options.useGrouping = false; | ||
} | ||
else { | ||
// ensure the separator is a string (formatNumber assumes this) | ||
self.options.separator = '' + self.options.separator; | ||
} | ||
@@ -53,4 +59,3 @@ // make sure requestAnimationFrame and cancelAnimationFrame are defined | ||
window.requestAnimationFrame = window[vendors[x]+'RequestAnimationFrame']; | ||
window.cancelAnimationFrame = | ||
window[vendors[x]+'CancelAnimationFrame'] || window[vendors[x]+'CancelRequestAnimationFrame']; | ||
window.cancelAnimationFrame = window[vendors[x]+'CancelAnimationFrame'] || window[vendors[x]+'CancelRequestAnimationFrame']; | ||
} | ||
@@ -61,4 +66,3 @@ if (!window.requestAnimationFrame) { | ||
var timeToCall = Math.max(0, 16 - (currTime - lastTime)); | ||
var id = window.setTimeout(function() { callback(currTime + timeToCall); }, | ||
timeToCall); | ||
var id = window.setTimeout(function() { callback(currTime + timeToCall); }, timeToCall); | ||
lastTime = currTime + timeToCall; | ||
@@ -77,11 +81,15 @@ return id; | ||
num += ''; | ||
var x, x1, x2, rgx; | ||
var x, x1, x2, x3, i, l; | ||
x = num.split('.'); | ||
x1 = x[0]; | ||
x2 = x.length > 1 ? self.options.decimal + x[1] : ''; | ||
rgx = /(\d+)(\d{3})/; | ||
if (self.options.useGrouping) { | ||
while (rgx.test(x1)) { | ||
x1 = x1.replace(rgx, '$1' + self.options.separator + '$2'); | ||
x3 = ''; | ||
for (i = 0, l = x1.length; i < l; ++i) { | ||
if (i !== 0 && ((i % 3) === 0)) { | ||
x3 = self.options.separator + x3; | ||
} | ||
x3 = x1[l - i - 1] + x3; | ||
} | ||
x1 = x3; | ||
} | ||
@@ -91,7 +99,7 @@ // optional numeral substitution | ||
x1 = x1.replace(/[0-9]/g, function(w) { | ||
return self.options.numerals[+w]; | ||
}) | ||
return self.options.numerals[+w]; | ||
}) | ||
x2 = x2.replace(/[0-9]/g, function(w) { | ||
return self.options.numerals[+w]; | ||
}) | ||
return self.options.numerals[+w]; | ||
}) | ||
} | ||
@@ -98,0 +106,0 @@ return self.options.prefix + x1 + x2 + self.options.suffix; |
@@ -29,3 +29,3 @@ | ||
var self = this; | ||
self.version = function () { return '1.9.1'; }; | ||
self.version = function () { return '1.9.2'; }; | ||
@@ -54,3 +54,9 @@ // default options | ||
if (self.options.separator === '') self.options.useGrouping = false; | ||
if (self.options.separator === '') { | ||
self.options.useGrouping = false; | ||
} | ||
else { | ||
// ensure the separator is a string (formatNumber assumes this) | ||
self.options.separator = '' + self.options.separator; | ||
} | ||
@@ -64,4 +70,3 @@ // make sure requestAnimationFrame and cancelAnimationFrame are defined | ||
window.requestAnimationFrame = window[vendors[x]+'RequestAnimationFrame']; | ||
window.cancelAnimationFrame = | ||
window[vendors[x]+'CancelAnimationFrame'] || window[vendors[x]+'CancelRequestAnimationFrame']; | ||
window.cancelAnimationFrame = window[vendors[x]+'CancelAnimationFrame'] || window[vendors[x]+'CancelRequestAnimationFrame']; | ||
} | ||
@@ -72,4 +77,3 @@ if (!window.requestAnimationFrame) { | ||
var timeToCall = Math.max(0, 16 - (currTime - lastTime)); | ||
var id = window.setTimeout(function() { callback(currTime + timeToCall); }, | ||
timeToCall); | ||
var id = window.setTimeout(function() { callback(currTime + timeToCall); }, timeToCall); | ||
lastTime = currTime + timeToCall; | ||
@@ -88,11 +92,15 @@ return id; | ||
num += ''; | ||
var x, x1, x2, rgx; | ||
var x, x1, x2, x3, i, l; | ||
x = num.split('.'); | ||
x1 = x[0]; | ||
x2 = x.length > 1 ? self.options.decimal + x[1] : ''; | ||
rgx = /(\d+)(\d{3})/; | ||
if (self.options.useGrouping) { | ||
while (rgx.test(x1)) { | ||
x1 = x1.replace(rgx, '$1' + self.options.separator + '$2'); | ||
x3 = ''; | ||
for (i = 0, l = x1.length; i < l; ++i) { | ||
if (i !== 0 && ((i % 3) === 0)) { | ||
x3 = self.options.separator + x3; | ||
} | ||
x3 = x1[l - i - 1] + x3; | ||
} | ||
x1 = x3; | ||
} | ||
@@ -102,7 +110,7 @@ // optional numeral substitution | ||
x1 = x1.replace(/[0-9]/g, function(w) { | ||
return self.options.numerals[+w]; | ||
}) | ||
return self.options.numerals[+w]; | ||
}) | ||
x2 = x2.replace(/[0-9]/g, function(w) { | ||
return self.options.numerals[+w]; | ||
}) | ||
return self.options.numerals[+w]; | ||
}) | ||
} | ||
@@ -109,0 +117,0 @@ return self.options.prefix + x1 + x2 + self.options.suffix; |
@@ -1,1 +0,1 @@ | ||
!function(a,e){"function"==typeof define&&define.amd?define(e):"object"==typeof exports?module.exports=e(require,exports,module):a.CountUp=e()}(this,function(a,e,n){var t=function(a,e,n,t,i,r){function o(a){a=a.toFixed(s.decimals),a+="";var e,n,t,i;if(e=a.split("."),n=e[0],t=e.length>1?s.options.decimal+e[1]:"",i=/(\d+)(\d{3})/,s.options.useGrouping)for(;i.test(n);)n=n.replace(i,"$1"+s.options.separator+"$2");return s.options.numerals.length&&(n=n.replace(/[0-9]/g,function(a){return s.options.numerals[+a]}),t=t.replace(/[0-9]/g,function(a){return s.options.numerals[+a]})),s.options.prefix+n+t+s.options.suffix}function u(a,e,n,t){return n*(-Math.pow(2,-10*a/t)+1)*1024/1023+e}function l(a){return"number"==typeof a&&!isNaN(a)}var s=this;if(s.version=function(){return"1.9.1"},s.options={useEasing:!0,useGrouping:!0,separator:",",decimal:".",easingFn:u,formattingFn:o,prefix:"",suffix:"",numerals:[]},r&&"object"==typeof r)for(var m in s.options)r.hasOwnProperty(m)&&null!==r[m]&&(s.options[m]=r[m]);""===s.options.separator&&(s.options.useGrouping=!1);for(var d=0,c=["webkit","moz","ms","o"],f=0;f<c.length&&!window.requestAnimationFrame;++f)window.requestAnimationFrame=window[c[f]+"RequestAnimationFrame"],window.cancelAnimationFrame=window[c[f]+"CancelAnimationFrame"]||window[c[f]+"CancelRequestAnimationFrame"];window.requestAnimationFrame||(window.requestAnimationFrame=function(a,e){var n=(new Date).getTime(),t=Math.max(0,16-(n-d)),i=window.setTimeout(function(){a(n+t)},t);return d=n+t,i}),window.cancelAnimationFrame||(window.cancelAnimationFrame=function(a){clearTimeout(a)}),s.initialize=function(){return!!s.initialized||(s.error="",s.d="string"==typeof a?document.getElementById(a):a,s.d?(s.startVal=Number(e),s.endVal=Number(n),l(s.startVal)&&l(s.endVal)?(s.decimals=Math.max(0,t||0),s.dec=Math.pow(10,s.decimals),s.duration=1e3*Number(i)||2e3,s.countDown=s.startVal>s.endVal,s.frameVal=s.startVal,s.initialized=!0,!0):(s.error="[CountUp] startVal ("+e+") or endVal ("+n+") is not a number",!1)):(s.error="[CountUp] target is null or undefined",!1))},s.printValue=function(a){var e=s.options.formattingFn(a);"INPUT"===s.d.tagName?this.d.value=e:"text"===s.d.tagName||"tspan"===s.d.tagName?this.d.textContent=e:this.d.innerHTML=e},s.count=function(a){s.startTime||(s.startTime=a),s.timestamp=a;var e=a-s.startTime;s.remaining=s.duration-e,s.options.useEasing?s.countDown?s.frameVal=s.startVal-s.options.easingFn(e,0,s.startVal-s.endVal,s.duration):s.frameVal=s.options.easingFn(e,s.startVal,s.endVal-s.startVal,s.duration):s.countDown?s.frameVal=s.startVal-(s.startVal-s.endVal)*(e/s.duration):s.frameVal=s.startVal+(s.endVal-s.startVal)*(e/s.duration),s.countDown?s.frameVal=s.frameVal<s.endVal?s.endVal:s.frameVal:s.frameVal=s.frameVal>s.endVal?s.endVal:s.frameVal,s.frameVal=Math.round(s.frameVal*s.dec)/s.dec,s.printValue(s.frameVal),e<s.duration?s.rAF=requestAnimationFrame(s.count):s.callback&&s.callback()},s.start=function(a){s.initialize()&&(s.callback=a,s.rAF=requestAnimationFrame(s.count))},s.pauseResume=function(){s.paused?(s.paused=!1,delete s.startTime,s.duration=s.remaining,s.startVal=s.frameVal,requestAnimationFrame(s.count)):(s.paused=!0,cancelAnimationFrame(s.rAF))},s.reset=function(){s.paused=!1,delete s.startTime,s.initialized=!1,s.initialize()&&(cancelAnimationFrame(s.rAF),s.printValue(s.startVal))},s.update=function(a){if(s.initialize()){if(a=Number(a),!l(a))return void(s.error="[CountUp] update() - new endVal is not a number: "+a);s.error="",a!==s.frameVal&&(cancelAnimationFrame(s.rAF),s.paused=!1,delete s.startTime,s.startVal=s.frameVal,s.endVal=a,s.countDown=s.startVal>s.endVal,s.rAF=requestAnimationFrame(s.count))}},s.initialize()&&s.printValue(s.startVal)};return t}); | ||
!function(a,n){"function"==typeof define&&define.amd?define(n):"object"==typeof exports?module.exports=n(require,exports,module):a.CountUp=n()}(this,function(a,n,t){var e=function(a,n,t,e,i,r){function o(a){a=a.toFixed(l.decimals),a+="";var n,t,e,i,r,o;if(n=a.split("."),t=n[0],e=n.length>1?l.options.decimal+n[1]:"",l.options.useGrouping){for(i="",r=0,o=t.length;r<o;++r)0!==r&&r%3===0&&(i=l.options.separator+i),i=t[o-r-1]+i;t=i}return l.options.numerals.length&&(t=t.replace(/[0-9]/g,function(a){return l.options.numerals[+a]}),e=e.replace(/[0-9]/g,function(a){return l.options.numerals[+a]})),l.options.prefix+t+e+l.options.suffix}function u(a,n,t,e){return t*(-Math.pow(2,-10*a/e)+1)*1024/1023+n}function s(a){return"number"==typeof a&&!isNaN(a)}var l=this;if(l.version=function(){return"1.9.2"},l.options={useEasing:!0,useGrouping:!0,separator:",",decimal:".",easingFn:u,formattingFn:o,prefix:"",suffix:"",numerals:[]},r&&"object"==typeof r)for(var m in l.options)r.hasOwnProperty(m)&&null!==r[m]&&(l.options[m]=r[m]);""===l.options.separator?l.options.useGrouping=!1:l.options.separator=""+l.options.separator;for(var d=0,c=["webkit","moz","ms","o"],f=0;f<c.length&&!window.requestAnimationFrame;++f)window.requestAnimationFrame=window[c[f]+"RequestAnimationFrame"],window.cancelAnimationFrame=window[c[f]+"CancelAnimationFrame"]||window[c[f]+"CancelRequestAnimationFrame"];window.requestAnimationFrame||(window.requestAnimationFrame=function(a,n){var t=(new Date).getTime(),e=Math.max(0,16-(t-d)),i=window.setTimeout(function(){a(t+e)},e);return d=t+e,i}),window.cancelAnimationFrame||(window.cancelAnimationFrame=function(a){clearTimeout(a)}),l.initialize=function(){return!!l.initialized||(l.error="",l.d="string"==typeof a?document.getElementById(a):a,l.d?(l.startVal=Number(n),l.endVal=Number(t),s(l.startVal)&&s(l.endVal)?(l.decimals=Math.max(0,e||0),l.dec=Math.pow(10,l.decimals),l.duration=1e3*Number(i)||2e3,l.countDown=l.startVal>l.endVal,l.frameVal=l.startVal,l.initialized=!0,!0):(l.error="[CountUp] startVal ("+n+") or endVal ("+t+") is not a number",!1)):(l.error="[CountUp] target is null or undefined",!1))},l.printValue=function(a){var n=l.options.formattingFn(a);"INPUT"===l.d.tagName?this.d.value=n:"text"===l.d.tagName||"tspan"===l.d.tagName?this.d.textContent=n:this.d.innerHTML=n},l.count=function(a){l.startTime||(l.startTime=a),l.timestamp=a;var n=a-l.startTime;l.remaining=l.duration-n,l.options.useEasing?l.countDown?l.frameVal=l.startVal-l.options.easingFn(n,0,l.startVal-l.endVal,l.duration):l.frameVal=l.options.easingFn(n,l.startVal,l.endVal-l.startVal,l.duration):l.countDown?l.frameVal=l.startVal-(l.startVal-l.endVal)*(n/l.duration):l.frameVal=l.startVal+(l.endVal-l.startVal)*(n/l.duration),l.countDown?l.frameVal=l.frameVal<l.endVal?l.endVal:l.frameVal:l.frameVal=l.frameVal>l.endVal?l.endVal:l.frameVal,l.frameVal=Math.round(l.frameVal*l.dec)/l.dec,l.printValue(l.frameVal),n<l.duration?l.rAF=requestAnimationFrame(l.count):l.callback&&l.callback()},l.start=function(a){l.initialize()&&(l.callback=a,l.rAF=requestAnimationFrame(l.count))},l.pauseResume=function(){l.paused?(l.paused=!1,delete l.startTime,l.duration=l.remaining,l.startVal=l.frameVal,requestAnimationFrame(l.count)):(l.paused=!0,cancelAnimationFrame(l.rAF))},l.reset=function(){l.paused=!1,delete l.startTime,l.initialized=!1,l.initialize()&&(cancelAnimationFrame(l.rAF),l.printValue(l.startVal))},l.update=function(a){if(l.initialize()){if(a=Number(a),!s(a))return void(l.error="[CountUp] update() - new endVal is not a number: "+a);l.error="",a!==l.frameVal&&(cancelAnimationFrame(l.rAF),l.paused=!1,delete l.startTime,l.startVal=l.frameVal,l.endVal=a,l.countDown=l.startVal>l.endVal,l.rAF=requestAnimationFrame(l.count))}},l.initialize()&&l.printValue(l.startVal)};return e}); |
{ | ||
"name": "countup.js", | ||
"description": "Animates a numerical value by counting to it", | ||
"version": "1.9.1", | ||
"version": "1.9.2", | ||
"license": "MIT", | ||
@@ -6,0 +6,0 @@ "main": "./dist/countUp.min.js", |
Sorry, the diff of this file is not supported yet
13
740
41351