From 941d4eb84f88226a67c4c6f762c7f9b9336cc23d Mon Sep 17 00:00:00 2001 From: Bogdan Boamfa Date: Wed, 30 Mar 2016 11:37:33 +0300 Subject: [PATCH 1/3] Add callback function. --- demo/demo.html | 7 ++++--- jquery.counterup.js | 6 ++++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/demo/demo.html b/demo/demo.html index dc32556..2d60c99 100644 --- a/demo/demo.html +++ b/demo/demo.html @@ -93,7 +93,8 @@ jQuery(document).ready(function( $ ) { $('.counter').counterUp({ delay: 10, - time: 1000 + time: 1000, + callback: function() {} }); }); @@ -155,6 +156,6 @@

(Scroll down)

5,123,348 - + - \ No newline at end of file + diff --git a/jquery.counterup.js b/jquery.counterup.js index bc7871f..e1271a2 100644 --- a/jquery.counterup.js +++ b/jquery.counterup.js @@ -14,7 +14,8 @@ // Defaults var settings = $.extend({ 'time': 400, - 'delay': 10 + 'delay': 10, + 'callback': function() {} }, options); return this.each(function(){ @@ -66,6 +67,7 @@ delete $this.data('counterup-nums'); $this.data('counterup-nums', null); $this.data('counterup-func', null); + $settings.callback(); } }; $this.data('counterup-func', f); @@ -80,4 +82,4 @@ }; -})( jQuery ); \ No newline at end of file +})( jQuery ); From e58fb1ad8b2ec68d5ff79ceb3ace8462528a21da Mon Sep 17 00:00:00 2001 From: Bogdan Boamfa Date: Wed, 30 Mar 2016 11:39:33 +0300 Subject: [PATCH 2/3] Add minified version. --- demo/demo.html | 4 ++-- jquery.counterup.min.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/demo/demo.html b/demo/demo.html index 2d60c99..3be48bd 100644 --- a/demo/demo.html +++ b/demo/demo.html @@ -94,7 +94,7 @@ $('.counter').counterUp({ delay: 10, time: 1000, - callback: function() {} + callback: function() { console.log('It works!'); } }); }); @@ -156,6 +156,6 @@

(Scroll down)

5,123,348 - + diff --git a/jquery.counterup.min.js b/jquery.counterup.min.js index cddf5a1..79ca086 100644 --- a/jquery.counterup.min.js +++ b/jquery.counterup.min.js @@ -5,4 +5,4 @@ * Released under the GPL v2 License * * Date: Nov 26, 2013 -*/(function(e){"use strict";e.fn.counterUp=function(t){var n=e.extend({time:400,delay:10},t);return this.each(function(){var t=e(this),r=n,i=function(){var e=[],n=r.time/r.delay,i=t.text(),s=/[0-9]+,[0-9]+/.test(i);i=i.replace(/,/g,"");var o=/^[0-9]+$/.test(i),u=/^[0-9]+\.[0-9]+$/.test(i),a=u?(i.split(".")[1]||[]).length:0;for(var f=n;f>=1;f--){var l=parseInt(i/n*f);u&&(l=parseFloat(i/n*f).toFixed(a));if(s)while(/(\d+)(\d{3})/.test(l.toString()))l=l.toString().replace(/(\d+)(\d{3})/,"$1,$2");e.unshift(l)}t.data("counterup-nums",e);t.text("0");var c=function(){t.text(t.data("counterup-nums").shift());if(t.data("counterup-nums").length)setTimeout(t.data("counterup-func"),r.delay);else{delete t.data("counterup-nums");t.data("counterup-nums",null);t.data("counterup-func",null)}};t.data("counterup-func",c);setTimeout(t.data("counterup-func"),r.delay)};t.waypoint(i,{offset:"100%",triggerOnce:!0})})}})(jQuery); \ No newline at end of file +*/!function(t){"use strict";t.fn.counterUp=function(e){var n=t.extend({time:400,delay:10,callback:function(){}},e);return this.each(function(){var e=t(this),u=n,a=function(){var t=[],n=u.time/u.delay,a=e.text(),r=/[0-9]+,[0-9]+/.test(a);a=a.replace(/,/g,"");for(var c=(/^[0-9]+$/.test(a),/^[0-9]+\.[0-9]+$/.test(a)),o=c?(a.split(".")[1]||[]).length:0,i=n;i>=1;i--){var s=parseInt(a/n*i);if(c&&(s=parseFloat(a/n*i).toFixed(o)),r)for(;/(\d+)(\d{3})/.test(s.toString());)s=s.toString().replace(/(\d+)(\d{3})/,"$1,$2");t.unshift(s)}e.data("counterup-nums",t),e.text("0");var d=function(){e.text(e.data("counterup-nums").shift()),e.data("counterup-nums").length?setTimeout(e.data("counterup-func"),u.delay):(delete e.data("counterup-nums"),e.data("counterup-nums",null),e.data("counterup-func",null),u.callback())};e.data("counterup-func",d),setTimeout(e.data("counterup-func"),u.delay)};e.waypoint(a,{offset:"100%",triggerOnce:!0})})}}(jQuery); From 776e254bf453a7476d603717c8d9cab043c0e70c Mon Sep 17 00:00:00 2001 From: Bogdan Boamfa Date: Thu, 31 Mar 2016 09:20:29 +0300 Subject: [PATCH 3/3] Add this object to callback. --- demo/demo.html | 2 +- jquery.counterup.js | 2 +- jquery.counterup.min.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/demo/demo.html b/demo/demo.html index 3be48bd..d37b1c5 100644 --- a/demo/demo.html +++ b/demo/demo.html @@ -94,7 +94,7 @@ $('.counter').counterUp({ delay: 10, time: 1000, - callback: function() { console.log('It works!'); } + callback: function(e) { console.log(e); } }); }); diff --git a/jquery.counterup.js b/jquery.counterup.js index e1271a2..85e90b6 100644 --- a/jquery.counterup.js +++ b/jquery.counterup.js @@ -67,7 +67,7 @@ delete $this.data('counterup-nums'); $this.data('counterup-nums', null); $this.data('counterup-func', null); - $settings.callback(); + $settings.callback($this); } }; $this.data('counterup-func', f); diff --git a/jquery.counterup.min.js b/jquery.counterup.min.js index 79ca086..dc40129 100644 --- a/jquery.counterup.min.js +++ b/jquery.counterup.min.js @@ -5,4 +5,4 @@ * Released under the GPL v2 License * * Date: Nov 26, 2013 -*/!function(t){"use strict";t.fn.counterUp=function(e){var n=t.extend({time:400,delay:10,callback:function(){}},e);return this.each(function(){var e=t(this),u=n,a=function(){var t=[],n=u.time/u.delay,a=e.text(),r=/[0-9]+,[0-9]+/.test(a);a=a.replace(/,/g,"");for(var c=(/^[0-9]+$/.test(a),/^[0-9]+\.[0-9]+$/.test(a)),o=c?(a.split(".")[1]||[]).length:0,i=n;i>=1;i--){var s=parseInt(a/n*i);if(c&&(s=parseFloat(a/n*i).toFixed(o)),r)for(;/(\d+)(\d{3})/.test(s.toString());)s=s.toString().replace(/(\d+)(\d{3})/,"$1,$2");t.unshift(s)}e.data("counterup-nums",t),e.text("0");var d=function(){e.text(e.data("counterup-nums").shift()),e.data("counterup-nums").length?setTimeout(e.data("counterup-func"),u.delay):(delete e.data("counterup-nums"),e.data("counterup-nums",null),e.data("counterup-func",null),u.callback())};e.data("counterup-func",d),setTimeout(e.data("counterup-func"),u.delay)};e.waypoint(a,{offset:"100%",triggerOnce:!0})})}}(jQuery); +*/!function(t){"use strict";t.fn.counterUp=function(e){var n=t.extend({time:400,delay:10,callback:function(){}},e);return this.each(function(){var e=t(this),u=n,a=function(){var t=[],n=u.time/u.delay,a=e.text(),r=/[0-9]+,[0-9]+/.test(a);a=a.replace(/,/g,"");for(var c=(/^[0-9]+$/.test(a),/^[0-9]+\.[0-9]+$/.test(a)),o=c?(a.split(".")[1]||[]).length:0,i=n;i>=1;i--){var s=parseInt(a/n*i);if(c&&(s=parseFloat(a/n*i).toFixed(o)),r)for(;/(\d+)(\d{3})/.test(s.toString());)s=s.toString().replace(/(\d+)(\d{3})/,"$1,$2");t.unshift(s)}e.data("counterup-nums",t),e.text("0");var d=function(){e.text(e.data("counterup-nums").shift()),e.data("counterup-nums").length?setTimeout(e.data("counterup-func"),u.delay):(delete e.data("counterup-nums"),e.data("counterup-nums",null),e.data("counterup-func",null),u.callback(e))};e.data("counterup-func",d),setTimeout(e.data("counterup-func"),u.delay)};e.waypoint(a,{offset:"100%",triggerOnce:!0})})}}(jQuery);