Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-09 07:58:27

0001 /*!

0002  * jquery.counterup.js 2.0.5

0003  *

0004  * Copyright 2013, Benjamin Intal http://gambit.ph @bfintal

0005  * Released under the GPL v2 License

0006  *

0007  * Amended by Jeremy Paris, Ciro Mattia Gonano and others

0008  *

0009  * Date: Jun 21, 2016

0010  */
0011 (function ($) {
0012     "use strict";
0013 
0014     $.fn.counterUp = function (options) {
0015 
0016         // Defaults

0017         var settings = $.extend({
0018                 'time': 400,
0019                 'delay': 10,
0020                 'formatter': false,
0021                 callback: function () {
0022                 }
0023             }, options),
0024             s;
0025 
0026         return this.each(function () {
0027 
0028             // Store the object

0029             var $this = $(this),
0030                 counter = {
0031                     time: $(this).data('counterup-time') || settings.time,
0032                     delay: $(this).data('counterup-delay') || settings.delay
0033                 };
0034 
0035             var counterUpper = function () {
0036                 var nums = [];
0037                 var divisions = counter.time / counter.delay;
0038                 var num = $this.text();
0039                 var isComma = /[0-9]+,[0-9]+/.test(num);
0040                 num = num.replace(/,/g, '');
0041                 var decimalPlaces = (num.split('.')[1] || []).length;
0042 
0043                 var isTime = /[0-9]+:[0-9]+:[0-9]+/.test(num);
0044 
0045                 // Convert time to total seconds

0046                 if (isTime) {
0047                     var times = num.split(':'),
0048                         m = 1;
0049                     s = 0;
0050                     while (times.length > 0) {
0051                         s += m * parseInt(times.pop(), 10);
0052                         m *= 60;
0053                     }
0054                 }
0055 
0056                 // Generate list of incremental numbers to display

0057                 for (var i = divisions; i >= 1; i--) {
0058 
0059                     var newNum = parseFloat(num / divisions * i).toFixed(decimalPlaces);
0060 
0061                     // Add incremental seconds and convert back to time

0062                     if (isTime) {
0063                         newNum = parseInt(s / divisions * i);
0064                         var hours = parseInt(newNum / 3600) % 24;
0065                         var minutes = parseInt(newNum / 60) % 60;
0066                         var seconds = parseInt(newNum % 60, 10);
0067                         newNum = (hours < 10 ? "0" + hours : hours) + ":" + (minutes < 10 ? "0" + minutes : minutes) + ":" + (seconds < 10 ? "0" + seconds : seconds);
0068                     }
0069 
0070                     // Preserve commas if input had commas

0071                     if (isComma) {
0072                         while (/(\d+)(\d{3})/.test(newNum.toString())) {
0073                             newNum = newNum.toString().replace(/(\d+)(\d{3})/, '$1' + ',' + '$2');
0074                         }
0075                     }
0076                     if (settings.formatter) {
0077                         newNum = settings.formatter.call(this, newNum);
0078                     }
0079                     nums.unshift(newNum);
0080                 }
0081 
0082                 $this.data('counterup-nums', nums);
0083                 $this.text('0');
0084 
0085                 // Updates the number until we're done

0086                 var f = function () {
0087                         if(!$this.data('counterup-nums'))
0088                         {
0089                                                 settings.callback.call(this);
0090                                                 return;
0091                                         }
0092                     $this.html($this.data('counterup-nums').shift());
0093                     if ($this.data('counterup-nums').length) {
0094                         setTimeout($this.data('counterup-func'), counter.delay);
0095                     } else {
0096                         $this.data('counterup-nums', null);
0097                         $this.data('counterup-func', null);
0098                         settings.callback.call(this);
0099                     }
0100                 };
0101                 $this.data('counterup-func', f);
0102 
0103                 // Start the count up

0104                 setTimeout($this.data('counterup-func'), counter.delay);
0105             };
0106 
0107             // Perform counts when the element gets into view

0108             $this.waypoint(function (direction) {
0109                 counterUpper();
0110                 this.destroy(); //-- Waypoint 3.0 version of triggerOnce

0111             }, {offset: '100%'});
0112         });
0113 
0114     };
0115 
0116 })(jQuery);