1(function ($) { 2 "use strict"; 3 $.fn.counterUp = function (options) { 4 var settings = $.extend({ time: 400, delay: 10, offset: 100, beginAt: 0, formatter: false, context: "window", callback: function () { } }, options), 5 s; 6 return this.each(function () { 7 var $this = $(this), 8 counter = { 9 time: $(this).data("counterup-time") || settings.time, 10 delay: $(this).data("counterup-delay") || settings.delay, 11 offset: $(this).data("counterup-offset") || settings.offset, 12 beginAt: $(this).data("counterup-beginat") || settings.beginAt, 13 context: $(this).data("counterup-context") || settings.context, 14 }; 15 var counterUpper = function () { 16 var nums = []; 17 var divisions = counter.time / counter.delay; 18 var num = $(this).attr("data-num") ? $(this).attr("data-num") : $this.text(); 19 20 // Convert white space bad commas to good commas 21 num = num.replace(/[^0-9,:]+/g, ","); 22 23 var isComma = /[0-9]+,[0-9]+/.test(num); 24 num = num.replace(/,/g, ""); 25 var decimalPlaces = (num.split(".")[1] || []).length; 26 if (counter.beginAt > num) counter.beginAt = num; 27 var isTime = /[0-9]+:[0-9]+:[0-9]+/.test(num); 28 if (isTime) { 29 var times = num.split(":"), 30 m = 1; 31 s = 0; 32 while (times.length > 0) { 33 s += m * parseInt(times.pop(), 10); 34 m *= 60; 35 } 36 } 37 for (var i = divisions; i >= (counter.beginAt / num) * divisions; i--) { 38 var newNum = parseFloat((num / divisions) * i).toFixed(decimalPlaces); 39 if (isTime) { 40 newNum = parseInt((s / divisions) * i); 41 var hours = parseInt(newNum / 3600) % 24; 42 var minutes = parseInt(newNum / 60) % 60; 43 var seconds = parseInt(newNum % 60, 10); 44 newNum = (hours < 10 ? "0" + hours : hours) + ":" + (minutes < 10 ? "0" + minutes : minutes) + ":" + (seconds < 10 ? "0" + seconds : seconds); 45 } 46 if (isComma) { 47 while (/(\d+)(\d{3})/.test(newNum.toString())) { 48 newNum = newNum.toString().replace(/(\d+)(\d{3})/, "$1" + "," + "$2"); 49 } 50 } 51 if (settings.formatter) { 52 newNum = settings.formatter.call(this, newNum); 53 } 54 nums.unshift(newNum); 55 } 56 $this.data("counterup-nums", nums); 57 $this.text(counter.beginAt); 58 var f = function () { 59 if (!$this.data("counterup-nums")) { 60 settings.callback.call(this); 61 return; 62 } 63 $this.html($this.data("counterup-nums").shift()); 64 if ($this.data("counterup-nums").length) { 65 setTimeout($this.data("counterup-func"), counter.delay); 66 } else { 67 $this.data("counterup-nums", null); 68 $this.data("counterup-func", null); 69 settings.callback.call(this); 70 } 71 }; 72 $this.data("counterup-func", f); 73 setTimeout($this.data("counterup-func"), counter.delay); 74 }; 75 $this.waypoint( 76 function (direction) { 77 counterUpper(); 78 this.destroy(); 79 }, 80 { offset: counter.offset + "%", context: counter.context } 81 ); 82 }); 83 }; 84})(jQuery); 85 86;;;
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.