use-mask-input 1.0.2 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/example/App.example.d.ts +3 -0
- package/dist/{useMaskInput.test.d.ts → example/index.d.ts} +0 -0
- package/dist/index.js +1 -2
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +1 -2
- package/dist/index.modern.js.map +1 -1
- package/dist/useMaskInput.d.ts +3 -3
- package/node_modules/inputmask/README.md +94 -61
- package/node_modules/inputmask/dist/inputmask.es6.js +5 -0
- package/node_modules/inputmask/dist/inputmask.js +2900 -2868
- package/node_modules/inputmask/dist/inputmask.min.js +3 -3
- package/node_modules/inputmask/dist/jquery.inputmask.js +2840 -2807
- package/node_modules/inputmask/dist/jquery.inputmask.min.js +3 -3
- package/node_modules/inputmask/lib/bindings/inputmask.es6.js +5 -0
- package/node_modules/inputmask/lib/canUseDOM.js +7 -0
- package/node_modules/inputmask/lib/defaults.js +36 -2
- package/node_modules/inputmask/lib/definitions.js +1 -1
- package/node_modules/inputmask/lib/dependencyLibs/events.js +19 -9
- package/node_modules/inputmask/lib/environment.js +2 -0
- package/node_modules/inputmask/lib/eventhandlers.js +55 -44
- package/node_modules/inputmask/lib/eventruler.js +10 -9
- package/node_modules/inputmask/lib/extensions/inputmask.date.extensions.js +543 -430
- package/node_modules/inputmask/lib/extensions/inputmask.extensions.js +117 -99
- package/node_modules/inputmask/lib/extensions/inputmask.numeric.extensions.js +590 -574
- package/node_modules/inputmask/lib/global/window.js +2 -1
- package/node_modules/inputmask/lib/inputHandling.js +30 -18
- package/node_modules/inputmask/lib/inputmask.js +9 -2
- package/node_modules/inputmask/lib/inputmaskElement.js +2 -1
- package/node_modules/inputmask/lib/keycode.json +4 -0
- package/node_modules/inputmask/lib/mask-lexer.js +434 -436
- package/node_modules/inputmask/lib/mask.js +4 -4
- package/node_modules/inputmask/lib/masktoken.js +13 -0
- package/node_modules/inputmask/lib/polyfills/Array.includes.js +48 -0
- package/node_modules/inputmask/lib/{getPrototypeOf.js → polyfills/Object.getPrototypeOf.js} +0 -0
- package/node_modules/inputmask/lib/positioning.js +5 -5
- package/node_modules/inputmask/lib/validation-tests.js +108 -46
- package/node_modules/inputmask/lib/validation.js +82 -73
- package/node_modules/inputmask/package.json +41 -69
- package/package.json +40 -38
- package/node_modules/inputmask/CHANGELOG.md +0 -744
- package/node_modules/inputmask/index.js +0 -1
- package/node_modules/inputmask/lib/dependencyLibs/inputmask.dependencyLib.jqlite.js +0 -20
|
@@ -7,609 +7,625 @@
|
|
|
7
7
|
import Inputmask from "../inputmask";
|
|
8
8
|
import keyCode from "../keycode.json";
|
|
9
9
|
import escapeRegex from "../escapeRegex";
|
|
10
|
+
import {seekNext} from "../positioning";
|
|
10
11
|
|
|
11
12
|
const $ = Inputmask.dependencyLib;
|
|
12
13
|
|
|
13
14
|
function autoEscape(txt, opts) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
15
|
+
var escapedTxt = "";
|
|
16
|
+
for (var i = 0; i < txt.length; i++) {
|
|
17
|
+
if (Inputmask.prototype.definitions[txt.charAt(i)] ||
|
|
18
|
+
opts.definitions[txt.charAt(i)] ||
|
|
19
|
+
opts.optionalmarker[0] === txt.charAt(i) ||
|
|
20
|
+
opts.optionalmarker[1] === txt.charAt(i) ||
|
|
21
|
+
opts.quantifiermarker[0] === txt.charAt(i) ||
|
|
22
|
+
opts.quantifiermarker[1] === txt.charAt(i) ||
|
|
23
|
+
opts.groupmarker[0] === txt.charAt(i) ||
|
|
24
|
+
opts.groupmarker[1] === txt.charAt(i) ||
|
|
25
|
+
opts.alternatormarker === txt.charAt(i)) {
|
|
26
|
+
escapedTxt += "\\" + txt.charAt(i);
|
|
27
|
+
} else {
|
|
28
|
+
escapedTxt += txt.charAt(i);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return escapedTxt;
|
|
31
32
|
}
|
|
32
33
|
|
|
33
34
|
function alignDigits(buffer, digits, opts, force) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
35
|
+
if (buffer.length > 0 && digits > 0 && (!opts.digitsOptional || force)) {
|
|
36
|
+
var radixPosition = buffer.indexOf(opts.radixPoint), negationBack = false;
|
|
37
|
+
if (opts.negationSymbol.back === buffer[buffer.length - 1]) {
|
|
38
|
+
negationBack = true;
|
|
39
|
+
buffer.length--;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (radixPosition === -1) {
|
|
43
|
+
buffer.push(opts.radixPoint);
|
|
44
|
+
radixPosition = buffer.length - 1;
|
|
45
|
+
}
|
|
46
|
+
for (var i = 1; i <= digits; i++) {
|
|
47
|
+
if (!isFinite(buffer[radixPosition + i])) {
|
|
48
|
+
buffer[radixPosition + i] = "0";
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (negationBack)
|
|
54
|
+
buffer.push(opts.negationSymbol.back);
|
|
55
|
+
return buffer;
|
|
55
56
|
}
|
|
56
57
|
|
|
57
58
|
function findValidator(symbol, maskset) {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
59
|
+
var posNdx = 0;
|
|
60
|
+
if (symbol === "+") {
|
|
61
|
+
for (posNdx in maskset.validPositions) ;
|
|
62
|
+
posNdx = seekNext.call(this, parseInt(posNdx));
|
|
63
|
+
}
|
|
64
|
+
for (var tstNdx in maskset.tests) {
|
|
65
|
+
tstNdx = parseInt(tstNdx);
|
|
66
|
+
if (tstNdx >= posNdx) {
|
|
67
|
+
for (var ndx = 0, ndxl = maskset.tests[tstNdx].length; ndx < ndxl; ndx++) {
|
|
68
|
+
if ((maskset.validPositions[tstNdx] === undefined || symbol === "-") && maskset.tests[tstNdx][ndx].match.def === symbol) {
|
|
69
|
+
return tstNdx + ((maskset.validPositions[tstNdx] !== undefined && symbol !== "-") ? 1 : 0);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return posNdx;
|
|
74
75
|
}
|
|
75
76
|
|
|
76
77
|
function findValid(symbol, maskset) {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
78
|
+
var ret = -1;
|
|
79
|
+
for (let ndx in maskset.validPositions) {
|
|
80
|
+
let tst = maskset.validPositions[ndx];
|
|
81
|
+
if (tst && tst.match.def === symbol) {
|
|
82
|
+
ret = parseInt(ndx);
|
|
83
|
+
break;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return ret;
|
|
86
87
|
}
|
|
87
88
|
|
|
88
89
|
function parseMinMaxOptions(opts) {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
90
|
+
if (opts.parseMinMaxOptions === undefined) {
|
|
91
|
+
// convert min and max options
|
|
92
|
+
if (opts.min !== null) {
|
|
93
|
+
opts.min = opts.min.toString().replace(new RegExp(escapeRegex(opts.groupSeparator), "g"), "");
|
|
94
|
+
if (opts.radixPoint === ",") opts.min = opts.min.replace(opts.radixPoint, ".");
|
|
95
|
+
opts.min = isFinite(opts.min) ? parseFloat(opts.min) : NaN;
|
|
96
|
+
if (isNaN(opts.min)) opts.min = Number.MIN_VALUE;
|
|
97
|
+
}
|
|
98
|
+
if (opts.max !== null) {
|
|
99
|
+
opts.max = opts.max.toString().replace(new RegExp(escapeRegex(opts.groupSeparator), "g"), "");
|
|
100
|
+
if (opts.radixPoint === ",") opts.max = opts.max.replace(opts.radixPoint, ".");
|
|
101
|
+
opts.max = isFinite(opts.max) ? parseFloat(opts.max) : NaN;
|
|
102
|
+
if (isNaN(opts.max)) opts.max = Number.MAX_VALUE;
|
|
103
|
+
}
|
|
104
|
+
opts.parseMinMaxOptions = "done";
|
|
105
|
+
}
|
|
105
106
|
}
|
|
106
107
|
|
|
107
108
|
function genMask(opts) {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
109
|
+
opts.repeat = 0;
|
|
110
|
+
//treat equal separator and radixpoint
|
|
111
|
+
if (opts.groupSeparator === opts.radixPoint && opts.digits && opts.digits !== "0") {
|
|
112
|
+
if (opts.radixPoint === ".") {
|
|
113
|
+
opts.groupSeparator = ",";
|
|
114
|
+
} else if (opts.radixPoint === ",") {
|
|
115
|
+
opts.groupSeparator = ".";
|
|
116
|
+
} else {
|
|
117
|
+
opts.groupSeparator = "";
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
//prevent conflict with default skipOptionalPartCharacter
|
|
121
|
+
if (opts.groupSeparator === " ") {
|
|
122
|
+
opts.skipOptionalPartCharacter = undefined;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
//enforce placeholder to single
|
|
126
|
+
if (opts.placeholder.length > 1) {
|
|
127
|
+
opts.placeholder = opts.placeholder.charAt(0);
|
|
128
|
+
}
|
|
129
|
+
//only allow radixfocus when placeholder = 0
|
|
130
|
+
if (opts.positionCaretOnClick === "radixFocus" && opts.placeholder === "") {
|
|
131
|
+
opts.positionCaretOnClick = "lvp";
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
var decimalDef = "0", radixPointDef = opts.radixPoint;
|
|
135
|
+
if (opts.numericInput === true && opts.__financeInput === undefined) { //finance people input style
|
|
136
|
+
decimalDef = "1";
|
|
137
|
+
opts.positionCaretOnClick = opts.positionCaretOnClick === "radixFocus" ? "lvp" : opts.positionCaretOnClick;
|
|
138
|
+
opts.digitsOptional = false;
|
|
139
|
+
if (isNaN(opts.digits)) opts.digits = 2;
|
|
140
|
+
opts._radixDance = false;
|
|
141
|
+
radixPointDef = (opts.radixPoint === "," ? "?" : "!");
|
|
142
|
+
if (opts.radixPoint !== "" && opts.definitions[radixPointDef] === undefined) {
|
|
143
|
+
//update separator definition
|
|
144
|
+
opts.definitions[radixPointDef] = {};
|
|
145
|
+
opts.definitions[radixPointDef].validator = "[" + opts.radixPoint + "]";
|
|
146
|
+
opts.definitions[radixPointDef].placeholder = opts.radixPoint;
|
|
147
|
+
opts.definitions[radixPointDef].static = true;
|
|
148
|
+
opts.definitions[radixPointDef].generated = true; //forced marker as generated input
|
|
149
|
+
}
|
|
150
|
+
} else {
|
|
151
|
+
opts.__financeInput = false; //needed to keep original selection when remasking
|
|
152
|
+
opts.numericInput = true;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
var mask = "[+]", altMask;
|
|
156
|
+
mask += autoEscape(opts.prefix, opts);
|
|
157
|
+
if (opts.groupSeparator !== "") {
|
|
158
|
+
if (opts.definitions[opts.groupSeparator] === undefined) {
|
|
159
|
+
//update separatot definition
|
|
160
|
+
opts.definitions[opts.groupSeparator] = {};
|
|
161
|
+
opts.definitions[opts.groupSeparator].validator = "[" + opts.groupSeparator + "]";
|
|
162
|
+
opts.definitions[opts.groupSeparator].placeholder = opts.groupSeparator;
|
|
163
|
+
opts.definitions[opts.groupSeparator].static = true;
|
|
164
|
+
opts.definitions[opts.groupSeparator].generated = true; //forced marker as generated input
|
|
165
|
+
}
|
|
166
|
+
mask += opts._mask(opts);
|
|
167
|
+
} else {
|
|
168
|
+
mask += "9{+}";
|
|
169
|
+
}
|
|
170
|
+
if (opts.digits !== undefined && opts.digits !== 0) {
|
|
171
|
+
var dq = opts.digits.toString().split(",");
|
|
172
|
+
if (isFinite(dq[0]) && dq[1] && isFinite(dq[1])) {
|
|
173
|
+
mask += radixPointDef + decimalDef + "{" + opts.digits + "}";
|
|
174
|
+
} else if (isNaN(opts.digits) || parseInt(opts.digits) > 0) {
|
|
175
|
+
if (opts.digitsOptional || opts.jitMasking) {
|
|
176
|
+
altMask = mask + radixPointDef + decimalDef + "{0," + opts.digits + "}";
|
|
177
|
+
// mask += "[" + opts.radixPoint + "]";
|
|
178
|
+
opts.keepStatic = true;
|
|
179
|
+
} else {
|
|
180
|
+
mask += radixPointDef + decimalDef + "{" + opts.digits + "}";
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
} else {
|
|
184
|
+
opts.inputmode = "numeric";
|
|
185
|
+
}
|
|
186
|
+
mask += autoEscape(opts.suffix, opts);
|
|
187
|
+
mask += "[-]";
|
|
188
|
+
|
|
189
|
+
if (altMask) {
|
|
190
|
+
mask = [(altMask + autoEscape(opts.suffix, opts) + "[-]"), mask];
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
opts.greedy = false; //enforce greedy false
|
|
195
|
+
|
|
196
|
+
parseMinMaxOptions(opts);
|
|
197
|
+
if (opts.radixPoint !== "")
|
|
198
|
+
opts.substitutes[opts.radixPoint == "." ? "," : "."] = opts.radixPoint;
|
|
199
|
+
// console.log(mask);
|
|
200
|
+
return mask;
|
|
197
201
|
}
|
|
198
202
|
|
|
199
203
|
function hanndleRadixDance(pos, c, radixPos, maskset, opts) {
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
204
|
+
if (opts._radixDance && opts.numericInput && c !== opts.negationSymbol.back) {
|
|
205
|
+
if (pos <= radixPos && (radixPos > 0 || c == opts.radixPoint) && (maskset.validPositions[pos - 1] === undefined || maskset.validPositions[pos - 1].input !== opts.negationSymbol.back)) {
|
|
206
|
+
pos -= 1;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
return pos;
|
|
206
210
|
}
|
|
207
211
|
|
|
208
212
|
function decimalValidator(chrs, maskset, pos, strict, opts) {
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
213
|
+
var radixPos = maskset.buffer ? maskset.buffer.indexOf(opts.radixPoint) : -1,
|
|
214
|
+
result = (radixPos !== -1 || (strict && opts.jitMasking)) && new RegExp(opts.definitions["9"].validator).test(chrs);
|
|
215
|
+
if (opts._radixDance && radixPos !== -1 && result && maskset.validPositions[radixPos] == undefined) {
|
|
216
|
+
return {
|
|
217
|
+
insert: {
|
|
218
|
+
pos: radixPos === pos ? radixPos + 1 : radixPos,
|
|
219
|
+
c: opts.radixPoint
|
|
220
|
+
},
|
|
221
|
+
pos: pos
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
return result;
|
|
222
226
|
}
|
|
223
227
|
|
|
224
228
|
function checkForLeadingZeroes(buffer, opts) {
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
229
|
+
//check leading zeros
|
|
230
|
+
var numberMatches = new RegExp("(^" + (opts.negationSymbol.front !== "" ? escapeRegex(opts.negationSymbol.front) + "?" : "") + escapeRegex(opts.prefix) + ")(.*)(" + escapeRegex(opts.suffix) + (opts.negationSymbol.back != "" ? escapeRegex(opts.negationSymbol.back) + "?" : "") + "$)").exec(buffer.slice().reverse().join("")),
|
|
231
|
+
number = numberMatches ? numberMatches[2] : "", leadingzeroes = false;
|
|
232
|
+
if (number) {
|
|
233
|
+
number = number.split(opts.radixPoint.charAt(0))[0];
|
|
234
|
+
leadingzeroes = new RegExp("^[0" + opts.groupSeparator + "]*").exec(number);
|
|
235
|
+
}
|
|
236
|
+
return leadingzeroes && (leadingzeroes[0].length > 1 || leadingzeroes[0].length > 0 && leadingzeroes[0].length < number.length) ? leadingzeroes : false;
|
|
233
237
|
}
|
|
234
238
|
|
|
235
239
|
//number aliases
|
|
236
240
|
Inputmask.extendAliases({
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
}
|
|
241
|
+
"numeric": {
|
|
242
|
+
mask: genMask,
|
|
243
|
+
_mask: function (opts) {
|
|
244
|
+
return "(" + opts.groupSeparator + "999){+|1}";
|
|
245
|
+
},
|
|
246
|
+
digits: "*", //number of fractionalDigits
|
|
247
|
+
digitsOptional: true,
|
|
248
|
+
enforceDigitsOnBlur: false,
|
|
249
|
+
radixPoint: ".",
|
|
250
|
+
positionCaretOnClick: "radixFocus",
|
|
251
|
+
_radixDance: true,
|
|
252
|
+
groupSeparator: "",
|
|
253
|
+
allowMinus: true,
|
|
254
|
+
negationSymbol: {
|
|
255
|
+
front: "-", //"("
|
|
256
|
+
back: "" //")"
|
|
257
|
+
},
|
|
258
|
+
prefix: "",
|
|
259
|
+
suffix: "",
|
|
260
|
+
min: null, //minimum value
|
|
261
|
+
max: null, //maximum value
|
|
262
|
+
SetMaxOnOverflow: false,
|
|
263
|
+
step: 1,
|
|
264
|
+
inputType: "text", //number ~ specify that values which are set are in textform (radix point is same as in the options) or in numberform (radixpoint = .)
|
|
265
|
+
unmaskAsNumber: false,
|
|
266
|
+
roundingFN: Math.round, //Math.floor , fn(x)
|
|
267
|
+
inputmode: "decimal",
|
|
268
|
+
shortcuts: {k: "1000", m: "1000000"},
|
|
269
|
+
//global options
|
|
270
|
+
placeholder: "0",
|
|
271
|
+
greedy: false,
|
|
272
|
+
rightAlign: true,
|
|
273
|
+
insertMode: true,
|
|
274
|
+
autoUnmask: false,
|
|
275
|
+
skipOptionalPartCharacter: "",
|
|
276
|
+
usePrototypeDefinitions: false,
|
|
277
|
+
stripLeadingZeroes: true,
|
|
278
|
+
definitions: {
|
|
279
|
+
"0": {
|
|
280
|
+
validator: decimalValidator
|
|
281
|
+
},
|
|
282
|
+
"1": {
|
|
283
|
+
validator: decimalValidator,
|
|
284
|
+
definitionSymbol: "9"
|
|
285
|
+
},
|
|
286
|
+
"9": { //\uFF11-\uFF19 #1606
|
|
287
|
+
validator: "[0-9\uFF10-\uFF19\u0660-\u0669\u06F0-\u06F9]",
|
|
288
|
+
definitionSymbol: "*"
|
|
289
|
+
},
|
|
290
|
+
"+": {
|
|
291
|
+
validator: function (chrs, maskset, pos, strict, opts) {
|
|
292
|
+
return (opts.allowMinus && (chrs === "-" || chrs === opts.negationSymbol.front));
|
|
293
|
+
|
|
294
|
+
}
|
|
295
|
+
},
|
|
296
|
+
"-": {
|
|
297
|
+
validator: function (chrs, maskset, pos, strict, opts) {
|
|
298
|
+
return (opts.allowMinus && chrs === opts.negationSymbol.back);
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
},
|
|
302
|
+
preValidation: function (buffer, pos, c, isSelection, opts, maskset, caretPos, strict) {
|
|
303
|
+
const inputmask = this;
|
|
304
|
+
|
|
305
|
+
if (opts.__financeInput !== false && c === opts.radixPoint) return false;
|
|
306
|
+
var radixPos = buffer.indexOf(opts.radixPoint), initPos = pos;
|
|
307
|
+
pos = hanndleRadixDance(pos, c, radixPos, maskset, opts);
|
|
308
|
+
if (c === "-" || c === opts.negationSymbol.front) {
|
|
309
|
+
if (opts.allowMinus !== true) return false;
|
|
310
|
+
var isNegative = false,
|
|
311
|
+
front = findValid("+", maskset), back = findValid("-", maskset);
|
|
312
|
+
if (front !== -1) {
|
|
313
|
+
isNegative = [front, back];
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
return isNegative !== false ? {
|
|
317
|
+
remove: isNegative,
|
|
318
|
+
caret: initPos - opts.negationSymbol.back.length
|
|
319
|
+
} : {
|
|
320
|
+
insert: [
|
|
321
|
+
{
|
|
322
|
+
pos: findValidator.call(inputmask, "+", maskset),
|
|
323
|
+
c: opts.negationSymbol.front,
|
|
324
|
+
fromIsValid: true
|
|
325
|
+
},
|
|
326
|
+
{
|
|
327
|
+
pos: findValidator.call(inputmask, "-", maskset),
|
|
328
|
+
c: opts.negationSymbol.back,
|
|
329
|
+
fromIsValid: undefined
|
|
330
|
+
}],
|
|
331
|
+
caret: initPos + opts.negationSymbol.back.length
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
if (c === opts.groupSeparator) {
|
|
336
|
+
return {caret: initPos};
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
if (strict) return true;
|
|
340
|
+
if (radixPos !== -1 && (opts._radixDance === true && isSelection === false && c === opts.radixPoint && (opts.digits !== undefined && (isNaN(opts.digits) || parseInt(opts.digits) > 0)) && radixPos !== pos)) {
|
|
341
|
+
return {
|
|
342
|
+
"caret": opts._radixDance && pos === radixPos - 1 ? radixPos + 1 : radixPos
|
|
343
|
+
};
|
|
344
|
+
}
|
|
345
|
+
if (opts.__financeInput === false) {
|
|
346
|
+
if (isSelection) {
|
|
347
|
+
if (opts.digitsOptional) {
|
|
348
|
+
return {rewritePosition: caretPos.end};
|
|
349
|
+
} else if (!opts.digitsOptional) {
|
|
350
|
+
if (caretPos.begin > radixPos && caretPos.end <= radixPos) {
|
|
351
|
+
if (c === opts.radixPoint) {
|
|
352
|
+
return {
|
|
353
|
+
insert: {pos: radixPos + 1, c: "0", fromIsValid: true},
|
|
354
|
+
rewritePosition: radixPos
|
|
355
|
+
};
|
|
356
|
+
} else {
|
|
357
|
+
return {rewritePosition: radixPos + 1};
|
|
358
|
+
}
|
|
359
|
+
} else if (caretPos.begin < radixPos) {
|
|
360
|
+
return {rewritePosition: caretPos.begin - 1};
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
} else if (!opts.showMaskOnHover && !opts.showMaskOnFocus && !opts.digitsOptional && opts.digits > 0 && this.__valueGet.call(this.el) === "") {
|
|
364
|
+
return {rewritePosition: radixPos};
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
return {rewritePosition: pos};
|
|
368
|
+
},
|
|
369
|
+
postValidation: function (buffer, pos, c, currentResult, opts, maskset, strict) {
|
|
370
|
+
if (currentResult === false) return currentResult;
|
|
371
|
+
if (strict) return true;
|
|
372
|
+
if (opts.min !== null || opts.max !== null) {
|
|
373
|
+
var unmasked = opts.onUnMask(buffer.slice().reverse().join(""), undefined, $.extend({}, opts, {
|
|
374
|
+
unmaskAsNumber: true
|
|
375
|
+
}));
|
|
376
|
+
if (opts.min !== null && unmasked < opts.min && (unmasked.toString().length > opts.min.toString().length || unmasked < 0)) {
|
|
377
|
+
return false;
|
|
378
|
+
// return {
|
|
379
|
+
// refreshFromBuffer: true,
|
|
380
|
+
// buffer: alignDigits(opts.min.toString().replace(".", opts.radixPoint).split(""), opts.digits, opts).reverse()
|
|
381
|
+
// };
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
if (opts.max !== null && unmasked > opts.max) {
|
|
385
|
+
return opts.SetMaxOnOverflow ? {
|
|
386
|
+
refreshFromBuffer: true,
|
|
387
|
+
buffer: alignDigits(opts.max.toString().replace(".", opts.radixPoint).split(""), opts.digits, opts).reverse()
|
|
388
|
+
} : false;
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
return currentResult;
|
|
393
|
+
},
|
|
394
|
+
onUnMask: function (maskedValue, unmaskedValue, opts) {
|
|
395
|
+
if (unmaskedValue === "" && opts.nullable === true) {
|
|
396
|
+
return unmaskedValue;
|
|
397
|
+
}
|
|
398
|
+
var processValue = maskedValue.replace(opts.prefix, "");
|
|
399
|
+
processValue = processValue.replace(opts.suffix, "");
|
|
400
|
+
processValue = processValue.replace(new RegExp(escapeRegex(opts.groupSeparator), "g"), "");
|
|
401
|
+
if (opts.placeholder.charAt(0) !== "") {
|
|
402
|
+
processValue = processValue.replace(new RegExp(opts.placeholder.charAt(0), "g"), "0");
|
|
403
|
+
}
|
|
404
|
+
if (opts.unmaskAsNumber) {
|
|
405
|
+
if (opts.radixPoint !== "" && processValue.indexOf(opts.radixPoint) !== -1) processValue = processValue.replace(escapeRegex.call(this, opts.radixPoint), ".");
|
|
406
|
+
processValue = processValue.replace(new RegExp("^" + escapeRegex(opts.negationSymbol.front)), "-");
|
|
407
|
+
processValue = processValue.replace(new RegExp(escapeRegex(opts.negationSymbol.back) + "$"), "");
|
|
408
|
+
return Number(processValue);
|
|
409
|
+
}
|
|
410
|
+
return processValue;
|
|
411
|
+
}
|
|
412
|
+
,
|
|
413
|
+
isComplete: function (buffer, opts) {
|
|
414
|
+
var maskedValue = (opts.numericInput ? buffer.slice().reverse() : buffer).join("");
|
|
415
|
+
maskedValue = maskedValue.replace(new RegExp("^" + escapeRegex(opts.negationSymbol.front)), "-");
|
|
416
|
+
maskedValue = maskedValue.replace(new RegExp(escapeRegex(opts.negationSymbol.back) + "$"), "");
|
|
417
|
+
maskedValue = maskedValue.replace(opts.prefix, "");
|
|
418
|
+
maskedValue = maskedValue.replace(opts.suffix, "");
|
|
419
|
+
maskedValue = maskedValue.replace(new RegExp(escapeRegex(opts.groupSeparator) + "([0-9]{3})", "g"), "$1");
|
|
420
|
+
if (opts.radixPoint === ",") maskedValue = maskedValue.replace(escapeRegex(opts.radixPoint), ".");
|
|
421
|
+
return isFinite(maskedValue);
|
|
422
|
+
},
|
|
423
|
+
onBeforeMask: function (initialValue, opts) {
|
|
424
|
+
var radixPoint = opts.radixPoint || ",";
|
|
425
|
+
if (isFinite(opts.digits)) opts.digits = parseInt(opts.digits);
|
|
426
|
+
|
|
427
|
+
if ((typeof initialValue == "number" || opts.inputType === "number") && radixPoint !== "") {
|
|
428
|
+
initialValue = initialValue.toString().replace(".", radixPoint);
|
|
429
|
+
}
|
|
430
|
+
var isNagtive = initialValue.charAt(0) === "-" || initialValue.charAt(0) === opts.negationSymbol.front;
|
|
431
|
+
var valueParts = initialValue.split(radixPoint),
|
|
432
|
+
integerPart = valueParts[0].replace(/[^\-0-9]/g, ""),
|
|
433
|
+
decimalPart = valueParts.length > 1 ? valueParts[1].replace(/[^0-9]/g, "") : "",
|
|
434
|
+
forceDigits = valueParts.length > 1;
|
|
435
|
+
|
|
436
|
+
initialValue = integerPart + (decimalPart !== "" ? radixPoint + decimalPart : decimalPart);
|
|
437
|
+
|
|
438
|
+
var digits = 0;
|
|
439
|
+
if (radixPoint !== "") {
|
|
440
|
+
digits = !opts.digitsOptional ? opts.digits : (opts.digits < decimalPart.length ? opts.digits : decimalPart.length);
|
|
441
|
+
if (decimalPart !== "" || !opts.digitsOptional) {
|
|
442
|
+
var digitsFactor = Math.pow(10, digits || 1);
|
|
443
|
+
|
|
444
|
+
//make the initialValue a valid javascript number for the parsefloat
|
|
445
|
+
initialValue = initialValue.replace(escapeRegex(radixPoint), ".");
|
|
446
|
+
if (!isNaN(parseFloat(initialValue))) {
|
|
447
|
+
initialValue = (opts.roundingFN(parseFloat(initialValue) * digitsFactor) / digitsFactor).toFixed(digits);
|
|
448
|
+
}
|
|
449
|
+
initialValue = initialValue.toString().replace(".", radixPoint);
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
//this needs to be in a separate part and not directly in decimalPart to allow rounding
|
|
453
|
+
if (opts.digits === 0 && initialValue.indexOf(radixPoint) !== -1) {
|
|
454
|
+
initialValue = initialValue.substring(0, initialValue.indexOf(radixPoint));
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
if (opts.min !== null || opts.max !== null) {
|
|
458
|
+
var numberValue = initialValue.toString().replace(radixPoint, ".");
|
|
459
|
+
if (opts.min !== null && numberValue < opts.min) {
|
|
460
|
+
initialValue = opts.min.toString().replace(".", radixPoint);
|
|
461
|
+
} else if (opts.max !== null && numberValue > opts.max) {
|
|
462
|
+
initialValue = opts.max.toString().replace(".", radixPoint);
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
if (isNagtive && initialValue.charAt(0) !== "-") {
|
|
467
|
+
initialValue = "-" + initialValue;
|
|
468
|
+
}
|
|
469
|
+
return alignDigits(initialValue.toString().split(""), digits, opts, forceDigits).join("");
|
|
470
|
+
}
|
|
471
|
+
,
|
|
472
|
+
onBeforeWrite: function (e, buffer, caretPos, opts) {
|
|
473
|
+
function stripBuffer(buffer, stripRadix) {
|
|
474
|
+
if (opts.__financeInput !== false || stripRadix) {
|
|
475
|
+
var position = buffer.indexOf(opts.radixPoint);
|
|
476
|
+
if (position !== -1) {
|
|
477
|
+
buffer.splice(position, 1);
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
if (opts.groupSeparator !== "") {
|
|
481
|
+
while ((position = buffer.indexOf(opts.groupSeparator)) !== -1) {
|
|
482
|
+
buffer.splice(position, 1);
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
return buffer;
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
let result, leadingzeroes;
|
|
490
|
+
if (opts.stripLeadingZeroes && (leadingzeroes = checkForLeadingZeroes(buffer, opts))) {
|
|
491
|
+
const caretNdx = buffer.join("").lastIndexOf(leadingzeroes[0].split("").reverse().join("")) - (leadingzeroes[0] == leadingzeroes.input ? 0 : 1),
|
|
492
|
+
offset = (leadingzeroes[0] == leadingzeroes.input ? 1 : 0);
|
|
493
|
+
for (let i = leadingzeroes[0].length - offset; i > 0; i--) {
|
|
494
|
+
delete this.maskset.validPositions[caretNdx + i];
|
|
495
|
+
delete buffer[caretNdx + i];
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
if (e) {
|
|
500
|
+
switch (e.type) {
|
|
501
|
+
case "blur":
|
|
502
|
+
case "checkval":
|
|
503
|
+
if (opts.min !== null) {
|
|
504
|
+
var unmasked = opts.onUnMask(buffer.slice().reverse().join(""), undefined, $.extend({}, opts, {
|
|
505
|
+
unmaskAsNumber: true
|
|
506
|
+
}));
|
|
507
|
+
if (opts.min !== null && unmasked < opts.min) {
|
|
508
|
+
return {
|
|
509
|
+
refreshFromBuffer: true,
|
|
510
|
+
buffer: alignDigits(opts.min.toString().replace(".", opts.radixPoint).split(""), opts.digits, opts).reverse()
|
|
511
|
+
};
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
if (buffer[buffer.length - 1] === opts.negationSymbol.front) { //strip negation symbol on blur when value is 0
|
|
515
|
+
var nmbrMtchs = new RegExp("(^" + (opts.negationSymbol.front != "" ? escapeRegex(opts.negationSymbol.front) + "?" : "") + escapeRegex(opts.prefix) + ")(.*)(" + escapeRegex(opts.suffix) + (opts.negationSymbol.back != "" ? escapeRegex(opts.negationSymbol.back) + "?" : "") + "$)").exec(stripBuffer(buffer.slice(), true).reverse().join("")),
|
|
516
|
+
number = nmbrMtchs ? nmbrMtchs[2] : "";
|
|
517
|
+
if (number == 0) {
|
|
518
|
+
result = {refreshFromBuffer: true, buffer: [0]};
|
|
519
|
+
}
|
|
520
|
+
} else if (opts.radixPoint !== "") { //strip radixpoint on blur when it is the latest char
|
|
521
|
+
var radixNDX = buffer.indexOf(opts.radixPoint);
|
|
522
|
+
if (radixNDX === opts.suffix.length) {
|
|
523
|
+
if (result && result.buffer) {
|
|
524
|
+
result.buffer.splice(0, 1 + opts.suffix.length);
|
|
525
|
+
} else {
|
|
526
|
+
buffer.splice(0, 1 + opts.suffix.length);
|
|
527
|
+
result =
|
|
528
|
+
{refreshFromBuffer: true, buffer: stripBuffer(buffer)};
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
if (opts.enforceDigitsOnBlur) {
|
|
534
|
+
result = result || {};
|
|
535
|
+
var bffr = (result && result.buffer) || buffer.slice().reverse();
|
|
536
|
+
result.refreshFromBuffer = true;
|
|
537
|
+
result.buffer = alignDigits(bffr, opts.digits, opts, true).reverse();
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
return result;
|
|
543
|
+
},
|
|
544
|
+
onKeyDown: function (e, buffer, caretPos, opts) {
|
|
545
|
+
var $input = $(this), bffr;
|
|
546
|
+
var pattern, c = String.fromCharCode(e.keyCode).toLowerCase();
|
|
547
|
+
if ((pattern = (opts.shortcuts && opts.shortcuts[c]))) {
|
|
548
|
+
if (pattern.length > 1) {
|
|
549
|
+
this.inputmask.__valueSet.call(this, parseFloat(this.inputmask.unmaskedvalue()) * parseInt(pattern));
|
|
550
|
+
$input.trigger("setvalue");
|
|
551
|
+
return false;
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
if (e.ctrlKey) {
|
|
555
|
+
switch (e.keyCode) {
|
|
556
|
+
case keyCode.UP:
|
|
557
|
+
this.inputmask.__valueSet.call(this, parseFloat(this.inputmask.unmaskedvalue()) + parseInt(opts.step));
|
|
558
|
+
$input.trigger("setvalue");
|
|
559
|
+
return false;
|
|
560
|
+
case keyCode.DOWN:
|
|
561
|
+
this.inputmask.__valueSet.call(this, parseFloat(this.inputmask.unmaskedvalue()) - parseInt(opts.step));
|
|
562
|
+
$input.trigger("setvalue");
|
|
563
|
+
return false;
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
if (!e.shiftKey && (e.keyCode === keyCode.DELETE || e.keyCode === keyCode.BACKSPACE || e.keyCode === keyCode.BACKSPACE_SAFARI) && caretPos.begin !== buffer.length) {
|
|
567
|
+
if (buffer[e.keyCode === keyCode.DELETE ? caretPos.begin - 1 : caretPos.end] === opts.negationSymbol.front) {
|
|
568
|
+
bffr = buffer.slice().reverse();
|
|
569
|
+
if (opts.negationSymbol.front !== "") bffr.shift();
|
|
570
|
+
if (opts.negationSymbol.back !== "") bffr.pop();
|
|
571
|
+
$input.trigger("setvalue", [bffr.join(""), caretPos.begin]);
|
|
572
|
+
return false;
|
|
573
|
+
} else if (opts._radixDance === true) {
|
|
574
|
+
var radixPos = buffer.indexOf(opts.radixPoint);
|
|
575
|
+
if (!opts.digitsOptional) {
|
|
576
|
+
if (radixPos !== -1 && (caretPos.begin < radixPos || caretPos.end < radixPos || (e.keyCode === keyCode.DELETE && caretPos.begin === radixPos))) {
|
|
577
|
+
if (caretPos.begin === caretPos.end && (e.keyCode === keyCode.BACKSPACE || e.keyCode === keyCode.BACKSPACE_SAFARI)) { //only adjust when not a selection
|
|
578
|
+
caretPos.begin++;
|
|
579
|
+
}
|
|
580
|
+
bffr = buffer.slice().reverse();
|
|
581
|
+
bffr.splice(bffr.length - caretPos.begin, caretPos.begin - caretPos.end + 1);
|
|
582
|
+
// console.log(caretPos);
|
|
583
|
+
bffr = alignDigits(bffr, opts.digits, opts).join("");
|
|
584
|
+
$input.trigger("setvalue", [bffr, caretPos.begin >= bffr.length ? radixPos + 1 : caretPos.begin]);
|
|
585
|
+
return false;
|
|
586
|
+
}
|
|
587
|
+
} else if (radixPos === 0) {
|
|
588
|
+
bffr = buffer.slice().reverse();
|
|
589
|
+
bffr.pop();
|
|
590
|
+
$input.trigger("setvalue", [bffr.join(""), caretPos.begin >= bffr.length ? bffr.length : caretPos.begin]);
|
|
591
|
+
return false;
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
},
|
|
597
|
+
"currency": {
|
|
598
|
+
prefix: "", //"$ ",
|
|
599
|
+
groupSeparator: ",",
|
|
600
|
+
alias: "numeric",
|
|
601
|
+
digits: 2,
|
|
602
|
+
digitsOptional: false
|
|
603
|
+
},
|
|
604
|
+
"decimal": {
|
|
605
|
+
alias: "numeric"
|
|
606
|
+
},
|
|
607
|
+
"integer": {
|
|
608
|
+
alias: "numeric",
|
|
609
|
+
inputmode: "numeric",
|
|
610
|
+
digits: 0
|
|
611
|
+
},
|
|
612
|
+
"percentage": {
|
|
613
|
+
alias: "numeric",
|
|
614
|
+
min: 0,
|
|
615
|
+
max: 100,
|
|
616
|
+
suffix: " %",
|
|
617
|
+
digits: 0,
|
|
618
|
+
allowMinus: false
|
|
619
|
+
},
|
|
620
|
+
"indianns": { //indian numbering system
|
|
621
|
+
alias: "numeric",
|
|
622
|
+
_mask: function (opts) {
|
|
623
|
+
return "(" + opts.groupSeparator + "99){*|1}(" + opts.groupSeparator + "999){1|1}";
|
|
624
|
+
},
|
|
625
|
+
groupSeparator: ",",
|
|
626
|
+
radixPoint: ".",
|
|
627
|
+
placeholder: "0",
|
|
628
|
+
digits: 2,
|
|
629
|
+
digitsOptional: false
|
|
630
|
+
}
|
|
631
|
+
});
|