]>
git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/static/AdminLTE-2.3.7/plugins/input-mask/jquery.inputmask.numeric.extensions.js
2 Input Mask plugin extensions
3 http://github.com/RobinHerbots/jquery.inputmask
4 Copyright (c) 2010 - 2014 Robin Herbots
5 Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
8 Optional extensions on the jquery.inputmask base
12 $.extend($.inputmask
.defaults
.aliases
, {
20 digits
: "*", //number of fractionalDigits
21 groupSeparator
: "",//",", // | "."
28 integerDigits
: "*", //number of integerDigits
34 getMaskLength: function (buffer
, greedy
, repeat
, currentBuffer
, opts
) { //custom getMaskLength to take the groupSeparator into account
35 var calculatedLength
= buffer
.length
;
39 calculatedLength
= currentBuffer
.length
+ 1;
40 } else if (repeat
> 1) {
41 calculatedLength
+= (buffer
.length
* (repeat
- 1));
45 var escapedGroupSeparator
= $.inputmask
.escapeRegex
.call(this, opts
.groupSeparator
);
46 var escapedRadixPoint
= $.inputmask
.escapeRegex
.call(this, opts
.radixPoint
);
47 var currentBufferStr
= currentBuffer
.join(''), strippedBufferStr
= currentBufferStr
.replace(new RegExp(escapedGroupSeparator
, "g"), "").replace(new RegExp(escapedRadixPoint
), ""),
48 groupOffset
= currentBufferStr
.length
- strippedBufferStr
.length
;
49 return calculatedLength
+ groupOffset
;
51 postFormat: function (buffer
, pos
, reformatOnly
, opts
) {
52 if (opts
.groupSeparator
== "") return pos
;
53 var cbuf
= buffer
.slice(),
54 radixPos
= $.inArray(opts
.radixPoint
, buffer
);
56 cbuf
.splice(pos
, 0, "?"); //set position indicator
58 var bufVal
= cbuf
.join('');
59 if (opts
.autoGroup
|| (reformatOnly
&& bufVal
.indexOf(opts
.groupSeparator
) != -1)) {
60 var escapedGroupSeparator
= $.inputmask
.escapeRegex
.call(this, opts
.groupSeparator
);
61 bufVal
= bufVal
.replace(new RegExp(escapedGroupSeparator
, "g"), '');
62 var radixSplit
= bufVal
.split(opts
.radixPoint
);
63 bufVal
= radixSplit
[0];
64 var reg
= new RegExp('([-\+]?[\\d\?]+)([\\d\?]{' + opts
.groupSize
+ '})');
65 while (reg
.test(bufVal
)) {
66 bufVal
= bufVal
.replace(reg
, '$1' + opts
.groupSeparator
+ '$2');
67 bufVal
= bufVal
.replace(opts
.groupSeparator
+ opts
.groupSeparator
, opts
.groupSeparator
);
69 if (radixSplit
.length
> 1)
70 bufVal
+= opts
.radixPoint
+ radixSplit
[1];
72 buffer
.length
= bufVal
.length
; //align the length
73 for (var i
= 0, l
= bufVal
.length
; i
< l
; i
++) {
74 buffer
[i
] = bufVal
.charAt(i
);
76 var newPos
= $.inArray("?", buffer
);
77 if (!reformatOnly
) buffer
.splice(newPos
, 1);
79 return reformatOnly
? pos
: newPos
;
82 number: function (opts
) {
83 var escapedGroupSeparator
= $.inputmask
.escapeRegex
.call(this, opts
.groupSeparator
);
84 var escapedRadixPoint
= $.inputmask
.escapeRegex
.call(this, opts
.radixPoint
);
85 var digitExpression
= isNaN(opts
.digits
) ? opts
.digits
: '{0,' + opts
.digits
+ '}';
86 var signedExpression
= opts
.allowPlus
|| opts
.allowMinus
? "[" + (opts
.allowPlus
? "\+" : "") + (opts
.allowMinus
? "-" : "") + "]?" : "";
87 return new RegExp("^" + signedExpression
+ "(\\d+|\\d{1," + opts
.groupSize
+ "}((" + escapedGroupSeparator
+ "\\d{" + opts
.groupSize
+ "})?)+)(" + escapedRadixPoint
+ "\\d" + digitExpression
+ ")?$");
90 onKeyDown: function (e
, buffer
, opts
) {
91 var $input
= $(this), input
= this;
92 if (e
.keyCode
== opts
.keyCode
.TAB
) {
93 var radixPosition
= $.inArray(opts
.radixPoint
, buffer
);
94 if (radixPosition
!= -1) {
95 var masksets
= $input
.data('_inputmask')['masksets'];
96 var activeMasksetIndex
= $input
.data('_inputmask')['activeMasksetIndex'];
97 for (var i
= 1; i
<= opts
.digits
&& i
< opts
.getMaskLength(masksets
[activeMasksetIndex
]["_buffer"], masksets
[activeMasksetIndex
]["greedy"], masksets
[activeMasksetIndex
]["repeat"], buffer
, opts
) ; i
++) {
98 if (buffer
[radixPosition
+ i
] == undefined || buffer
[radixPosition
+ i
] == "") buffer
[radixPosition
+ i
] = "0";
100 input
._valueSet(buffer
.join(''));
102 } else if (e
.keyCode
== opts
.keyCode
.DELETE
|| e
.keyCode
== opts
.keyCode
.BACKSPACE
) {
103 opts
.postFormat(buffer
, 0, true, opts
);
104 input
._valueSet(buffer
.join(''));
110 validator: function (chrs
, buffer
, pos
, strict
, opts
) {
111 if (chrs
== "") return false;
112 if (!strict
&& pos
<= 1 && buffer
[0] === '0' && new RegExp("[\\d-]").test(chrs
) && buffer
.join('').length
== 1) { //handle first char
117 var cbuf
= strict
? buffer
.slice(0, pos
) : buffer
.slice();
119 cbuf
.splice(pos
, 0, chrs
);
120 var bufferStr
= cbuf
.join('');
122 //strip groupseparator
123 var escapedGroupSeparator
= $.inputmask
.escapeRegex
.call(this, opts
.groupSeparator
);
124 bufferStr
= bufferStr
.replace(new RegExp(escapedGroupSeparator
, "g"), '');
126 var isValid
= opts
.regex
.number(opts
).test(bufferStr
);
128 //let's help the regex a bit
130 isValid
= opts
.regex
.number(opts
).test(bufferStr
);
133 var lastGroupSeparator
= bufferStr
.lastIndexOf(opts
.groupSeparator
);
134 for (var i
= bufferStr
.length
- lastGroupSeparator
; i
<= 3; i
++) {
138 isValid
= opts
.regex
.number(opts
).test(bufferStr
);
139 if (!isValid
&& !strict
) {
140 if (chrs
== opts
.radixPoint
) {
141 isValid
= opts
.regex
.number(opts
).test("0" + bufferStr
+ "0");
145 return { "pos": pos
};
152 if (isValid
!= false && !strict
&& chrs
!= opts
.radixPoint
) {
153 var newPos
= opts
.postFormat(buffer
, pos
, false, opts
);
154 return { "pos": newPos
};
168 number: function (opts
) {
169 var escapedGroupSeparator
= $.inputmask
.escapeRegex
.call(this, opts
.groupSeparator
);
170 var signedExpression
= opts
.allowPlus
|| opts
.allowMinus
? "[" + (opts
.allowPlus
? "\+" : "") + (opts
.allowMinus
? "-" : "") + "]?" : "";
171 return new RegExp("^" + signedExpression
+ "(\\d+|\\d{1," + opts
.groupSize
+ "}((" + escapedGroupSeparator
+ "\\d{" + opts
.groupSize
+ "})?)+)$");