1;(function (factory) { 2 'use strict'; 3 if (typeof define === 'function' && define.amd) { 4 // AMD is used - Register as an anonymous module. 5 define(['jquery'], factory); 6 } else if (typeof exports === 'object') { 7 factory(require('jquery')); 8 } else { 9 // Neither AMD nor CommonJS used. Use global variables. 10 if (typeof jQuery === 'undefined') { 11 throw 'jquery-numerator requires jQuery to be loaded first'; 12 } 13 factory(jQuery); 14 } 15}(function ($) { 16 17 var pluginName = "numerator", 18 defaults = { 19 easing: 'swing', 20 duration: 500, 21 delimiter: undefined, 22 rounding: 0, 23 toValue: undefined, 24 fromValue: undefined, 25 queue: false, 26 onStart: function(){}, 27 onStep: function(){}, 28 onProgress: function(){}, 29 onComplete: function(){} 30 }; 31 32 function Plugin ( element, options ) { 33 this.element = element; 34 this.settings = $.extend( {}, defaults, options ); 35 this._defaults = defaults; 36 this._name = pluginName; 37 this.init(); 38 } 39 40 Plugin.prototype = { 41 42 init: function () { 43 this.parseElement(); 44 this.setValue(); 45 }, 46 47 parseElement: function () { 48 var elText = $.trim($(this.element).text()); 49 50 this.settings.fromValue = this.settings.fromValue || this.format(elText); 51 }, 52 53 setValue: function() { 54 var self = this; 55 56 $({value: self.settings.fromValue}).animate({value: self.settings.toValue}, { 57 58 duration: parseInt(self.settings.duration, 10), 59 60 easing: self.settings.easing, 61 62 start: self.settings.onStart, 63 64 step: function(now, fx) { 65 $(self.element).text(self.format(now)); 66 // accepts two params - (now, fx) 67 self.settings.onStep(now, fx); 68 }, 69 70 // accepts three params - (animation object, progress ratio, time remaining(ms)) 71 progress: self.settings.onProgress, 72 73 complete: self.settings.onComplete 74 }); 75 }, 76 77 format: function(value){ 78 var self = this; 79 80 if ( parseInt(this.settings.rounding ) < 1) { 81 value = parseInt(value, 10); 82 } else { 83 value = parseFloat(value).toFixed( parseInt(this.settings.rounding) ); 84 } 85 value = value.toString().replace(/\./g,","); 86 if (self.settings.delimiter) { 87 return this.delimit(value) 88 } else { 89 return value; 90 } 91 }, 92 93 // TODO: Add comments to this function 94 delimit: function(value){ 95 var self = this; 96 97 value = value.toString(); 98 99 if (self.settings.rounding && parseInt(self.settings.rounding, 10) > 0) { 100 var decimals = value.substring( (value.length - (self.settings.rounding + 1)), value.length ), 101 wholeValue = value.substring( 0, (value.length - (self.settings.rounding + 1))); 102 103 return self.addDelimiter(wholeValue) + decimals; 104 } else { 105 return self.addDelimiter(value); 106 } 107 }, 108 109 addDelimiter: function(value){ 110 return value.toString().replace(/\B(?=(\d{3})+(?!\d))/g, this.settings.delimiter); 111 } 112 }; 113 114 $.fn[ pluginName ] = function ( options ) { 115 return this.each(function() { 116 if ( $.data( this, "plugin_" + pluginName ) ) { 117 $.data(this, 'plugin_' + pluginName, null); 118 } 119 $.data( this, "plugin_" + pluginName, new Plugin( this, options ) ); 120 }); 121 }; 122 123}));
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.