1/*! 2* jquery.counterup.js 1.0 3* 4* Copyright 2013, Benjamin Intal http://gambit.ph @bfintal 5* Released under the GPL v2 License 6* 7* Date: Nov 26, 2013 8*/ 9(function( $ ){ 10 "use strict"; 11 12 $.fn.counterUp = function( options ) { 13 14 // Defaults 15 var settings = $.extend({ 16 'time': 400, 17 'delay': 10 18 }, options); 19 20 return this.each(function(){ 21 22 // Store the object 23 var $this = $(this); 24 var $settings = settings; 25 var counterUpper = function() { 26 var nums = []; 27 var divisions = $settings.time / $settings.delay; 28 var num = $this.text(); 29 var isComma = /[0-9]+,[0-9]+/.test(num); 30 num = num.replace(/,/g, ''); 31 var isInt = /^[0-9]+$/.test(num); 32 var isFloat = /^[0-9]+\.[0-9]+$/.test(num); 33 var decimalPlaces = isFloat ? (num.split('.')[1] || []).length : 0; 34 35 // Generate list of incremental numbers to display 36 for (var i = divisions; i >= 1; i--) { 37 38 // Preserve as int if input was int 39 var newNum = parseInt(num / divisions * i); 40 41 // Preserve float if input was float 42 if (isFloat) { 43 newNum = parseFloat(num / divisions * i).toFixed(decimalPlaces); 44 } 45 46 // Preserve commas if input had commas 47 if (isComma) { 48 while (/(\d+)(\d{3})/.test(newNum.toString())) { 49 newNum = newNum.toString().replace(/(\d+)(\d{3})/, '$1'+','+'$2'); 50 } 51 } 52 53 nums.unshift(newNum); 54 } 55 56 $this.data('counterup-nums', nums); 57 $this.text('0'); 58 59 // Updates the number until we're done 60 var f = function() { 61 $this.text($this.data('counterup-nums').shift()); 62 if ($this.data('counterup-nums').length) { 63 setTimeout($this.data('counterup-func'), $settings.delay); 64 } else { 65 delete $this.data('counterup-nums'); 66 $this.data('counterup-nums', null); 67 $this.data('counterup-func', null); 68 } 69 }; 70 $this.data('counterup-func', f); 71 72 // Start the count up 73 setTimeout($this.data('counterup-func'), $settings.delay); 74 75 this.destroy(); 76 }; 77 78 // Perform counts when the element gets into view 79 $this.waypoint(counterUpper, { offset: '100%', triggerOnce: true }); 80 }); 81 82 }; 83 84})( jQuery );
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.