PageSourceSearch

https://esbank.pl/assets/frontend/js/jquery.number-574155e9e4571307ff0663e03043052d.js

js esbank.pl collected 2026-10-08 11:00:58 UTC 17,547 bytes, 626 lines download raw bytes

vendor: 12,500 bytes, lines 1-462
1/**
2* jQuery number plug-in 2.1.0
3* Copyright 2012, Digital Fusion
4* Licensed under the MIT license.
5* http://opensource.teamdf.com/license/
6*
7* A jQuery plugin which implements a permutation of phpjs.org's number_format to provide
8* simple number formatting, insertion, and as-you-type masking of a number.
9*
10* @author Sam Sehnert
11* @docs http://www.teamdf.com/web/jquery-number-format-redux/196/
12*/
13(function($){
14
15/**
16* Method for selecting a range of characters in an input/textarea.
17*
18* @param int rangeStart : Where we want the selection to start.
19* @param int rangeEnd : Where we want the selection to end.
20*
21* @return void;
22*/
23function setSelectionRange( rangeStart, rangeEnd )
24{
25// Check which way we need to define the text range.
26if( this.createTextRange )
27{
28var range = this.createTextRange();
29range.collapse( true );
30range.moveStart( 'character',	rangeStart );
31range.moveEnd( 'character',	rangeEnd-rangeStart );
32range.select();
33}
34
35// Alternate setSelectionRange method for supporting browsers.
36else if( this.setSelectionRange )
37{
38this.focus();
39this.setSelectionRange( rangeStart, rangeEnd );
40}
41}
42
43/**
44* Get the selection position for the given part.
45*
46* @param string part : Options, 'Start' or 'End'. The selection position to get.
47*
48* @return int : The index position of the selection part.
49*/
50function getSelection( part )
51{
52var pos	= this.value.length;
53
54// Work out the selection part.
55part = ( part.toLowerCase() == 'start' ? 'Start' : 'End' );
56
57if( document.selection ){
58// The current selection
59var range = document.selection.createRange(), stored_range, selectionStart, selectionEnd;
60// We'll use this as a 'dummy'
61stored_range = range.duplicate();
62// Select all text
63//stored_range.moveToElementText( this );
64stored_range.expand('textedit');
65// Now move 'dummy' end point to end point of original range
66stored_range.setEndPoint( 'EndToEnd', range );
67// Now we can calculate start and end points
68selectionStart = stored_range.text.length - range.text.length;
69selectionEnd = selectionStart + range.text.length;
70return part == 'Start' ? selectionStart : selectionEnd;
71}
72
73else if(typeof(this['selection'+part])!="undefined")
74{
75pos = this['selection'+part];
76}
77return pos;
78}
79
80/**
81* Substitutions for keydown keycodes.
82* Allows conversion from e.which to ascii characters.
83*/
84var _keydown = {
85codes : {
86188 : 44,
87109 : 45,
88190 : 46,
89191 : 47,
90192 : 96,
91220 : 92,
92222 : 39,
93221 : 93,
94219 : 91,
95173 : 45,
96187 : 61, //IE Key codes
97186 : 59, //IE Key codes
98189 : 45, //IE Key codes
99110 : 46 //IE Key codes
100        },
101        shifts : {
10296 : "~",
10349 : "!",
10450 : "@",
10551 : "#",
10652 : "$",
10753 : "%",
10854 : "^",
10955 : "&",
11056 : "*",
11157 : "(",
11248 : ")",
11345 : "_",
11461 : "+",
11591 : "{",
11693 : "}",
11792 : "|",
11859 : ":",
11939 : "\"",
12044 : "<",
12146 : ">",
12247 : "?"
123        }
124    };
125
126/**
127* jQuery number formatter plugin. This will allow you to format numbers on an element.
128*
129* @params proxied for format_number method.
130*
131* @return : The jQuery collection the method was called with.
132*/
133$.fn.number = function( number, decimals, dec_point, thousands_sep ){
134
135// Enter the default thousands separator, and the decimal placeholder.
136thousands_sep	= (typeof thousands_sep === 'undefined') ? ' ' : thousands_sep;
137dec_point	= (typeof dec_point === 'undefined') ? ',' : dec_point;
138decimals	= (typeof decimals === 'undefined' ) ? 0 : decimals;
139
140// Work out the unicode character for the decimal placeholder.
141var u_dec	= ('\\u'+('0000'+(dec_point.charCodeAt(0).toString(16))).slice(-4)),
142regex_dec_num	= new RegExp('[^'+u_dec+'0-9]','g'),
143regex_dec	= new RegExp(u_dec,'g');
144
145// If we've specified to take the number from the target element,
146// we loop over the collection, and get the number.
147if( number === true )
148{
149// If this element is a number, then we add a keyup
150if( this.is('input:text') )
151{
152// Return the jquery collection.
153return this.on({
154
155/**
156* Handles keyup events, re-formatting numbers.
157*
158* @param object e : the keyup event object.s
159*
160* @return void;
161*/
162'keydown.format' : function(e){
163
164// Define variables used in the code below.
165var $this	= $(this),
166data	= $this.data('numFormat'),
167code	= (e.keyCode ? e.keyCode : e.which),
168chara	= '', //unescape(e.originalEvent.keyIdentifier.replace('U+','%u')),
169start	= getSelection.apply(this,['start']),
170end	= getSelection.apply(this,['end']),
171val	= '',
172setPos	= false;
173
174// Webkit (Chrome & Safari) on windows screws up the keyIdentifier detection
175// for numpad characters. I've disabled this for now, because while keyCode munging
176// below is hackish and ugly, it actually works cross browser & platform.
177
178// if( typeof e.originalEvent.keyIdentifier !== 'undefined' )
179// {
180// chara = unescape(e.originalEvent.keyIdentifier.replace('U+','%u'));
181// }
182// else
183// {
184if (_keydown.codes.hasOwnProperty(code)) {
185code = _keydown.codes[code];
186}
187if (!e.shiftKey && (code >= 65 && code <= 90)){
188code += 32;
189} else if (!e.shiftKey && (code >= 69 && code <= 105)){
190code -= 48;
191} else if (e.shiftKey && _keydown.shifts.hasOwnProperty(code)){
192//get shifted keyCode value
193chara = _keydown.shifts[code];
194}
195
196if( chara == '' ) chara = String.fromCharCode(code);
197// }
198
199// Stop executing if the user didn't type a number key, a decimal character, or backspace.
200if( code !== 8 && chara != dec_point && !chara.match(/[0-9]/) )
201{
202// We need the original keycode now...
203var key = (e.keyCode ? e.keyCode : e.which);
204if( // Allow control keys to go through... (delete, etc)
205key == 46 || key == 8 || key == 9 || key == 27 || key == 13 ||
206// Allow: Ctrl+A, Ctrl+R
207( (key == 65 || key == 82 ) && ( e.ctrlKey || e.metaKey ) === true ) ||
208// Allow: home, end, left, right
209( (key >= 35 && key <= 39) )
210){
211return;
212}
213// But prevent all other keys.
214e.preventDefault();
215return false;
216}
217
218//console.log('Continuing on: ', code, chara);
219
220// The whole lot has been selected, or if the field is empty, and the character
221if( ( start == 0 && end == this.value.length || $this.val() == 0 ) && !e.metaKey && !e.ctrlKey && !e.altKey && chara.length === 1 && chara != 0 )
222{
223// Blank out the field, but only if the data object has already been instanciated.
224     start = end = 1;
225     this.value = '';
226    
227     // Reset the cursor position.
228data.init = (decimals>0?-1:0);
229data.c = (decimals>0?-(decimals+1):0);
230setSelectionRange.apply(this, [0,0]);
231}
232
233// Otherwise, we need to reset the caret position
234// based on the users selection.
235else
236{
237data.c = end-this.value.length;
238}
239
240// If the start position is before the decimal point,
241// and the user has typed a decimal point, we need to move the caret
242// past the decimal place.
243if( decimals > 0 && chara == dec_point && start == this.value.length-decimals-1 )
244{
245data.c++;
246data.init = Math.max(0,data.init);
247e.preventDefault();
248
249// Set the selection position.
250setPos = this.value.length+data.c;
251}
252
253// If the user is just typing the decimal place,
254// we simply ignore it.
255else if( chara == dec_point )
256{
257data.init = Math.max(0,data.init);
258e.preventDefault();
259}
260
261// If hitting the delete key, and the cursor is behind a decimal place,
262// we simply move the cursor to the other side of the decimal place.
263else if( decimals > 0 && code == 8 && start == this.value.length-decimals )
264{
265e.preventDefault();
266data.c--;
267
268// Set the selection position.
269setPos = this.value.length+data.c;
270}
271
272// If hitting the delete key, and the cursor is to the right of the decimal
273// (but not directly to the right) we replace the character preceeding the
274// caret with a 0.
275else if( decimals > 0 && code == 8 && start > this.value.length-decimals )
276{
277if( this.value === '' ) return;
278
279// If the character preceeding is not already a 0,
280// replace it with one.
281if( this.value.slice(start-1, start) != '0' )
282{
283val = this.value.slice(0, start-1) + '0' + this.value.slice(start);
284$this.val(val.replace(regex_dec_num,'').replace(regex_dec,dec_point));
285}
286
287e.preventDefault();
288data.c--;
289
290// Set the selection position.
291setPos = this.value.length+data.c;
292}
293
294// If the delete key was pressed, and the character immediately
295// before the caret is a thousands_separator character, simply
296// step over it.
297else if( code == 8 && this.value.slice(start-1, start) == thousands_sep )
298{
299e.preventDefault();
300data.c--;
301
302// Set the selection position.
303setPos = this.value.length+data.c;
304}
305
306// If the caret is to the right of the decimal place, and the user is entering a
307// number, remove the following character before putting in the new one.
308else if(
309decimals > 0 &&
310start == end &&
311this.value.length > decimals+1 &&
312start > this.value.length-decimals-1 && isFinite(+chara) &&
313!e.metaKey && !e.ctrlKey && !e.altKey && chara.length === 1
314)
315{
316// If the character preceeding is not already a 0,
317// replace it with one.
318if( end === this.value.length )
319{
320val = this.value.slice(0, start-1);
321}
322else
323{
324val = this.value.slice(0, start)+this.value.slice(start+1);
325}
326
327// Reset the position.
328this.value = val;
329setPos = start;
330}
331
332// If we need to re-position the characters.
333if( setPos !== false )
334{
335//console.log('Setpos keydown: ', setPos );
336setSelectionRange.apply(this, [setPos, setPos]);
337}
338
339// Store the data on the element.
340$this.data('numFormat', data);
341
342},
343
344/**
345* Handles keyup events, re-formatting numbers.
346*
347* @param object e : the keyup event object.s
348*
349* @return void;
350*/
351'keyup.format' : function(e){
352
353// Store these variables for use below.
354var $this	= $(this),
355data	= $this.data('numFormat'),
356code	= (e.keyCode ? e.keyCode : e.which),
357start	= getSelection.apply(this,['start']),
358setPos;
359
360// Stop executing if the user didn't type a number key, a decimal, or a comma.
361if( this.value === '' || (code < 48 || code > 57) && (code < 96 || code > 105 ) && code !== 8 ) return;
362
363// Re-format the textarea.
364$this.val($this.val());
365
366if( decimals > 0 )
367{
368// If we haven't marked this item as 'initialised'
369// then do so now. It means we should place the caret just
370// before the decimal. This will never be un-initialised before
371// the decimal character itself is entered.
372if( data.init < 1 )
373{
374start	= this.value.length-decimals-( data.init < 0 ? 1 : 0 );
375data.c	= start-this.value.length;
376data.init	= 1;
377
378$this.data('numFormat', data);
379}
380
381// Increase the cursor position if the caret is to the right
382// of the decimal place, and the character pressed isn't the delete key.
383else if( start > this.value.length-decimals && code != 8 )
384{
385data.c++;
386
387// Store the data, now that it's changed.
388$this.data('numFormat', data);
389}
390}
391
392//console.log( 'Setting pos: ', start, decimals, this.value.length + data.c, this.value.length, data.c );
393
394// Set the selection position.
395setPos = this.value.length+data.c;
396setSelectionRange.apply(this, [setPos, setPos]);
397},
398
399/**
400* Reformat when pasting into the field.
401*
402* @param object e : jQuery event object.
403*
404* @return false : prevent default action.
405*/
406'paste.format' : function(e){
407
408// Defint $this. It's used twice!.
409var $this	= $(this),
410original	= e.originalEvent,
411val	= null;
412
413// Get the text content stream.
414if (window.clipboardData && window.clipboardData.getData) { // IE
415val = window.clipboardData.getData('Text');
416} else if (original.clipboardData && original.clipboardData.getData) {
417val = original.clipboardData.getData('text/plain');
418}
419
420// Do the reformat operation.
421$this.val(val);
422
423// Stop the actual content from being pasted.
424e.preventDefault();
425return false;
426}
427
428})
429
430// Loop each element (which isn't blank) and do the format.
431     .each(function(){
432    
433     var $this = $(this).data('numFormat',{
434     c	: -(decimals+1),
435     decimals	: decimals,
436     thousands_sep	: thousands_sep,
437     dec_point	: dec_point,
438     regex_dec_num	: regex_dec_num,
439     regex_dec	: regex_dec,
440     init	: false
441     });
442    
443     // Return if the element is empty.
444     if( this.value === '' ) return;
445    
446     // Otherwise... format!!
447     $this.val($this.val());
448     });
449}
450else
451{
452// return the collection.
453return this.each(function(){
454var $this = $(this), num = +$this.text().replace(regex_dec_num,'').replace(regex_dec,'.');
455$this.number( !isFinite(num) ? 0 : +num, decimals, dec_point, thousands_sep );
456});
457}
458}
459
460// Add this number to the element as text.
461return this.text( $.number.apply(window,arguments) );
462};
463
464//
465// Create .val() hooks to get and set formatted numbers in inputs.
466//
467
468// We check if any hooks already exist, and cache
469// them in case we need to re-use them later on.
470var origHookGet = null, origHookSet = null;
471
472// Check if a text valHook already exists.
473if( $.valHooks.text )
474{
475// Preserve the original valhook function
476// we'll call this for values we're not
477// explicitly handling.
478origHookGet = $.valHooks.text.get;
479origHookSet = $.valHooks.text.set;
480}
481else
482{
483// Define an object for the new valhook.
484$.valHooks.text = {};
485}
486
487/**
488* Define the valHook to return normalised field data against an input
489* which has been tagged by the number formatter.
490*
491* @param object el : The raw DOM element that we're getting the value from.
492*
493* @return mixed : Returns the value that was written to the element as a
494* javascript number, or undefined to let jQuery handle it normally.
495*/
496$.valHooks.text.get = function( el ){
497
498// Get the element, and its data.
499var $this	= $(el), num,
500data	= $this.data('numFormat');
501
502        // Does this element have our data field?
503        if( !data )
504        {
505            // Check if the valhook function already existed
506            if( $.isFunction( origHookGet ) )
507            {
508                // There was, so go ahead and call it
509                return origHookGet(el);
510            }
511            else
512            {
513                // No previous function, return undefined to have jQuery
514                // take care of retrieving the value
515                return undefined;
516}
517}
518else
519{	
520// Remove formatting, and return as number.
521if( el.value === '' ) return '';
522
523// Convert to a number.
524num = +(el.value
525.replace( data.regex_dec_num, '' )
526.replace( data.regex_dec, '.' ));
527
528// If we've got a finite number, return it.
529// Otherwise, simply return 0.
vendor: 3,190 bytes, lines 530-626
530// Return as a string... thats what we're
531// used to with .val()
532return ''+( isFinite( num ) ? num : 0 );
533}
534};
535
536/**
537* A valhook which formats a number when run against an input
538* which has been tagged by the number formatter.
539*
540* @param object el : The raw DOM element (input element).
541* @param float : The number to set into the value field.
542*
543* @return mixed : Returns the value that was written to the element,
544* or undefined to let jQuery handle it normally.
545*/
546$.valHooks.text.set = function( el, val )
547{
548// Get the element, and its data.
549var $this	= $(el),
550data	= $this.data('numFormat');
551
552// Does this element have our data field?
553if( !data )
554{
555// Check if the valhook function already existed
556if( $.isFunction( origHookSet ) )
557{
558// There was, so go ahead and call it
559return origHookSet(el,val);
560}
561else
562{
563// No previous function, return undefined to have jQuery
564// take care of retrieving the value
565return undefined;
566}
567}
568else
569{
570return el.value = $.number( val, data.decimals, data.dec_point, data.thousands_sep )
571}
572};
573
574/**
575* The (modified) excellent number formatting method from PHPJS.org.
576* http://phpjs.org/functions/number_format/
577*
578* @modified by Sam Sehnert (teamdf.com)
579* - don't redefine dec_point, thousands_sep... just overwrite with defaults.
580* - don't redefine decimals, just overwrite as numeric.
581* - Generate regex for normalizing pre-formatted numbers.
582*
583* @param float number : The number you wish to format, or TRUE to use the text contents
584* of the element as the number. Please note that this won't work for
585* elements which have child nodes with text content.
586* @param int decimals : The number of decimal places that should be displayed. Defaults to 0.
587* @param string dec_point : The character to use as a decimal point. Defaults to '.'.
588* @param string thousands_sep : The character to use as a thousands separator. Defaults to ','.
589*
590* @return string : The formatted number as a string.
591*/
592$.number = function( number, decimals, dec_point, thousands_sep ){
593
594// Set the default values here, instead so we can use them in the replace below.
595thousands_sep	= (typeof thousands_sep === 'undefined') ? ',' : thousands_sep;
596dec_point	= (typeof dec_point === 'undefined') ? '.' : dec_point;
597decimals	= !isFinite(+decimals) ? 0 : Math.abs(decimals);
598
599// Work out the unicode representation for the decimal place.
600var u_dec = ('\\u'+('0000'+(dec_point.charCodeAt(0).toString(16))).slice(-4));
601
602// Fix the number, so that it's an actual number.
603number = (number + '')
604.replace(new RegExp(u_dec,'g'),'.')
605.replace(new RegExp('[^0-9+\-Ee.]','g'),'');
606
607var n = !isFinite(+number) ? 0 : +number,
608s = '',
609toFixedFix = function (n, decimals) {
610var k = Math.pow(10, decimals);
611return '' + Math.round(n * k) / k;
612};
613
614// Fix for IE parseFloat(0.55).toFixed(0) = 0;
615s = (decimals ? toFixedFix(n, decimals) : '' + Math.round(n)).split('.');
616if (s[0].length > 3) {
617s[0] = s[0].replace(/\B(?=(?:\d{3})+(?!\d))/g, thousands_sep);
618}
619if ((s[1] || '').length < decimals) {
620s[1] = s[1] || '';
621s[1] += new Array(decimals - s[1].length + 1).join('0');
622}
623return s.join(dec_point);
624}
625
626})(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.