inputmask-rails 4.0.9.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +50 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +158 -0
- data/LICENSE +21 -0
- data/README.md +66 -0
- data/Rakefile +31 -0
- data/inputmask-rails.gemspec +27 -0
- data/lib/inputmask-rails.rb +1 -0
- data/lib/inputmask/rails.rb +8 -0
- data/lib/inputmask/rails/engine.rb +6 -0
- data/lib/inputmask/rails/version.rb +6 -0
- data/vendor/assets/javascripts/bindings/inputmask.binding.js +33 -0
- data/vendor/assets/javascripts/bindings/inputmask.binding.min.js +1 -0
- data/vendor/assets/javascripts/dependencyLibs/inputmask.dependencyLib.jqlite.js +129 -0
- data/vendor/assets/javascripts/dependencyLibs/inputmask.dependencyLib.jqlite.min.js +1 -0
- data/vendor/assets/javascripts/dependencyLibs/inputmask.dependencyLib.jquery.js +19 -0
- data/vendor/assets/javascripts/dependencyLibs/inputmask.dependencyLib.jquery.min.js +1 -0
- data/vendor/assets/javascripts/dependencyLibs/inputmask.dependencyLib.js +301 -0
- data/vendor/assets/javascripts/dependencyLibs/inputmask.dependencyLib.min.js +1 -0
- data/vendor/assets/javascripts/global/window.js +11 -0
- data/vendor/assets/javascripts/global/window.min.js +1 -0
- data/vendor/assets/javascripts/inputmask.date.extensions.js +252 -0
- data/vendor/assets/javascripts/inputmask.date.extensions.min.js +1 -0
- data/vendor/assets/javascripts/inputmask.extensions.js +97 -0
- data/vendor/assets/javascripts/inputmask.extensions.min.js +1 -0
- data/vendor/assets/javascripts/inputmask.js +2745 -0
- data/vendor/assets/javascripts/inputmask.min.js +1 -0
- data/vendor/assets/javascripts/inputmask.numeric.extensions.js +553 -0
- data/vendor/assets/javascripts/inputmask.numeric.extensions.min.js +1 -0
- data/vendor/assets/javascripts/jquery.inputmask.bundle.js +3867 -0
- data/vendor/assets/javascripts/jquery.inputmask.bundle.min.js +9 -0
- data/vendor/assets/javascripts/jquery.inputmask.js +97 -0
- data/vendor/assets/javascripts/jquery.inputmask.min.js +1 -0
- metadata +135 -0
@@ -0,0 +1 @@
|
|
1
|
+
404: Not Found
|
@@ -0,0 +1,553 @@
|
|
1
|
+
/*!
|
2
|
+
* inputmask.numeric.extensions.js
|
3
|
+
* https://github.com/RobinHerbots/Inputmask
|
4
|
+
* Copyright (c) 2010 - 2019 Robin Herbots
|
5
|
+
* Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
|
6
|
+
* Version: 4.0.9
|
7
|
+
*/
|
8
|
+
|
9
|
+
(function(factory) {
|
10
|
+
if (typeof define === "function" && define.amd) {
|
11
|
+
define([ "./inputmask" ], factory);
|
12
|
+
} else if (typeof exports === "object") {
|
13
|
+
module.exports = factory(require("./inputmask"));
|
14
|
+
} else {
|
15
|
+
factory(window.Inputmask);
|
16
|
+
}
|
17
|
+
})(function(Inputmask) {
|
18
|
+
var $ = Inputmask.dependencyLib;
|
19
|
+
function autoEscape(txt, opts) {
|
20
|
+
var escapedTxt = "";
|
21
|
+
for (var i = 0; i < txt.length; i++) {
|
22
|
+
if (Inputmask.prototype.definitions[txt.charAt(i)] || opts.definitions[txt.charAt(i)] || opts.optionalmarker.start === txt.charAt(i) || opts.optionalmarker.end === txt.charAt(i) || opts.quantifiermarker.start === txt.charAt(i) || opts.quantifiermarker.end === txt.charAt(i) || opts.groupmarker.start === txt.charAt(i) || opts.groupmarker.end === txt.charAt(i) || opts.alternatormarker === txt.charAt(i)) {
|
23
|
+
escapedTxt += "\\" + txt.charAt(i);
|
24
|
+
} else escapedTxt += txt.charAt(i);
|
25
|
+
}
|
26
|
+
return escapedTxt;
|
27
|
+
}
|
28
|
+
function alignDigits(buffer, digits, opts) {
|
29
|
+
if (digits > 0) {
|
30
|
+
var radixPosition = $.inArray(opts.radixPoint, buffer);
|
31
|
+
if (radixPosition === -1) {
|
32
|
+
buffer.push(opts.radixPoint);
|
33
|
+
radixPosition = buffer.length - 1;
|
34
|
+
}
|
35
|
+
for (var i = 1; i <= digits; i++) {
|
36
|
+
buffer[radixPosition + i] = buffer[radixPosition + i] || "0";
|
37
|
+
}
|
38
|
+
}
|
39
|
+
return buffer;
|
40
|
+
}
|
41
|
+
Inputmask.extendAliases({
|
42
|
+
numeric: {
|
43
|
+
mask: function(opts) {
|
44
|
+
if (opts.repeat !== 0 && isNaN(opts.integerDigits)) {
|
45
|
+
opts.integerDigits = opts.repeat;
|
46
|
+
}
|
47
|
+
opts.repeat = 0;
|
48
|
+
if (opts.groupSeparator === opts.radixPoint && opts.digits && opts.digits !== "0") {
|
49
|
+
if (opts.radixPoint === ".") {
|
50
|
+
opts.groupSeparator = ",";
|
51
|
+
} else if (opts.radixPoint === ",") {
|
52
|
+
opts.groupSeparator = ".";
|
53
|
+
} else opts.groupSeparator = "";
|
54
|
+
}
|
55
|
+
if (opts.groupSeparator === " ") {
|
56
|
+
opts.skipOptionalPartCharacter = undefined;
|
57
|
+
}
|
58
|
+
opts.autoGroup = opts.autoGroup && opts.groupSeparator !== "";
|
59
|
+
if (opts.autoGroup) {
|
60
|
+
if (typeof opts.groupSize == "string" && isFinite(opts.groupSize)) opts.groupSize = parseInt(opts.groupSize);
|
61
|
+
if (isFinite(opts.integerDigits)) {
|
62
|
+
var seps = Math.floor(opts.integerDigits / opts.groupSize);
|
63
|
+
var mod = opts.integerDigits % opts.groupSize;
|
64
|
+
opts.integerDigits = parseInt(opts.integerDigits) + (mod === 0 ? seps - 1 : seps);
|
65
|
+
if (opts.integerDigits < 1) {
|
66
|
+
opts.integerDigits = "*";
|
67
|
+
}
|
68
|
+
}
|
69
|
+
}
|
70
|
+
if (opts.placeholder.length > 1) {
|
71
|
+
opts.placeholder = opts.placeholder.charAt(0);
|
72
|
+
}
|
73
|
+
if (opts.positionCaretOnClick === "radixFocus" && (opts.placeholder === "" && opts.integerOptional === false)) {
|
74
|
+
opts.positionCaretOnClick = "lvp";
|
75
|
+
}
|
76
|
+
opts.definitions[";"] = opts.definitions["~"];
|
77
|
+
opts.definitions[";"].definitionSymbol = "~";
|
78
|
+
if (opts.numericInput === true) {
|
79
|
+
opts.positionCaretOnClick = opts.positionCaretOnClick === "radixFocus" ? "lvp" : opts.positionCaretOnClick;
|
80
|
+
opts.digitsOptional = false;
|
81
|
+
if (isNaN(opts.digits)) opts.digits = 2;
|
82
|
+
opts.decimalProtect = false;
|
83
|
+
}
|
84
|
+
var mask = "[+]";
|
85
|
+
mask += autoEscape(opts.prefix, opts);
|
86
|
+
if (opts.integerOptional === true) {
|
87
|
+
mask += "~{1," + opts.integerDigits + "}";
|
88
|
+
} else mask += "~{" + opts.integerDigits + "}";
|
89
|
+
if (opts.digits !== undefined) {
|
90
|
+
var radixDef = opts.decimalProtect ? ":" : opts.radixPoint;
|
91
|
+
var dq = opts.digits.toString().split(",");
|
92
|
+
if (isFinite(dq[0]) && dq[1] && isFinite(dq[1])) {
|
93
|
+
mask += radixDef + ";{" + opts.digits + "}";
|
94
|
+
} else if (isNaN(opts.digits) || parseInt(opts.digits) > 0) {
|
95
|
+
if (opts.digitsOptional) {
|
96
|
+
mask += "[" + radixDef + ";{1," + opts.digits + "}]";
|
97
|
+
} else mask += radixDef + ";{" + opts.digits + "}";
|
98
|
+
}
|
99
|
+
}
|
100
|
+
mask += autoEscape(opts.suffix, opts);
|
101
|
+
mask += "[-]";
|
102
|
+
opts.greedy = false;
|
103
|
+
return mask;
|
104
|
+
},
|
105
|
+
placeholder: "",
|
106
|
+
greedy: false,
|
107
|
+
digits: "*",
|
108
|
+
digitsOptional: true,
|
109
|
+
enforceDigitsOnBlur: false,
|
110
|
+
radixPoint: ".",
|
111
|
+
positionCaretOnClick: "radixFocus",
|
112
|
+
groupSize: 3,
|
113
|
+
groupSeparator: "",
|
114
|
+
autoGroup: false,
|
115
|
+
allowMinus: true,
|
116
|
+
negationSymbol: {
|
117
|
+
front: "-",
|
118
|
+
back: ""
|
119
|
+
},
|
120
|
+
integerDigits: "+",
|
121
|
+
integerOptional: true,
|
122
|
+
prefix: "",
|
123
|
+
suffix: "",
|
124
|
+
rightAlign: true,
|
125
|
+
decimalProtect: true,
|
126
|
+
min: null,
|
127
|
+
max: null,
|
128
|
+
step: 1,
|
129
|
+
insertMode: true,
|
130
|
+
autoUnmask: false,
|
131
|
+
unmaskAsNumber: false,
|
132
|
+
inputType: "text",
|
133
|
+
inputmode: "numeric",
|
134
|
+
preValidation: function(buffer, pos, c, isSelection, opts, maskset) {
|
135
|
+
if (c === "-" || c === opts.negationSymbol.front) {
|
136
|
+
if (opts.allowMinus !== true) return false;
|
137
|
+
opts.isNegative = opts.isNegative === undefined ? true : !opts.isNegative;
|
138
|
+
if (buffer.join("") === "") return true;
|
139
|
+
return {
|
140
|
+
caret: maskset.validPositions[pos] ? pos : undefined,
|
141
|
+
dopost: true
|
142
|
+
};
|
143
|
+
}
|
144
|
+
if (isSelection === false && c === opts.radixPoint && (opts.digits !== undefined && (isNaN(opts.digits) || parseInt(opts.digits) > 0))) {
|
145
|
+
var radixPos = $.inArray(opts.radixPoint, buffer);
|
146
|
+
if (radixPos !== -1 && maskset.validPositions[radixPos] !== undefined) {
|
147
|
+
if (opts.numericInput === true) {
|
148
|
+
return pos === radixPos;
|
149
|
+
}
|
150
|
+
return {
|
151
|
+
caret: radixPos + 1
|
152
|
+
};
|
153
|
+
}
|
154
|
+
}
|
155
|
+
return true;
|
156
|
+
},
|
157
|
+
postValidation: function(buffer, pos, currentResult, opts) {
|
158
|
+
function buildPostMask(buffer, opts) {
|
159
|
+
var postMask = "";
|
160
|
+
postMask += "(" + opts.groupSeparator + "*{" + opts.groupSize + "}){*}";
|
161
|
+
if (opts.radixPoint !== "") {
|
162
|
+
var radixSplit = buffer.join("").split(opts.radixPoint);
|
163
|
+
if (radixSplit[1]) {
|
164
|
+
postMask += opts.radixPoint + "*{" + radixSplit[1].match(/^\d*\??\d*/)[0].length + "}";
|
165
|
+
}
|
166
|
+
}
|
167
|
+
return postMask;
|
168
|
+
}
|
169
|
+
var suffix = opts.suffix.split(""), prefix = opts.prefix.split("");
|
170
|
+
if (currentResult.pos === undefined && currentResult.caret !== undefined && currentResult.dopost !== true) return currentResult;
|
171
|
+
var caretPos = currentResult.caret !== undefined ? currentResult.caret : currentResult.pos;
|
172
|
+
var maskedValue = buffer.slice();
|
173
|
+
if (opts.numericInput) {
|
174
|
+
caretPos = maskedValue.length - caretPos - 1;
|
175
|
+
maskedValue = maskedValue.reverse();
|
176
|
+
}
|
177
|
+
var charAtPos = maskedValue[caretPos];
|
178
|
+
if (charAtPos === opts.groupSeparator) {
|
179
|
+
caretPos += 1;
|
180
|
+
charAtPos = maskedValue[caretPos];
|
181
|
+
}
|
182
|
+
if (caretPos === maskedValue.length - opts.suffix.length - 1 && charAtPos === opts.radixPoint) return currentResult;
|
183
|
+
if (charAtPos !== undefined) {
|
184
|
+
if (charAtPos !== opts.radixPoint && charAtPos !== opts.negationSymbol.front && charAtPos !== opts.negationSymbol.back) {
|
185
|
+
maskedValue[caretPos] = "?";
|
186
|
+
if (opts.prefix.length > 0 && caretPos >= (opts.isNegative === false ? 1 : 0) && caretPos < opts.prefix.length - 1 + (opts.isNegative === false ? 1 : 0)) {
|
187
|
+
prefix[caretPos - (opts.isNegative === false ? 1 : 0)] = "?";
|
188
|
+
} else if (opts.suffix.length > 0 && caretPos >= maskedValue.length - opts.suffix.length - (opts.isNegative === false ? 1 : 0)) {
|
189
|
+
suffix[caretPos - (maskedValue.length - opts.suffix.length - (opts.isNegative === false ? 1 : 0))] = "?";
|
190
|
+
}
|
191
|
+
}
|
192
|
+
}
|
193
|
+
prefix = prefix.join("");
|
194
|
+
suffix = suffix.join("");
|
195
|
+
var processValue = maskedValue.join("").replace(prefix, "");
|
196
|
+
processValue = processValue.replace(suffix, "");
|
197
|
+
processValue = processValue.replace(new RegExp(Inputmask.escapeRegex(opts.groupSeparator), "g"), "");
|
198
|
+
processValue = processValue.replace(new RegExp("[-" + Inputmask.escapeRegex(opts.negationSymbol.front) + "]", "g"), "");
|
199
|
+
processValue = processValue.replace(new RegExp(Inputmask.escapeRegex(opts.negationSymbol.back) + "$"), "");
|
200
|
+
if (isNaN(opts.placeholder)) {
|
201
|
+
processValue = processValue.replace(new RegExp(Inputmask.escapeRegex(opts.placeholder), "g"), "");
|
202
|
+
}
|
203
|
+
if (processValue.length > 1 && processValue.indexOf(opts.radixPoint) !== 1) {
|
204
|
+
if (charAtPos === "0") {
|
205
|
+
processValue = processValue.replace(/^\?/g, "");
|
206
|
+
}
|
207
|
+
processValue = processValue.replace(/^0/g, "");
|
208
|
+
}
|
209
|
+
if (processValue.charAt(0) === opts.radixPoint && opts.radixPoint !== "" && opts.numericInput !== true) {
|
210
|
+
processValue = "0" + processValue;
|
211
|
+
}
|
212
|
+
if (processValue !== "") {
|
213
|
+
processValue = processValue.split("");
|
214
|
+
if ((!opts.digitsOptional || opts.enforceDigitsOnBlur && currentResult.event === "blur") && isFinite(opts.digits)) {
|
215
|
+
var radixPosition = $.inArray(opts.radixPoint, processValue);
|
216
|
+
var rpb = $.inArray(opts.radixPoint, maskedValue);
|
217
|
+
if (radixPosition === -1) {
|
218
|
+
processValue.push(opts.radixPoint);
|
219
|
+
radixPosition = processValue.length - 1;
|
220
|
+
}
|
221
|
+
for (var i = 1; i <= opts.digits; i++) {
|
222
|
+
if ((!opts.digitsOptional || opts.enforceDigitsOnBlur && currentResult.event === "blur") && (processValue[radixPosition + i] === undefined || processValue[radixPosition + i] === opts.placeholder.charAt(0))) {
|
223
|
+
processValue[radixPosition + i] = currentResult.placeholder || opts.placeholder.charAt(0);
|
224
|
+
} else if (rpb !== -1 && maskedValue[rpb + i] !== undefined) {
|
225
|
+
processValue[radixPosition + i] = processValue[radixPosition + i] || maskedValue[rpb + i];
|
226
|
+
}
|
227
|
+
}
|
228
|
+
}
|
229
|
+
if (opts.autoGroup === true && opts.groupSeparator !== "" && (charAtPos !== opts.radixPoint || currentResult.pos !== undefined || currentResult.dopost)) {
|
230
|
+
var addRadix = processValue[processValue.length - 1] === opts.radixPoint && currentResult.c === opts.radixPoint;
|
231
|
+
processValue = Inputmask(buildPostMask(processValue, opts), {
|
232
|
+
numericInput: true,
|
233
|
+
jitMasking: true,
|
234
|
+
definitions: {
|
235
|
+
"*": {
|
236
|
+
validator: "[0-9?]",
|
237
|
+
cardinality: 1
|
238
|
+
}
|
239
|
+
}
|
240
|
+
}).format(processValue.join(""));
|
241
|
+
if (addRadix) processValue += opts.radixPoint;
|
242
|
+
if (processValue.charAt(0) === opts.groupSeparator) {
|
243
|
+
processValue.substr(1);
|
244
|
+
}
|
245
|
+
} else processValue = processValue.join("");
|
246
|
+
}
|
247
|
+
if (opts.isNegative && currentResult.event === "blur") {
|
248
|
+
opts.isNegative = processValue !== "0";
|
249
|
+
}
|
250
|
+
processValue = prefix + processValue;
|
251
|
+
processValue += suffix;
|
252
|
+
if (opts.isNegative) {
|
253
|
+
processValue = opts.negationSymbol.front + processValue;
|
254
|
+
processValue += opts.negationSymbol.back;
|
255
|
+
}
|
256
|
+
processValue = processValue.split("");
|
257
|
+
if (charAtPos !== undefined) {
|
258
|
+
if (charAtPos !== opts.radixPoint && charAtPos !== opts.negationSymbol.front && charAtPos !== opts.negationSymbol.back) {
|
259
|
+
caretPos = $.inArray("?", processValue);
|
260
|
+
if (caretPos > -1) {
|
261
|
+
processValue[caretPos] = charAtPos;
|
262
|
+
} else caretPos = currentResult.caret || 0;
|
263
|
+
} else if (charAtPos === opts.radixPoint || charAtPos === opts.negationSymbol.front || charAtPos === opts.negationSymbol.back) {
|
264
|
+
var newCaretPos = $.inArray(charAtPos, processValue);
|
265
|
+
if (newCaretPos !== -1) caretPos = newCaretPos;
|
266
|
+
}
|
267
|
+
}
|
268
|
+
if (opts.numericInput) {
|
269
|
+
caretPos = processValue.length - caretPos - 1;
|
270
|
+
processValue = processValue.reverse();
|
271
|
+
}
|
272
|
+
var rslt = {
|
273
|
+
caret: (charAtPos === undefined || currentResult.pos !== undefined) && caretPos !== undefined ? caretPos + (opts.numericInput ? -1 : 1) : caretPos,
|
274
|
+
buffer: processValue,
|
275
|
+
refreshFromBuffer: currentResult.dopost || buffer.join("") !== processValue.join("")
|
276
|
+
};
|
277
|
+
return rslt.refreshFromBuffer ? rslt : currentResult;
|
278
|
+
},
|
279
|
+
onBeforeWrite: function(e, buffer, caretPos, opts) {
|
280
|
+
function parseMinMaxOptions(opts) {
|
281
|
+
if (opts.parseMinMaxOptions === undefined) {
|
282
|
+
if (opts.min !== null) {
|
283
|
+
opts.min = opts.min.toString().replace(new RegExp(Inputmask.escapeRegex(opts.groupSeparator), "g"), "");
|
284
|
+
if (opts.radixPoint === ",") opts.min = opts.min.replace(opts.radixPoint, ".");
|
285
|
+
opts.min = isFinite(opts.min) ? parseFloat(opts.min) : NaN;
|
286
|
+
if (isNaN(opts.min)) opts.min = Number.MIN_VALUE;
|
287
|
+
}
|
288
|
+
if (opts.max !== null) {
|
289
|
+
opts.max = opts.max.toString().replace(new RegExp(Inputmask.escapeRegex(opts.groupSeparator), "g"), "");
|
290
|
+
if (opts.radixPoint === ",") opts.max = opts.max.replace(opts.radixPoint, ".");
|
291
|
+
opts.max = isFinite(opts.max) ? parseFloat(opts.max) : NaN;
|
292
|
+
if (isNaN(opts.max)) opts.max = Number.MAX_VALUE;
|
293
|
+
}
|
294
|
+
opts.parseMinMaxOptions = "done";
|
295
|
+
}
|
296
|
+
}
|
297
|
+
if (e) {
|
298
|
+
switch (e.type) {
|
299
|
+
case "keydown":
|
300
|
+
return opts.postValidation(buffer, caretPos, {
|
301
|
+
caret: caretPos,
|
302
|
+
dopost: true
|
303
|
+
}, opts);
|
304
|
+
|
305
|
+
case "blur":
|
306
|
+
case "checkval":
|
307
|
+
var unmasked;
|
308
|
+
parseMinMaxOptions(opts);
|
309
|
+
if (opts.min !== null || opts.max !== null) {
|
310
|
+
unmasked = opts.onUnMask(buffer.join(""), undefined, $.extend({}, opts, {
|
311
|
+
unmaskAsNumber: true
|
312
|
+
}));
|
313
|
+
if (opts.min !== null && unmasked < opts.min) {
|
314
|
+
opts.isNegative = opts.min < 0;
|
315
|
+
return opts.postValidation(opts.min.toString().replace(".", opts.radixPoint).split(""), caretPos, {
|
316
|
+
caret: caretPos,
|
317
|
+
dopost: true,
|
318
|
+
placeholder: "0"
|
319
|
+
}, opts);
|
320
|
+
} else if (opts.max !== null && unmasked > opts.max) {
|
321
|
+
opts.isNegative = opts.max < 0;
|
322
|
+
return opts.postValidation(opts.max.toString().replace(".", opts.radixPoint).split(""), caretPos, {
|
323
|
+
caret: caretPos,
|
324
|
+
dopost: true,
|
325
|
+
placeholder: "0"
|
326
|
+
}, opts);
|
327
|
+
}
|
328
|
+
}
|
329
|
+
return opts.postValidation(buffer, caretPos, {
|
330
|
+
caret: caretPos,
|
331
|
+
placeholder: "0",
|
332
|
+
event: "blur"
|
333
|
+
}, opts);
|
334
|
+
|
335
|
+
case "_checkval":
|
336
|
+
return {
|
337
|
+
caret: caretPos
|
338
|
+
};
|
339
|
+
|
340
|
+
default:
|
341
|
+
break;
|
342
|
+
}
|
343
|
+
}
|
344
|
+
},
|
345
|
+
regex: {
|
346
|
+
integerPart: function(opts, emptyCheck) {
|
347
|
+
return emptyCheck ? new RegExp("[" + Inputmask.escapeRegex(opts.negationSymbol.front) + "+]?") : new RegExp("[" + Inputmask.escapeRegex(opts.negationSymbol.front) + "+]?\\d+");
|
348
|
+
},
|
349
|
+
integerNPart: function(opts) {
|
350
|
+
return new RegExp("[\\d" + Inputmask.escapeRegex(opts.groupSeparator) + Inputmask.escapeRegex(opts.placeholder.charAt(0)) + "]+");
|
351
|
+
}
|
352
|
+
},
|
353
|
+
definitions: {
|
354
|
+
"~": {
|
355
|
+
validator: function(chrs, maskset, pos, strict, opts, isSelection) {
|
356
|
+
var isValid, l;
|
357
|
+
if (chrs === "k" || chrs === "m") {
|
358
|
+
isValid = {
|
359
|
+
insert: [],
|
360
|
+
c: 0
|
361
|
+
};
|
362
|
+
for (var i = 0, l = chrs === "k" ? 2 : 5; i < l; i++) {
|
363
|
+
isValid.insert.push({
|
364
|
+
pos: pos + i,
|
365
|
+
c: 0
|
366
|
+
});
|
367
|
+
}
|
368
|
+
isValid.pos = pos + l;
|
369
|
+
return isValid;
|
370
|
+
}
|
371
|
+
isValid = strict ? new RegExp("[0-9" + Inputmask.escapeRegex(opts.groupSeparator) + "]").test(chrs) : new RegExp("[0-9]").test(chrs);
|
372
|
+
if (isValid === true) {
|
373
|
+
if (opts.numericInput !== true && maskset.validPositions[pos] !== undefined && maskset.validPositions[pos].match.def === "~" && !isSelection) {
|
374
|
+
var processValue = maskset.buffer.join("");
|
375
|
+
processValue = processValue.replace(new RegExp("[-" + Inputmask.escapeRegex(opts.negationSymbol.front) + "]", "g"), "");
|
376
|
+
processValue = processValue.replace(new RegExp(Inputmask.escapeRegex(opts.negationSymbol.back) + "$"), "");
|
377
|
+
var pvRadixSplit = processValue.split(opts.radixPoint);
|
378
|
+
if (pvRadixSplit.length > 1) {
|
379
|
+
pvRadixSplit[1] = pvRadixSplit[1].replace(/0/g, opts.placeholder.charAt(0));
|
380
|
+
}
|
381
|
+
if (pvRadixSplit[0] === "0") {
|
382
|
+
pvRadixSplit[0] = pvRadixSplit[0].replace(/0/g, opts.placeholder.charAt(0));
|
383
|
+
}
|
384
|
+
processValue = pvRadixSplit[0] + opts.radixPoint + pvRadixSplit[1] || "";
|
385
|
+
var bufferTemplate = maskset._buffer.join("");
|
386
|
+
if (processValue === opts.radixPoint) {
|
387
|
+
processValue = bufferTemplate;
|
388
|
+
}
|
389
|
+
while (processValue.match(Inputmask.escapeRegex(bufferTemplate) + "$") === null) {
|
390
|
+
bufferTemplate = bufferTemplate.slice(1);
|
391
|
+
}
|
392
|
+
processValue = processValue.replace(bufferTemplate, "");
|
393
|
+
processValue = processValue.split("");
|
394
|
+
if (processValue[pos] === undefined) {
|
395
|
+
isValid = {
|
396
|
+
pos: pos,
|
397
|
+
remove: pos
|
398
|
+
};
|
399
|
+
} else {
|
400
|
+
isValid = {
|
401
|
+
pos: pos
|
402
|
+
};
|
403
|
+
}
|
404
|
+
}
|
405
|
+
} else if (!strict && chrs === opts.radixPoint && maskset.validPositions[pos - 1] === undefined) {
|
406
|
+
isValid = {
|
407
|
+
insert: {
|
408
|
+
pos: pos,
|
409
|
+
c: 0
|
410
|
+
},
|
411
|
+
pos: pos + 1
|
412
|
+
};
|
413
|
+
}
|
414
|
+
return isValid;
|
415
|
+
},
|
416
|
+
cardinality: 1
|
417
|
+
},
|
418
|
+
"+": {
|
419
|
+
validator: function(chrs, maskset, pos, strict, opts) {
|
420
|
+
return opts.allowMinus && (chrs === "-" || chrs === opts.negationSymbol.front);
|
421
|
+
},
|
422
|
+
cardinality: 1,
|
423
|
+
placeholder: ""
|
424
|
+
},
|
425
|
+
"-": {
|
426
|
+
validator: function(chrs, maskset, pos, strict, opts) {
|
427
|
+
return opts.allowMinus && chrs === opts.negationSymbol.back;
|
428
|
+
},
|
429
|
+
cardinality: 1,
|
430
|
+
placeholder: ""
|
431
|
+
},
|
432
|
+
":": {
|
433
|
+
validator: function(chrs, maskset, pos, strict, opts) {
|
434
|
+
var radix = "[" + Inputmask.escapeRegex(opts.radixPoint) + "]";
|
435
|
+
var isValid = new RegExp(radix).test(chrs);
|
436
|
+
if (isValid && maskset.validPositions[pos] && maskset.validPositions[pos].match.placeholder === opts.radixPoint) {
|
437
|
+
isValid = {
|
438
|
+
caret: pos + 1
|
439
|
+
};
|
440
|
+
}
|
441
|
+
return isValid;
|
442
|
+
},
|
443
|
+
cardinality: 1,
|
444
|
+
placeholder: function(opts) {
|
445
|
+
return opts.radixPoint;
|
446
|
+
}
|
447
|
+
}
|
448
|
+
},
|
449
|
+
onUnMask: function(maskedValue, unmaskedValue, opts) {
|
450
|
+
if (unmaskedValue === "" && opts.nullable === true) {
|
451
|
+
return unmaskedValue;
|
452
|
+
}
|
453
|
+
var processValue = maskedValue.replace(opts.prefix, "");
|
454
|
+
processValue = processValue.replace(opts.suffix, "");
|
455
|
+
processValue = processValue.replace(new RegExp(Inputmask.escapeRegex(opts.groupSeparator), "g"), "");
|
456
|
+
if (opts.placeholder.charAt(0) !== "") {
|
457
|
+
processValue = processValue.replace(new RegExp(opts.placeholder.charAt(0), "g"), "0");
|
458
|
+
}
|
459
|
+
if (opts.unmaskAsNumber) {
|
460
|
+
if (opts.radixPoint !== "" && processValue.indexOf(opts.radixPoint) !== -1) processValue = processValue.replace(Inputmask.escapeRegex.call(this, opts.radixPoint), ".");
|
461
|
+
processValue = processValue.replace(new RegExp("^" + Inputmask.escapeRegex(opts.negationSymbol.front)), "-");
|
462
|
+
processValue = processValue.replace(new RegExp(Inputmask.escapeRegex(opts.negationSymbol.back) + "$"), "");
|
463
|
+
return Number(processValue);
|
464
|
+
}
|
465
|
+
return processValue;
|
466
|
+
},
|
467
|
+
isComplete: function(buffer, opts) {
|
468
|
+
var maskedValue = (opts.numericInput ? buffer.slice().reverse() : buffer).join("");
|
469
|
+
maskedValue = maskedValue.replace(new RegExp("^" + Inputmask.escapeRegex(opts.negationSymbol.front)), "-");
|
470
|
+
maskedValue = maskedValue.replace(new RegExp(Inputmask.escapeRegex(opts.negationSymbol.back) + "$"), "");
|
471
|
+
maskedValue = maskedValue.replace(opts.prefix, "");
|
472
|
+
maskedValue = maskedValue.replace(opts.suffix, "");
|
473
|
+
maskedValue = maskedValue.replace(new RegExp(Inputmask.escapeRegex(opts.groupSeparator) + "([0-9]{3})", "g"), "$1");
|
474
|
+
if (opts.radixPoint === ",") maskedValue = maskedValue.replace(Inputmask.escapeRegex(opts.radixPoint), ".");
|
475
|
+
return isFinite(maskedValue);
|
476
|
+
},
|
477
|
+
onBeforeMask: function(initialValue, opts) {
|
478
|
+
opts.isNegative = undefined;
|
479
|
+
var radixPoint = opts.radixPoint || ",";
|
480
|
+
if ((typeof initialValue == "number" || opts.inputType === "number") && radixPoint !== "") {
|
481
|
+
initialValue = initialValue.toString().replace(".", radixPoint);
|
482
|
+
}
|
483
|
+
var valueParts = initialValue.split(radixPoint), integerPart = valueParts[0].replace(/[^\-0-9]/g, ""), decimalPart = valueParts.length > 1 ? valueParts[1].replace(/[^0-9]/g, "") : "";
|
484
|
+
initialValue = integerPart + (decimalPart !== "" ? radixPoint + decimalPart : decimalPart);
|
485
|
+
var digits = 0;
|
486
|
+
if (radixPoint !== "") {
|
487
|
+
digits = decimalPart.length;
|
488
|
+
if (decimalPart !== "") {
|
489
|
+
var digitsFactor = Math.pow(10, digits || 1);
|
490
|
+
if (isFinite(opts.digits)) {
|
491
|
+
digits = parseInt(opts.digits);
|
492
|
+
digitsFactor = Math.pow(10, digits);
|
493
|
+
}
|
494
|
+
initialValue = initialValue.replace(Inputmask.escapeRegex(radixPoint), ".");
|
495
|
+
if (isFinite(initialValue)) initialValue = Math.round(parseFloat(initialValue) * digitsFactor) / digitsFactor;
|
496
|
+
initialValue = initialValue.toString().replace(".", radixPoint);
|
497
|
+
}
|
498
|
+
}
|
499
|
+
if (opts.digits === 0 && initialValue.indexOf(Inputmask.escapeRegex(radixPoint)) !== -1) {
|
500
|
+
initialValue = initialValue.substring(0, initialValue.indexOf(Inputmask.escapeRegex(radixPoint)));
|
501
|
+
}
|
502
|
+
return alignDigits(initialValue.toString().split(""), digits, opts).join("");
|
503
|
+
},
|
504
|
+
onKeyDown: function(e, buffer, caretPos, opts) {
|
505
|
+
var $input = $(this);
|
506
|
+
if (e.ctrlKey) {
|
507
|
+
switch (e.keyCode) {
|
508
|
+
case Inputmask.keyCode.UP:
|
509
|
+
$input.val(parseFloat(this.inputmask.unmaskedvalue()) + parseInt(opts.step));
|
510
|
+
$input.trigger("setvalue");
|
511
|
+
break;
|
512
|
+
|
513
|
+
case Inputmask.keyCode.DOWN:
|
514
|
+
$input.val(parseFloat(this.inputmask.unmaskedvalue()) - parseInt(opts.step));
|
515
|
+
$input.trigger("setvalue");
|
516
|
+
break;
|
517
|
+
}
|
518
|
+
}
|
519
|
+
}
|
520
|
+
},
|
521
|
+
currency: {
|
522
|
+
prefix: "$ ",
|
523
|
+
groupSeparator: ",",
|
524
|
+
alias: "numeric",
|
525
|
+
placeholder: "0",
|
526
|
+
autoGroup: true,
|
527
|
+
digits: 2,
|
528
|
+
digitsOptional: false,
|
529
|
+
clearMaskOnLostFocus: false
|
530
|
+
},
|
531
|
+
decimal: {
|
532
|
+
alias: "numeric"
|
533
|
+
},
|
534
|
+
integer: {
|
535
|
+
alias: "numeric",
|
536
|
+
digits: 0,
|
537
|
+
radixPoint: ""
|
538
|
+
},
|
539
|
+
percentage: {
|
540
|
+
alias: "numeric",
|
541
|
+
digits: 2,
|
542
|
+
digitsOptional: true,
|
543
|
+
radixPoint: ".",
|
544
|
+
placeholder: "0",
|
545
|
+
autoGroup: false,
|
546
|
+
min: 0,
|
547
|
+
max: 100,
|
548
|
+
suffix: " %",
|
549
|
+
allowMinus: false
|
550
|
+
}
|
551
|
+
});
|
552
|
+
return Inputmask;
|
553
|
+
});
|