jquery.counterup
Advanced tools
Comparing version 2.0.5 to 2.1.0
{ | ||
"name": "jquery.counterup", | ||
"version": "2.0.5", | ||
"version": "2.1.0", | ||
"title": "jquery.counterup", | ||
@@ -5,0 +5,0 @@ "description": "A lightweight jQuery plugin that counts up to a targeted number when the number becomes visible.", |
/*! | ||
* jquery.counterup.js 2.0.5 | ||
* jquery.counterup.js 2.1.0 | ||
* | ||
@@ -9,3 +9,3 @@ * Copyright 2013, Benjamin Intal http://gambit.ph @bfintal | ||
* | ||
* Date: Jun 21, 2016 | ||
* Date: Feb 24, 2017 | ||
*/ | ||
@@ -21,3 +21,6 @@ (function ($) { | ||
'delay': 10, | ||
'offset': 100, | ||
'beginAt': 0, | ||
'formatter': false, | ||
'context': 'window', | ||
callback: function () { | ||
@@ -34,3 +37,6 @@ } | ||
time: $(this).data('counterup-time') || settings.time, | ||
delay: $(this).data('counterup-delay') || settings.delay | ||
delay: $(this).data('counterup-delay') || settings.delay, | ||
offset: $(this).data('counterup-offset') || settings.offset, | ||
beginAt: $(this).data('counterup-beginat') || settings.beginAt, | ||
context: $(this).data('counterup-context') || settings.context | ||
}; | ||
@@ -41,6 +47,8 @@ | ||
var divisions = counter.time / counter.delay; | ||
var num = $this.text(); | ||
var num = $(this).attr('data-num') ? $(this).attr('data-num') : $this.text(); | ||
var isComma = /[0-9]+,[0-9]+/.test(num); | ||
num = num.replace(/,/g, ''); | ||
var decimalPlaces = (num.split('.')[1] || []).length; | ||
if (counter.beginAt > num) | ||
counter.beginAt = num; | ||
@@ -61,3 +69,3 @@ var isTime = /[0-9]+:[0-9]+:[0-9]+/.test(num); | ||
// Generate list of incremental numbers to display | ||
for (var i = divisions; i >= 1; i--) { | ||
for (var i = divisions; i >= counter.beginAt / num * divisions; i--) { | ||
@@ -88,11 +96,10 @@ var newNum = parseFloat(num / divisions * i).toFixed(decimalPlaces); | ||
$this.data('counterup-nums', nums); | ||
$this.text('0'); | ||
$this.text(counter.beginAt); | ||
// Updates the number until we're done | ||
var f = function () { | ||
if(!$this.data('counterup-nums')) | ||
{ | ||
settings.callback.call(this); | ||
return; | ||
} | ||
if (!$this.data('counterup-nums')) { | ||
settings.callback.call(this); | ||
return; | ||
} | ||
$this.html($this.data('counterup-nums').shift()); | ||
@@ -117,3 +124,3 @@ if ($this.data('counterup-nums').length) { | ||
this.destroy(); //-- Waypoint 3.0 version of triggerOnce | ||
}, {offset: '100%'}); | ||
}, {offset: counter.offset + "%", context: counter.context}); | ||
}); | ||
@@ -120,0 +127,0 @@ |
@@ -1,1 +0,1 @@ | ||
!function(t){"use strict";t.fn.counterUp=function(a){var e,n=t.extend({time:400,delay:10,formatter:!1,callback:function(){}},a);return this.each(function(){var a=t(this),u={time:t(this).data("counterup-time")||n.time,delay:t(this).data("counterup-delay")||n.delay},r=function(){var t=[],r=u.time/u.delay,o=a.text(),c=/[0-9]+,[0-9]+/.test(o);o=o.replace(/,/g,"");var i=(o.split(".")[1]||[]).length,l=/[0-9]+:[0-9]+:[0-9]+/.test(o);if(l){var s=o.split(":"),d=1;for(e=0;s.length>0;)e+=d*parseInt(s.pop(),10),d*=60}for(var f=r;f>=1;f--){var p=parseFloat(o/r*f).toFixed(i);if(l){p=parseInt(e/r*f);var m=parseInt(p/3600)%24,h=parseInt(p/60)%60,v=parseInt(p%60,10);p=(10>m?"0"+m:m)+":"+(10>h?"0"+h:h)+":"+(10>v?"0"+v:v)}if(c)for(;/(\d+)(\d{3})/.test(p.toString());)p=p.toString().replace(/(\d+)(\d{3})/,"$1,$2");n.formatter&&(p=n.formatter.call(this,p)),t.unshift(p)}a.data("counterup-nums",t),a.text("0");var y=function(){return a.data("counterup-nums")?(a.html(a.data("counterup-nums").shift()),void(a.data("counterup-nums").length?setTimeout(a.data("counterup-func"),u.delay):(a.data("counterup-nums",null),a.data("counterup-func",null),n.callback.call(this)))):void n.callback.call(this)};a.data("counterup-func",y),setTimeout(a.data("counterup-func"),u.delay)};a.waypoint(function(t){r(),this.destroy()},{offset:"100%"})})}}(jQuery); | ||
(function($){"use strict";$.fn.counterUp=function(options){var settings=$.extend({time:400,delay:10,offset:100,beginAt:0,formatter:false,context:"window",callback:function(){}},options),s;return this.each(function(){var $this=$(this),counter={time:$(this).data("counterup-time")||settings.time,delay:$(this).data("counterup-delay")||settings.delay,offset:$(this).data("counterup-offset")||settings.offset,beginAt:$(this).data("counterup-beginat")||settings.beginAt,context:$(this).data("counterup-context")||settings.context};var counterUpper=function(){var nums=[];var divisions=counter.time/counter.delay;var num=$(this).attr("data-num")?$(this).attr("data-num"):$this.text();var isComma=/[0-9]+,[0-9]+/.test(num);num=num.replace(/,/g,"");var decimalPlaces=(num.split(".")[1]||[]).length;if(counter.beginAt>num)counter.beginAt=num;var isTime=/[0-9]+:[0-9]+:[0-9]+/.test(num);if(isTime){var times=num.split(":"),m=1;s=0;while(times.length>0){s+=m*parseInt(times.pop(),10);m*=60}}for(var i=divisions;i>=counter.beginAt/num*divisions;i--){var newNum=parseFloat(num/divisions*i).toFixed(decimalPlaces);if(isTime){newNum=parseInt(s/divisions*i);var hours=parseInt(newNum/3600)%24;var minutes=parseInt(newNum/60)%60;var seconds=parseInt(newNum%60,10);newNum=(hours<10?"0"+hours:hours)+":"+(minutes<10?"0"+minutes:minutes)+":"+(seconds<10?"0"+seconds:seconds)}if(isComma){while(/(\d+)(\d{3})/.test(newNum.toString())){newNum=newNum.toString().replace(/(\d+)(\d{3})/,"$1"+","+"$2")}}if(settings.formatter){newNum=settings.formatter.call(this,newNum)}nums.unshift(newNum)}$this.data("counterup-nums",nums);$this.text(counter.beginAt);var f=function(){if(!$this.data("counterup-nums")){settings.callback.call(this);return}$this.html($this.data("counterup-nums").shift());if($this.data("counterup-nums").length){setTimeout($this.data("counterup-func"),counter.delay)}else{$this.data("counterup-nums",null);$this.data("counterup-func",null);settings.callback.call(this)}};$this.data("counterup-func",f);setTimeout($this.data("counterup-func"),counter.delay)};$this.waypoint(function(direction){counterUpper();this.destroy()},{offset:counter.offset+"%",context:counter.context})})}})(jQuery); |
{ | ||
"name": "jquery.counterup", | ||
"version": "2.0.5", | ||
"version": "2.1.0", | ||
"description": "jquery.counterup is a lightweight jQuery plugin that counts up to a targeted number when the number becomes visible.", | ||
@@ -33,3 +33,4 @@ "main": "jquery.counterup.js", | ||
"Jeremy Paris (https://github.com/digsite)", | ||
"Ciro Mattia Gonano <ciromattia@gmail.com> (https://github.com/ciromattia)" | ||
"Ciro Mattia Gonano <ciromattia@gmail.com> (https://github.com/ciromattia)", | ||
"Josh Lee (https://github.com/Jishaxe)" | ||
], | ||
@@ -36,0 +37,0 @@ "license": "GPL-2.0", |
@@ -50,3 +50,3 @@ jquery.counterup | ||
``` | ||
<span class="counter" data-counterup-time="1500" data-counterup-delay="30">1,234,567.00</span> | ||
<span class="counter" data-counterup-time="1500" data-counterup-delay="30" data-counterup-beginat="100">1,234,567.00</span> | ||
``` | ||
@@ -66,2 +66,4 @@ | ||
time: 1000, | ||
offset: 70, | ||
beginAt: 100, | ||
formatter: function (n) { | ||
@@ -77,2 +79,7 @@ return n.replace(/,/g, '.'); | ||
`offset` - The viewport percentile from which the counter starts (by default it's 100, meaning it's triggered | ||
at the very moment the element enters the viewport) | ||
`beginAt` - The number from which to count up | ||
`formatter` - A callback to format the number with |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
38263
189
83