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,11 @@
|
|
1
|
+
/*!
|
2
|
+
* global/window.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
|
+
if (typeof define === "function" && define.amd) define(function() {
|
10
|
+
return typeof window !== "undefined" ? window : new (eval("require('jsdom').JSDOM"))("").window;
|
11
|
+
}); else if (typeof exports === "object") module.exports = typeof window !== "undefined" ? window : new (eval("require('jsdom').JSDOM"))("").window;
|
@@ -0,0 +1 @@
|
|
1
|
+
404: Not Found
|
@@ -0,0 +1,252 @@
|
|
1
|
+
/*!
|
2
|
+
* inputmask.date.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
|
+
var formatCode = {
|
20
|
+
d: [ "[1-9]|[12][0-9]|3[01]", Date.prototype.setDate, "day", Date.prototype.getDate ],
|
21
|
+
dd: [ "0[1-9]|[12][0-9]|3[01]", Date.prototype.setDate, "day", function() {
|
22
|
+
return pad(Date.prototype.getDate.call(this), 2);
|
23
|
+
} ],
|
24
|
+
ddd: [ "" ],
|
25
|
+
dddd: [ "" ],
|
26
|
+
m: [ "[1-9]|1[012]", Date.prototype.setMonth, "month", function() {
|
27
|
+
return Date.prototype.getMonth.call(this) + 1;
|
28
|
+
} ],
|
29
|
+
mm: [ "0[1-9]|1[012]", Date.prototype.setMonth, "month", function() {
|
30
|
+
return pad(Date.prototype.getMonth.call(this) + 1, 2);
|
31
|
+
} ],
|
32
|
+
mmm: [ "" ],
|
33
|
+
mmmm: [ "" ],
|
34
|
+
yy: [ "[0-9]{2}", Date.prototype.setFullYear, "year", function() {
|
35
|
+
return pad(Date.prototype.getFullYear.call(this), 2);
|
36
|
+
} ],
|
37
|
+
yyyy: [ "[0-9]{4}", Date.prototype.setFullYear, "year", function() {
|
38
|
+
return pad(Date.prototype.getFullYear.call(this), 4);
|
39
|
+
} ],
|
40
|
+
h: [ "[1-9]|1[0-2]", Date.prototype.setHours, "hours", Date.prototype.getHours ],
|
41
|
+
hh: [ "0[1-9]|1[0-2]", Date.prototype.setHours, "hours", function() {
|
42
|
+
return pad(Date.prototype.getHours.call(this), 2);
|
43
|
+
} ],
|
44
|
+
hhh: [ "[0-9]+", Date.prototype.setHours, "hours", Date.prototype.getHours ],
|
45
|
+
H: [ "1?[0-9]|2[0-3]", Date.prototype.setHours, "hours", Date.prototype.getHours ],
|
46
|
+
HH: [ "0[0-9]|1[0-9]|2[0-3]", Date.prototype.setHours, "hours", function() {
|
47
|
+
return pad(Date.prototype.getHours.call(this), 2);
|
48
|
+
} ],
|
49
|
+
HHH: [ "[0-9]+", Date.prototype.setHours, "hours", Date.prototype.getHours ],
|
50
|
+
M: [ "[1-5]?[0-9]", Date.prototype.setMinutes, "minutes", Date.prototype.getMinutes ],
|
51
|
+
MM: [ "0[0-9]|1[0-9]|2[0-9]|3[0-9]|4[0-9]|5[0-9]", Date.prototype.setMinutes, "minutes", function() {
|
52
|
+
return pad(Date.prototype.getMinutes.call(this), 2);
|
53
|
+
} ],
|
54
|
+
ss: [ "[0-5][0-9]", Date.prototype.setSeconds, "seconds", function() {
|
55
|
+
return pad(Date.prototype.getSeconds.call(this), 2);
|
56
|
+
} ],
|
57
|
+
l: [ "[0-9]{3}", Date.prototype.setMilliseconds, "milliseconds", function() {
|
58
|
+
return pad(Date.prototype.getMilliseconds.call(this), 3);
|
59
|
+
} ],
|
60
|
+
L: [ "[0-9]{2}", Date.prototype.setMilliseconds, "milliseconds", function() {
|
61
|
+
return pad(Date.prototype.getMilliseconds.call(this), 2);
|
62
|
+
} ],
|
63
|
+
t: [ "[ap]" ],
|
64
|
+
tt: [ "[ap]m" ],
|
65
|
+
T: [ "[AP]" ],
|
66
|
+
TT: [ "[AP]M" ],
|
67
|
+
Z: [ "" ],
|
68
|
+
o: [ "" ],
|
69
|
+
S: [ "" ]
|
70
|
+
}, formatAlias = {
|
71
|
+
isoDate: "yyyy-mm-dd",
|
72
|
+
isoTime: "HH:MM:ss",
|
73
|
+
isoDateTime: "yyyy-mm-dd'T'HH:MM:ss",
|
74
|
+
isoUtcDateTime: "UTC:yyyy-mm-dd'T'HH:MM:ss'Z'"
|
75
|
+
};
|
76
|
+
function getTokenizer(opts) {
|
77
|
+
if (!opts.tokenizer) {
|
78
|
+
var tokens = [];
|
79
|
+
for (var ndx in formatCode) {
|
80
|
+
if (tokens.indexOf(ndx[0]) === -1) tokens.push(ndx[0]);
|
81
|
+
}
|
82
|
+
opts.tokenizer = "(" + tokens.join("+|") + ")+?|.";
|
83
|
+
opts.tokenizer = new RegExp(opts.tokenizer, "g");
|
84
|
+
}
|
85
|
+
return opts.tokenizer;
|
86
|
+
}
|
87
|
+
function isValidDate(dateParts, currentResult) {
|
88
|
+
return !isFinite(dateParts.rawday) || dateParts.day == "29" && !isFinite(dateParts.rawyear) || new Date(dateParts.date.getFullYear(), isFinite(dateParts.rawmonth) ? dateParts.month : dateParts.date.getMonth() + 1, 0).getDate() >= dateParts.day ? currentResult : false;
|
89
|
+
}
|
90
|
+
function isDateInRange(dateParts, opts) {
|
91
|
+
var result = true;
|
92
|
+
if (opts.min) {
|
93
|
+
if (dateParts["rawyear"]) {
|
94
|
+
var rawYear = dateParts["rawyear"].replace(/[^0-9]/g, ""), minYear = opts.min.year.substr(0, rawYear.length);
|
95
|
+
result = minYear <= rawYear;
|
96
|
+
}
|
97
|
+
if (dateParts["year"] === dateParts["rawyear"]) {
|
98
|
+
if (opts.min.date.getTime() === opts.min.date.getTime()) {
|
99
|
+
result = opts.min.date.getTime() <= dateParts.date.getTime();
|
100
|
+
}
|
101
|
+
}
|
102
|
+
}
|
103
|
+
if (result && opts.max && opts.max.date.getTime() === opts.max.date.getTime()) {
|
104
|
+
result = opts.max.date.getTime() >= dateParts.date.getTime();
|
105
|
+
}
|
106
|
+
return result;
|
107
|
+
}
|
108
|
+
function parse(format, dateObjValue, opts, raw) {
|
109
|
+
var mask = "", match;
|
110
|
+
while (match = getTokenizer(opts).exec(format)) {
|
111
|
+
if (dateObjValue === undefined) {
|
112
|
+
if (formatCode[match[0]]) {
|
113
|
+
mask += "(" + formatCode[match[0]][0] + ")";
|
114
|
+
} else {
|
115
|
+
switch (match[0]) {
|
116
|
+
case "[":
|
117
|
+
mask += "(";
|
118
|
+
break;
|
119
|
+
|
120
|
+
case "]":
|
121
|
+
mask += ")?";
|
122
|
+
break;
|
123
|
+
|
124
|
+
default:
|
125
|
+
mask += Inputmask.escapeRegex(match[0]);
|
126
|
+
}
|
127
|
+
}
|
128
|
+
} else {
|
129
|
+
if (formatCode[match[0]]) {
|
130
|
+
if (raw !== true && formatCode[match[0]][3]) {
|
131
|
+
var getFn = formatCode[match[0]][3];
|
132
|
+
mask += getFn.call(dateObjValue.date);
|
133
|
+
} else if (formatCode[match[0]][2]) mask += dateObjValue["raw" + formatCode[match[0]][2]]; else mask += match[0];
|
134
|
+
} else mask += match[0];
|
135
|
+
}
|
136
|
+
}
|
137
|
+
return mask;
|
138
|
+
}
|
139
|
+
function pad(val, len) {
|
140
|
+
val = String(val);
|
141
|
+
len = len || 2;
|
142
|
+
while (val.length < len) val = "0" + val;
|
143
|
+
return val;
|
144
|
+
}
|
145
|
+
function analyseMask(maskString, format, opts) {
|
146
|
+
var dateObj = {
|
147
|
+
date: new Date(1, 0, 1)
|
148
|
+
}, targetProp, mask = maskString, match, dateOperation, targetValidator;
|
149
|
+
function extendProperty(value) {
|
150
|
+
var correctedValue = value.replace(/[^0-9]/g, "0");
|
151
|
+
if (correctedValue != value) {
|
152
|
+
var enteredPart = value.replace(/[^0-9]/g, ""), min = (opts.min && opts.min[targetProp] || value).toString(), max = (opts.max && opts.max[targetProp] || value).toString();
|
153
|
+
correctedValue = enteredPart + (enteredPart < min.slice(0, enteredPart.length) ? min.slice(enteredPart.length) : enteredPart > max.slice(0, enteredPart.length) ? max.slice(enteredPart.length) : correctedValue.toString().slice(enteredPart.length));
|
154
|
+
}
|
155
|
+
return correctedValue;
|
156
|
+
}
|
157
|
+
function setValue(dateObj, value, opts) {
|
158
|
+
dateObj[targetProp] = extendProperty(value);
|
159
|
+
dateObj["raw" + targetProp] = value;
|
160
|
+
if (dateOperation !== undefined) dateOperation.call(dateObj.date, targetProp == "month" ? parseInt(dateObj[targetProp]) - 1 : dateObj[targetProp]);
|
161
|
+
}
|
162
|
+
if (typeof mask === "string") {
|
163
|
+
while (match = getTokenizer(opts).exec(format)) {
|
164
|
+
var value = mask.slice(0, match[0].length);
|
165
|
+
if (formatCode.hasOwnProperty(match[0])) {
|
166
|
+
targetValidator = formatCode[match[0]][0];
|
167
|
+
targetProp = formatCode[match[0]][2];
|
168
|
+
dateOperation = formatCode[match[0]][1];
|
169
|
+
setValue(dateObj, value, opts);
|
170
|
+
}
|
171
|
+
mask = mask.slice(value.length);
|
172
|
+
}
|
173
|
+
return dateObj;
|
174
|
+
} else if (mask && typeof mask === "object" && mask.hasOwnProperty("date")) {
|
175
|
+
return mask;
|
176
|
+
}
|
177
|
+
return undefined;
|
178
|
+
}
|
179
|
+
Inputmask.extendAliases({
|
180
|
+
datetime: {
|
181
|
+
mask: function(opts) {
|
182
|
+
formatCode.S = opts.i18n.ordinalSuffix.join("|");
|
183
|
+
opts.inputFormat = formatAlias[opts.inputFormat] || opts.inputFormat;
|
184
|
+
opts.displayFormat = formatAlias[opts.displayFormat] || opts.displayFormat || opts.inputFormat;
|
185
|
+
opts.outputFormat = formatAlias[opts.outputFormat] || opts.outputFormat || opts.inputFormat;
|
186
|
+
opts.placeholder = opts.placeholder !== "" ? opts.placeholder : opts.inputFormat.replace(/[\[\]]/, "");
|
187
|
+
opts.regex = parse(opts.inputFormat, undefined, opts);
|
188
|
+
return null;
|
189
|
+
},
|
190
|
+
placeholder: "",
|
191
|
+
inputFormat: "isoDateTime",
|
192
|
+
displayFormat: undefined,
|
193
|
+
outputFormat: undefined,
|
194
|
+
min: null,
|
195
|
+
max: null,
|
196
|
+
i18n: {
|
197
|
+
dayNames: [ "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" ],
|
198
|
+
monthNames: [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ],
|
199
|
+
ordinalSuffix: [ "st", "nd", "rd", "th" ]
|
200
|
+
},
|
201
|
+
postValidation: function(buffer, pos, currentResult, opts) {
|
202
|
+
opts.min = analyseMask(opts.min, opts.inputFormat, opts);
|
203
|
+
opts.max = analyseMask(opts.max, opts.inputFormat, opts);
|
204
|
+
var result = currentResult, dateParts = analyseMask(buffer.join(""), opts.inputFormat, opts);
|
205
|
+
if (result && dateParts.date.getTime() === dateParts.date.getTime()) {
|
206
|
+
result = isValidDate(dateParts, result);
|
207
|
+
result = result && isDateInRange(dateParts, opts);
|
208
|
+
}
|
209
|
+
if (pos && result && currentResult.pos !== pos) {
|
210
|
+
return {
|
211
|
+
buffer: parse(opts.inputFormat, dateParts, opts),
|
212
|
+
refreshFromBuffer: {
|
213
|
+
start: pos,
|
214
|
+
end: currentResult.pos
|
215
|
+
}
|
216
|
+
};
|
217
|
+
}
|
218
|
+
return result;
|
219
|
+
},
|
220
|
+
onKeyDown: function(e, buffer, caretPos, opts) {
|
221
|
+
var input = this;
|
222
|
+
if (e.ctrlKey && e.keyCode === Inputmask.keyCode.RIGHT) {
|
223
|
+
var today = new Date(), match, date = "";
|
224
|
+
while (match = getTokenizer(opts).exec(opts.inputFormat)) {
|
225
|
+
if (match[0].charAt(0) === "d") {
|
226
|
+
date += pad(today.getDate(), match[0].length);
|
227
|
+
} else if (match[0].charAt(0) === "m") {
|
228
|
+
date += pad(today.getMonth() + 1, match[0].length);
|
229
|
+
} else if (match[0] === "yyyy") {
|
230
|
+
date += today.getFullYear().toString();
|
231
|
+
} else if (match[0].charAt(0) === "y") {
|
232
|
+
date += pad(today.getYear(), match[0].length);
|
233
|
+
}
|
234
|
+
}
|
235
|
+
input.inputmask._valueSet(date);
|
236
|
+
$(input).trigger("setvalue");
|
237
|
+
}
|
238
|
+
},
|
239
|
+
onUnMask: function(maskedValue, unmaskedValue, opts) {
|
240
|
+
return parse(opts.outputFormat, analyseMask(maskedValue, opts.inputFormat, opts), opts, true);
|
241
|
+
},
|
242
|
+
casing: function(elem, test, pos, validPositions) {
|
243
|
+
if (test.nativeDef.indexOf("[ap]") == 0) return elem.toLowerCase();
|
244
|
+
if (test.nativeDef.indexOf("[AP]") == 0) return elem.toUpperCase();
|
245
|
+
return elem;
|
246
|
+
},
|
247
|
+
insertMode: false,
|
248
|
+
shiftPositions: false
|
249
|
+
}
|
250
|
+
});
|
251
|
+
return Inputmask;
|
252
|
+
});
|
@@ -0,0 +1 @@
|
|
1
|
+
404: Not Found
|
@@ -0,0 +1,97 @@
|
|
1
|
+
/*!
|
2
|
+
* inputmask.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
|
+
Inputmask.extendDefinitions({
|
19
|
+
A: {
|
20
|
+
validator: "[A-Za-z\u0410-\u044f\u0401\u0451\xc0-\xff\xb5]",
|
21
|
+
casing: "upper"
|
22
|
+
},
|
23
|
+
"&": {
|
24
|
+
validator: "[0-9A-Za-z\u0410-\u044f\u0401\u0451\xc0-\xff\xb5]",
|
25
|
+
casing: "upper"
|
26
|
+
},
|
27
|
+
"#": {
|
28
|
+
validator: "[0-9A-Fa-f]",
|
29
|
+
casing: "upper"
|
30
|
+
}
|
31
|
+
});
|
32
|
+
Inputmask.extendAliases({
|
33
|
+
cssunit: {
|
34
|
+
regex: "[+-]?[0-9]+\\.?([0-9]+)?(px|em|rem|ex|%|in|cm|mm|pt|pc)"
|
35
|
+
},
|
36
|
+
url: {
|
37
|
+
regex: "(https?|ftp)//.*",
|
38
|
+
autoUnmask: false
|
39
|
+
},
|
40
|
+
ip: {
|
41
|
+
mask: "i[i[i]].i[i[i]].i[i[i]].i[i[i]]",
|
42
|
+
definitions: {
|
43
|
+
i: {
|
44
|
+
validator: function(chrs, maskset, pos, strict, opts) {
|
45
|
+
if (pos - 1 > -1 && maskset.buffer[pos - 1] !== ".") {
|
46
|
+
chrs = maskset.buffer[pos - 1] + chrs;
|
47
|
+
if (pos - 2 > -1 && maskset.buffer[pos - 2] !== ".") {
|
48
|
+
chrs = maskset.buffer[pos - 2] + chrs;
|
49
|
+
} else chrs = "0" + chrs;
|
50
|
+
} else chrs = "00" + chrs;
|
51
|
+
return new RegExp("25[0-5]|2[0-4][0-9]|[01][0-9][0-9]").test(chrs);
|
52
|
+
}
|
53
|
+
}
|
54
|
+
},
|
55
|
+
onUnMask: function(maskedValue, unmaskedValue, opts) {
|
56
|
+
return maskedValue;
|
57
|
+
},
|
58
|
+
inputmode: "numeric"
|
59
|
+
},
|
60
|
+
email: {
|
61
|
+
mask: "*{1,64}[.*{1,64}][.*{1,64}][.*{1,63}]@-{1,63}.-{1,63}[.-{1,63}][.-{1,63}]",
|
62
|
+
greedy: false,
|
63
|
+
casing: "lower",
|
64
|
+
onBeforePaste: function(pastedValue, opts) {
|
65
|
+
pastedValue = pastedValue.toLowerCase();
|
66
|
+
return pastedValue.replace("mailto:", "");
|
67
|
+
},
|
68
|
+
definitions: {
|
69
|
+
"*": {
|
70
|
+
validator: "[0-9\uff11-\uff19A-Za-z\u0410-\u044f\u0401\u0451\xc0-\xff\xb5!#$%&'*+/=?^_`{|}~-]"
|
71
|
+
},
|
72
|
+
"-": {
|
73
|
+
validator: "[0-9A-Za-z-]"
|
74
|
+
}
|
75
|
+
},
|
76
|
+
onUnMask: function(maskedValue, unmaskedValue, opts) {
|
77
|
+
return maskedValue;
|
78
|
+
},
|
79
|
+
inputmode: "email"
|
80
|
+
},
|
81
|
+
mac: {
|
82
|
+
mask: "##:##:##:##:##:##"
|
83
|
+
},
|
84
|
+
vin: {
|
85
|
+
mask: "V{13}9{4}",
|
86
|
+
definitions: {
|
87
|
+
V: {
|
88
|
+
validator: "[A-HJ-NPR-Za-hj-npr-z\\d]",
|
89
|
+
casing: "upper"
|
90
|
+
}
|
91
|
+
},
|
92
|
+
clearIncomplete: true,
|
93
|
+
autoUnmask: true
|
94
|
+
}
|
95
|
+
});
|
96
|
+
return Inputmask;
|
97
|
+
});
|
@@ -0,0 +1 @@
|
|
1
|
+
404: Not Found
|
@@ -0,0 +1,2745 @@
|
|
1
|
+
/*!
|
2
|
+
* inputmask.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([ "./dependencyLibs/inputmask.dependencyLib", "./global/window" ], factory);
|
12
|
+
} else if (typeof exports === "object") {
|
13
|
+
module.exports = factory(require("./dependencyLibs/inputmask.dependencyLib"), require("./global/window"));
|
14
|
+
} else {
|
15
|
+
window.Inputmask = factory(window.dependencyLib || jQuery, window);
|
16
|
+
}
|
17
|
+
})(function($, window, undefined) {
|
18
|
+
var document = window.document, ua = navigator.userAgent, ie = ua.indexOf("MSIE ") > 0 || ua.indexOf("Trident/") > 0, mobile = isInputEventSupported("touchstart"), iemobile = /iemobile/i.test(ua), iphone = /iphone/i.test(ua) && !iemobile;
|
19
|
+
function Inputmask(alias, options, internal) {
|
20
|
+
if (!(this instanceof Inputmask)) {
|
21
|
+
return new Inputmask(alias, options, internal);
|
22
|
+
}
|
23
|
+
this.el = undefined;
|
24
|
+
this.events = {};
|
25
|
+
this.maskset = undefined;
|
26
|
+
this.refreshValue = false;
|
27
|
+
if (internal !== true) {
|
28
|
+
if ($.isPlainObject(alias)) {
|
29
|
+
options = alias;
|
30
|
+
} else {
|
31
|
+
options = options || {};
|
32
|
+
if (alias) options.alias = alias;
|
33
|
+
}
|
34
|
+
this.opts = $.extend(true, {}, this.defaults, options);
|
35
|
+
this.noMasksCache = options && options.definitions !== undefined;
|
36
|
+
this.userOptions = options || {};
|
37
|
+
this.isRTL = this.opts.numericInput;
|
38
|
+
resolveAlias(this.opts.alias, options, this.opts);
|
39
|
+
}
|
40
|
+
}
|
41
|
+
Inputmask.prototype = {
|
42
|
+
dataAttribute: "data-inputmask",
|
43
|
+
defaults: {
|
44
|
+
placeholder: "_",
|
45
|
+
optionalmarker: [ "[", "]" ],
|
46
|
+
quantifiermarker: [ "{", "}" ],
|
47
|
+
groupmarker: [ "(", ")" ],
|
48
|
+
alternatormarker: "|",
|
49
|
+
escapeChar: "\\",
|
50
|
+
mask: null,
|
51
|
+
regex: null,
|
52
|
+
oncomplete: $.noop,
|
53
|
+
onincomplete: $.noop,
|
54
|
+
oncleared: $.noop,
|
55
|
+
repeat: 0,
|
56
|
+
greedy: false,
|
57
|
+
autoUnmask: false,
|
58
|
+
removeMaskOnSubmit: false,
|
59
|
+
clearMaskOnLostFocus: true,
|
60
|
+
insertMode: true,
|
61
|
+
clearIncomplete: false,
|
62
|
+
alias: null,
|
63
|
+
onKeyDown: $.noop,
|
64
|
+
onBeforeMask: null,
|
65
|
+
onBeforePaste: function(pastedValue, opts) {
|
66
|
+
return $.isFunction(opts.onBeforeMask) ? opts.onBeforeMask.call(this, pastedValue, opts) : pastedValue;
|
67
|
+
},
|
68
|
+
onBeforeWrite: null,
|
69
|
+
onUnMask: null,
|
70
|
+
showMaskOnFocus: true,
|
71
|
+
showMaskOnHover: true,
|
72
|
+
onKeyValidation: $.noop,
|
73
|
+
skipOptionalPartCharacter: " ",
|
74
|
+
numericInput: false,
|
75
|
+
rightAlign: false,
|
76
|
+
undoOnEscape: true,
|
77
|
+
radixPoint: "",
|
78
|
+
_radixDance: false,
|
79
|
+
groupSeparator: "",
|
80
|
+
keepStatic: null,
|
81
|
+
positionCaretOnTab: true,
|
82
|
+
tabThrough: false,
|
83
|
+
supportsInputType: [ "text", "tel", "url", "password", "search" ],
|
84
|
+
ignorables: [ 8, 9, 13, 19, 27, 33, 34, 35, 36, 37, 38, 39, 40, 45, 46, 93, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 0, 229 ],
|
85
|
+
isComplete: null,
|
86
|
+
preValidation: null,
|
87
|
+
postValidation: null,
|
88
|
+
staticDefinitionSymbol: undefined,
|
89
|
+
jitMasking: false,
|
90
|
+
nullable: true,
|
91
|
+
inputEventOnly: false,
|
92
|
+
noValuePatching: false,
|
93
|
+
positionCaretOnClick: "lvp",
|
94
|
+
casing: null,
|
95
|
+
inputmode: "verbatim",
|
96
|
+
colorMask: false,
|
97
|
+
disablePredictiveText: false,
|
98
|
+
importDataAttributes: true,
|
99
|
+
shiftPositions: true
|
100
|
+
},
|
101
|
+
definitions: {
|
102
|
+
9: {
|
103
|
+
validator: "[0-9\uff11-\uff19]",
|
104
|
+
definitionSymbol: "*"
|
105
|
+
},
|
106
|
+
a: {
|
107
|
+
validator: "[A-Za-z\u0410-\u044f\u0401\u0451\xc0-\xff\xb5]",
|
108
|
+
definitionSymbol: "*"
|
109
|
+
},
|
110
|
+
"*": {
|
111
|
+
validator: "[0-9\uff11-\uff19A-Za-z\u0410-\u044f\u0401\u0451\xc0-\xff\xb5]"
|
112
|
+
}
|
113
|
+
},
|
114
|
+
aliases: {},
|
115
|
+
masksCache: {},
|
116
|
+
mask: function(elems) {
|
117
|
+
var that = this;
|
118
|
+
function importAttributeOptions(npt, opts, userOptions, dataAttribute) {
|
119
|
+
if (opts.importDataAttributes === true) {
|
120
|
+
var attrOptions = npt.getAttribute(dataAttribute), option, dataoptions, optionData, p;
|
121
|
+
var importOption = function(option, optionData) {
|
122
|
+
optionData = optionData !== undefined ? optionData : npt.getAttribute(dataAttribute + "-" + option);
|
123
|
+
if (optionData !== null) {
|
124
|
+
if (typeof optionData === "string") {
|
125
|
+
if (option.indexOf("on") === 0) optionData = window[optionData]; else if (optionData === "false") optionData = false; else if (optionData === "true") optionData = true;
|
126
|
+
}
|
127
|
+
userOptions[option] = optionData;
|
128
|
+
}
|
129
|
+
};
|
130
|
+
if (attrOptions && attrOptions !== "") {
|
131
|
+
attrOptions = attrOptions.replace(/'/g, '"');
|
132
|
+
dataoptions = JSON.parse("{" + attrOptions + "}");
|
133
|
+
}
|
134
|
+
if (dataoptions) {
|
135
|
+
optionData = undefined;
|
136
|
+
for (p in dataoptions) {
|
137
|
+
if (p.toLowerCase() === "alias") {
|
138
|
+
optionData = dataoptions[p];
|
139
|
+
break;
|
140
|
+
}
|
141
|
+
}
|
142
|
+
}
|
143
|
+
importOption("alias", optionData);
|
144
|
+
if (userOptions.alias) {
|
145
|
+
resolveAlias(userOptions.alias, userOptions, opts);
|
146
|
+
}
|
147
|
+
for (option in opts) {
|
148
|
+
if (dataoptions) {
|
149
|
+
optionData = undefined;
|
150
|
+
for (p in dataoptions) {
|
151
|
+
if (p.toLowerCase() === option.toLowerCase()) {
|
152
|
+
optionData = dataoptions[p];
|
153
|
+
break;
|
154
|
+
}
|
155
|
+
}
|
156
|
+
}
|
157
|
+
importOption(option, optionData);
|
158
|
+
}
|
159
|
+
}
|
160
|
+
$.extend(true, opts, userOptions);
|
161
|
+
if (npt.dir === "rtl" || opts.rightAlign) {
|
162
|
+
npt.style.textAlign = "right";
|
163
|
+
}
|
164
|
+
if (npt.dir === "rtl" || opts.numericInput) {
|
165
|
+
npt.dir = "ltr";
|
166
|
+
npt.removeAttribute("dir");
|
167
|
+
opts.isRTL = true;
|
168
|
+
}
|
169
|
+
return Object.keys(userOptions).length;
|
170
|
+
}
|
171
|
+
if (typeof elems === "string") {
|
172
|
+
elems = document.getElementById(elems) || document.querySelectorAll(elems);
|
173
|
+
}
|
174
|
+
elems = elems.nodeName ? [ elems ] : elems;
|
175
|
+
$.each(elems, function(ndx, el) {
|
176
|
+
var scopedOpts = $.extend(true, {}, that.opts);
|
177
|
+
if (importAttributeOptions(el, scopedOpts, $.extend(true, {}, that.userOptions), that.dataAttribute)) {
|
178
|
+
var maskset = generateMaskSet(scopedOpts, that.noMasksCache);
|
179
|
+
if (maskset !== undefined) {
|
180
|
+
if (el.inputmask !== undefined) {
|
181
|
+
el.inputmask.opts.autoUnmask = true;
|
182
|
+
el.inputmask.remove();
|
183
|
+
}
|
184
|
+
el.inputmask = new Inputmask(undefined, undefined, true);
|
185
|
+
el.inputmask.opts = scopedOpts;
|
186
|
+
el.inputmask.noMasksCache = that.noMasksCache;
|
187
|
+
el.inputmask.userOptions = $.extend(true, {}, that.userOptions);
|
188
|
+
el.inputmask.isRTL = scopedOpts.isRTL || scopedOpts.numericInput;
|
189
|
+
el.inputmask.el = el;
|
190
|
+
el.inputmask.maskset = maskset;
|
191
|
+
$.data(el, "_inputmask_opts", scopedOpts);
|
192
|
+
maskScope.call(el.inputmask, {
|
193
|
+
action: "mask"
|
194
|
+
});
|
195
|
+
}
|
196
|
+
}
|
197
|
+
});
|
198
|
+
return elems && elems[0] ? elems[0].inputmask || this : this;
|
199
|
+
},
|
200
|
+
option: function(options, noremask) {
|
201
|
+
if (typeof options === "string") {
|
202
|
+
return this.opts[options];
|
203
|
+
} else if (typeof options === "object") {
|
204
|
+
$.extend(this.userOptions, options);
|
205
|
+
if (this.el && noremask !== true) {
|
206
|
+
this.mask(this.el);
|
207
|
+
}
|
208
|
+
return this;
|
209
|
+
}
|
210
|
+
},
|
211
|
+
unmaskedvalue: function(value) {
|
212
|
+
this.maskset = this.maskset || generateMaskSet(this.opts, this.noMasksCache);
|
213
|
+
return maskScope.call(this, {
|
214
|
+
action: "unmaskedvalue",
|
215
|
+
value: value
|
216
|
+
});
|
217
|
+
},
|
218
|
+
remove: function() {
|
219
|
+
return maskScope.call(this, {
|
220
|
+
action: "remove"
|
221
|
+
});
|
222
|
+
},
|
223
|
+
getemptymask: function() {
|
224
|
+
this.maskset = this.maskset || generateMaskSet(this.opts, this.noMasksCache);
|
225
|
+
return maskScope.call(this, {
|
226
|
+
action: "getemptymask"
|
227
|
+
});
|
228
|
+
},
|
229
|
+
hasMaskedValue: function() {
|
230
|
+
return !this.opts.autoUnmask;
|
231
|
+
},
|
232
|
+
isComplete: function() {
|
233
|
+
this.maskset = this.maskset || generateMaskSet(this.opts, this.noMasksCache);
|
234
|
+
return maskScope.call(this, {
|
235
|
+
action: "isComplete"
|
236
|
+
});
|
237
|
+
},
|
238
|
+
getmetadata: function() {
|
239
|
+
this.maskset = this.maskset || generateMaskSet(this.opts, this.noMasksCache);
|
240
|
+
return maskScope.call(this, {
|
241
|
+
action: "getmetadata"
|
242
|
+
});
|
243
|
+
},
|
244
|
+
isValid: function(value) {
|
245
|
+
this.maskset = this.maskset || generateMaskSet(this.opts, this.noMasksCache);
|
246
|
+
return maskScope.call(this, {
|
247
|
+
action: "isValid",
|
248
|
+
value: value
|
249
|
+
});
|
250
|
+
},
|
251
|
+
format: function(value, metadata) {
|
252
|
+
this.maskset = this.maskset || generateMaskSet(this.opts, this.noMasksCache);
|
253
|
+
return maskScope.call(this, {
|
254
|
+
action: "format",
|
255
|
+
value: value,
|
256
|
+
metadata: metadata
|
257
|
+
});
|
258
|
+
},
|
259
|
+
setValue: function(value) {
|
260
|
+
if (this.el) {
|
261
|
+
$(this.el).trigger("setvalue", [ value ]);
|
262
|
+
}
|
263
|
+
},
|
264
|
+
analyseMask: function(mask, regexMask, opts) {
|
265
|
+
var tokenizer = /(?:[?*+]|\{[0-9\+\*]+(?:,[0-9\+\*]*)?(?:\|[0-9\+\*]*)?\})|[^.?*+^${[]()|\\]+|./g, regexTokenizer = /\[\^?]?(?:[^\\\]]+|\\[\S\s]?)*]?|\\(?:0(?:[0-3][0-7]{0,2}|[4-7][0-7]?)?|[1-9][0-9]*|x[0-9A-Fa-f]{2}|u[0-9A-Fa-f]{4}|c[A-Za-z]|[\S\s]?)|\((?:\?[:=!]?)?|(?:[?*+]|\{[0-9]+(?:,[0-9]*)?\})\??|[^.?*+^${[()|\\]+|./g, escaped = false, currentToken = new MaskToken(), match, m, openenings = [], maskTokens = [], openingToken, currentOpeningToken, alternator, lastMatch, groupToken;
|
266
|
+
function MaskToken(isGroup, isOptional, isQuantifier, isAlternator) {
|
267
|
+
this.matches = [];
|
268
|
+
this.openGroup = isGroup || false;
|
269
|
+
this.alternatorGroup = false;
|
270
|
+
this.isGroup = isGroup || false;
|
271
|
+
this.isOptional = isOptional || false;
|
272
|
+
this.isQuantifier = isQuantifier || false;
|
273
|
+
this.isAlternator = isAlternator || false;
|
274
|
+
this.quantifier = {
|
275
|
+
min: 1,
|
276
|
+
max: 1
|
277
|
+
};
|
278
|
+
}
|
279
|
+
function insertTestDefinition(mtoken, element, position) {
|
280
|
+
position = position !== undefined ? position : mtoken.matches.length;
|
281
|
+
var prevMatch = mtoken.matches[position - 1];
|
282
|
+
if (regexMask) {
|
283
|
+
if (element.indexOf("[") === 0 || escaped && /\\d|\\s|\\w]/i.test(element) || element === ".") {
|
284
|
+
mtoken.matches.splice(position++, 0, {
|
285
|
+
fn: new RegExp(element, opts.casing ? "i" : ""),
|
286
|
+
optionality: false,
|
287
|
+
newBlockMarker: prevMatch === undefined ? "master" : prevMatch.def !== element,
|
288
|
+
casing: null,
|
289
|
+
def: element,
|
290
|
+
placeholder: undefined,
|
291
|
+
nativeDef: element
|
292
|
+
});
|
293
|
+
} else {
|
294
|
+
if (escaped) element = element[element.length - 1];
|
295
|
+
$.each(element.split(""), function(ndx, lmnt) {
|
296
|
+
prevMatch = mtoken.matches[position - 1];
|
297
|
+
mtoken.matches.splice(position++, 0, {
|
298
|
+
fn: null,
|
299
|
+
optionality: false,
|
300
|
+
newBlockMarker: prevMatch === undefined ? "master" : prevMatch.def !== lmnt && prevMatch.fn !== null,
|
301
|
+
casing: null,
|
302
|
+
def: opts.staticDefinitionSymbol || lmnt,
|
303
|
+
placeholder: opts.staticDefinitionSymbol !== undefined ? lmnt : undefined,
|
304
|
+
nativeDef: (escaped ? "'" : "") + lmnt
|
305
|
+
});
|
306
|
+
});
|
307
|
+
}
|
308
|
+
escaped = false;
|
309
|
+
} else {
|
310
|
+
var maskdef = (opts.definitions ? opts.definitions[element] : undefined) || Inputmask.prototype.definitions[element];
|
311
|
+
if (maskdef && !escaped) {
|
312
|
+
mtoken.matches.splice(position++, 0, {
|
313
|
+
fn: maskdef.validator ? typeof maskdef.validator == "string" ? new RegExp(maskdef.validator, opts.casing ? "i" : "") : new function() {
|
314
|
+
this.test = maskdef.validator;
|
315
|
+
}() : new RegExp("."),
|
316
|
+
optionality: false,
|
317
|
+
newBlockMarker: prevMatch === undefined ? "master" : prevMatch.def !== (maskdef.definitionSymbol || element),
|
318
|
+
casing: maskdef.casing,
|
319
|
+
def: maskdef.definitionSymbol || element,
|
320
|
+
placeholder: maskdef.placeholder,
|
321
|
+
nativeDef: element
|
322
|
+
});
|
323
|
+
} else {
|
324
|
+
mtoken.matches.splice(position++, 0, {
|
325
|
+
fn: null,
|
326
|
+
optionality: false,
|
327
|
+
newBlockMarker: prevMatch === undefined ? "master" : prevMatch.def !== element && prevMatch.fn !== null,
|
328
|
+
casing: null,
|
329
|
+
def: opts.staticDefinitionSymbol || element,
|
330
|
+
placeholder: opts.staticDefinitionSymbol !== undefined ? element : undefined,
|
331
|
+
nativeDef: (escaped ? "'" : "") + element
|
332
|
+
});
|
333
|
+
escaped = false;
|
334
|
+
}
|
335
|
+
}
|
336
|
+
}
|
337
|
+
function verifyGroupMarker(maskToken) {
|
338
|
+
if (maskToken && maskToken.matches) {
|
339
|
+
$.each(maskToken.matches, function(ndx, token) {
|
340
|
+
var nextToken = maskToken.matches[ndx + 1];
|
341
|
+
if ((nextToken === undefined || (nextToken.matches === undefined || nextToken.isQuantifier === false)) && token && token.isGroup) {
|
342
|
+
token.isGroup = false;
|
343
|
+
if (!regexMask) {
|
344
|
+
insertTestDefinition(token, opts.groupmarker[0], 0);
|
345
|
+
if (token.openGroup !== true) {
|
346
|
+
insertTestDefinition(token, opts.groupmarker[1]);
|
347
|
+
}
|
348
|
+
}
|
349
|
+
}
|
350
|
+
verifyGroupMarker(token);
|
351
|
+
});
|
352
|
+
}
|
353
|
+
}
|
354
|
+
function defaultCase() {
|
355
|
+
if (openenings.length > 0) {
|
356
|
+
currentOpeningToken = openenings[openenings.length - 1];
|
357
|
+
insertTestDefinition(currentOpeningToken, m);
|
358
|
+
if (currentOpeningToken.isAlternator) {
|
359
|
+
alternator = openenings.pop();
|
360
|
+
for (var mndx = 0; mndx < alternator.matches.length; mndx++) {
|
361
|
+
if (alternator.matches[mndx].isGroup) alternator.matches[mndx].isGroup = false;
|
362
|
+
}
|
363
|
+
if (openenings.length > 0) {
|
364
|
+
currentOpeningToken = openenings[openenings.length - 1];
|
365
|
+
currentOpeningToken.matches.push(alternator);
|
366
|
+
} else {
|
367
|
+
currentToken.matches.push(alternator);
|
368
|
+
}
|
369
|
+
}
|
370
|
+
} else {
|
371
|
+
insertTestDefinition(currentToken, m);
|
372
|
+
}
|
373
|
+
}
|
374
|
+
function reverseTokens(maskToken) {
|
375
|
+
function reverseStatic(st) {
|
376
|
+
if (st === opts.optionalmarker[0]) st = opts.optionalmarker[1]; else if (st === opts.optionalmarker[1]) st = opts.optionalmarker[0]; else if (st === opts.groupmarker[0]) st = opts.groupmarker[1]; else if (st === opts.groupmarker[1]) st = opts.groupmarker[0];
|
377
|
+
return st;
|
378
|
+
}
|
379
|
+
maskToken.matches = maskToken.matches.reverse();
|
380
|
+
for (var match in maskToken.matches) {
|
381
|
+
if (maskToken.matches.hasOwnProperty(match)) {
|
382
|
+
var intMatch = parseInt(match);
|
383
|
+
if (maskToken.matches[match].isQuantifier && maskToken.matches[intMatch + 1] && maskToken.matches[intMatch + 1].isGroup) {
|
384
|
+
var qt = maskToken.matches[match];
|
385
|
+
maskToken.matches.splice(match, 1);
|
386
|
+
maskToken.matches.splice(intMatch + 1, 0, qt);
|
387
|
+
}
|
388
|
+
if (maskToken.matches[match].matches !== undefined) {
|
389
|
+
maskToken.matches[match] = reverseTokens(maskToken.matches[match]);
|
390
|
+
} else {
|
391
|
+
maskToken.matches[match] = reverseStatic(maskToken.matches[match]);
|
392
|
+
}
|
393
|
+
}
|
394
|
+
}
|
395
|
+
return maskToken;
|
396
|
+
}
|
397
|
+
function groupify(matches) {
|
398
|
+
var groupToken = new MaskToken(true);
|
399
|
+
groupToken.openGroup = false;
|
400
|
+
groupToken.matches = matches;
|
401
|
+
return groupToken;
|
402
|
+
}
|
403
|
+
if (regexMask) {
|
404
|
+
opts.optionalmarker[0] = undefined;
|
405
|
+
opts.optionalmarker[1] = undefined;
|
406
|
+
}
|
407
|
+
while (match = regexMask ? regexTokenizer.exec(mask) : tokenizer.exec(mask)) {
|
408
|
+
m = match[0];
|
409
|
+
if (regexMask) {
|
410
|
+
switch (m.charAt(0)) {
|
411
|
+
case "?":
|
412
|
+
m = "{0,1}";
|
413
|
+
break;
|
414
|
+
|
415
|
+
case "+":
|
416
|
+
case "*":
|
417
|
+
m = "{" + m + "}";
|
418
|
+
break;
|
419
|
+
}
|
420
|
+
}
|
421
|
+
if (escaped) {
|
422
|
+
defaultCase();
|
423
|
+
continue;
|
424
|
+
}
|
425
|
+
switch (m.charAt(0)) {
|
426
|
+
case "(?=":
|
427
|
+
break;
|
428
|
+
|
429
|
+
case "(?!":
|
430
|
+
break;
|
431
|
+
|
432
|
+
case "(?<=":
|
433
|
+
break;
|
434
|
+
|
435
|
+
case "(?<!":
|
436
|
+
break;
|
437
|
+
|
438
|
+
case opts.escapeChar:
|
439
|
+
escaped = true;
|
440
|
+
if (regexMask) {
|
441
|
+
defaultCase();
|
442
|
+
}
|
443
|
+
break;
|
444
|
+
|
445
|
+
case opts.optionalmarker[1]:
|
446
|
+
case opts.groupmarker[1]:
|
447
|
+
openingToken = openenings.pop();
|
448
|
+
openingToken.openGroup = false;
|
449
|
+
if (openingToken !== undefined) {
|
450
|
+
if (openenings.length > 0) {
|
451
|
+
currentOpeningToken = openenings[openenings.length - 1];
|
452
|
+
currentOpeningToken.matches.push(openingToken);
|
453
|
+
if (currentOpeningToken.isAlternator) {
|
454
|
+
alternator = openenings.pop();
|
455
|
+
for (var mndx = 0; mndx < alternator.matches.length; mndx++) {
|
456
|
+
alternator.matches[mndx].isGroup = false;
|
457
|
+
alternator.matches[mndx].alternatorGroup = false;
|
458
|
+
}
|
459
|
+
if (openenings.length > 0) {
|
460
|
+
currentOpeningToken = openenings[openenings.length - 1];
|
461
|
+
currentOpeningToken.matches.push(alternator);
|
462
|
+
} else {
|
463
|
+
currentToken.matches.push(alternator);
|
464
|
+
}
|
465
|
+
}
|
466
|
+
} else {
|
467
|
+
currentToken.matches.push(openingToken);
|
468
|
+
}
|
469
|
+
} else defaultCase();
|
470
|
+
break;
|
471
|
+
|
472
|
+
case opts.optionalmarker[0]:
|
473
|
+
openenings.push(new MaskToken(false, true));
|
474
|
+
break;
|
475
|
+
|
476
|
+
case opts.groupmarker[0]:
|
477
|
+
openenings.push(new MaskToken(true));
|
478
|
+
break;
|
479
|
+
|
480
|
+
case opts.quantifiermarker[0]:
|
481
|
+
var quantifier = new MaskToken(false, false, true);
|
482
|
+
m = m.replace(/[{}]/g, "");
|
483
|
+
var mqj = m.split("|"), mq = mqj[0].split(","), mq0 = isNaN(mq[0]) ? mq[0] : parseInt(mq[0]), mq1 = mq.length === 1 ? mq0 : isNaN(mq[1]) ? mq[1] : parseInt(mq[1]);
|
484
|
+
if (mq0 === "*" || mq0 === "+") {
|
485
|
+
mq0 = mq1 === "*" ? 0 : 1;
|
486
|
+
}
|
487
|
+
quantifier.quantifier = {
|
488
|
+
min: mq0,
|
489
|
+
max: mq1,
|
490
|
+
jit: mqj[1]
|
491
|
+
};
|
492
|
+
var matches = openenings.length > 0 ? openenings[openenings.length - 1].matches : currentToken.matches;
|
493
|
+
match = matches.pop();
|
494
|
+
if (match.isAlternator) {
|
495
|
+
matches.push(match);
|
496
|
+
matches = match.matches;
|
497
|
+
var groupToken = new MaskToken(true);
|
498
|
+
var tmpMatch = matches.pop();
|
499
|
+
matches.push(groupToken);
|
500
|
+
matches = groupToken.matches;
|
501
|
+
match = tmpMatch;
|
502
|
+
}
|
503
|
+
if (!match.isGroup) {
|
504
|
+
match = groupify([ match ]);
|
505
|
+
}
|
506
|
+
matches.push(match);
|
507
|
+
matches.push(quantifier);
|
508
|
+
break;
|
509
|
+
|
510
|
+
case opts.alternatormarker:
|
511
|
+
var groupQuantifier = function(matches) {
|
512
|
+
var lastMatch = matches.pop();
|
513
|
+
if (lastMatch.isQuantifier) {
|
514
|
+
lastMatch = groupify([ matches.pop(), lastMatch ]);
|
515
|
+
}
|
516
|
+
return lastMatch;
|
517
|
+
};
|
518
|
+
if (openenings.length > 0) {
|
519
|
+
currentOpeningToken = openenings[openenings.length - 1];
|
520
|
+
var subToken = currentOpeningToken.matches[currentOpeningToken.matches.length - 1];
|
521
|
+
if (currentOpeningToken.openGroup && (subToken.matches === undefined || subToken.isGroup === false && subToken.isAlternator === false)) {
|
522
|
+
lastMatch = openenings.pop();
|
523
|
+
} else {
|
524
|
+
lastMatch = groupQuantifier(currentOpeningToken.matches);
|
525
|
+
}
|
526
|
+
} else {
|
527
|
+
lastMatch = groupQuantifier(currentToken.matches);
|
528
|
+
}
|
529
|
+
if (lastMatch.isAlternator) {
|
530
|
+
openenings.push(lastMatch);
|
531
|
+
} else {
|
532
|
+
if (lastMatch.alternatorGroup) {
|
533
|
+
alternator = openenings.pop();
|
534
|
+
lastMatch.alternatorGroup = false;
|
535
|
+
} else {
|
536
|
+
alternator = new MaskToken(false, false, false, true);
|
537
|
+
}
|
538
|
+
alternator.matches.push(lastMatch);
|
539
|
+
openenings.push(alternator);
|
540
|
+
if (lastMatch.openGroup) {
|
541
|
+
lastMatch.openGroup = false;
|
542
|
+
var alternatorGroup = new MaskToken(true);
|
543
|
+
alternatorGroup.alternatorGroup = true;
|
544
|
+
openenings.push(alternatorGroup);
|
545
|
+
}
|
546
|
+
}
|
547
|
+
break;
|
548
|
+
|
549
|
+
default:
|
550
|
+
defaultCase();
|
551
|
+
}
|
552
|
+
}
|
553
|
+
while (openenings.length > 0) {
|
554
|
+
openingToken = openenings.pop();
|
555
|
+
currentToken.matches.push(openingToken);
|
556
|
+
}
|
557
|
+
if (currentToken.matches.length > 0) {
|
558
|
+
verifyGroupMarker(currentToken);
|
559
|
+
maskTokens.push(currentToken);
|
560
|
+
}
|
561
|
+
if (opts.numericInput || opts.isRTL) {
|
562
|
+
reverseTokens(maskTokens[0]);
|
563
|
+
}
|
564
|
+
return maskTokens;
|
565
|
+
},
|
566
|
+
positionColorMask: function(input, template) {
|
567
|
+
input.style.left = template.offsetLeft + "px";
|
568
|
+
}
|
569
|
+
};
|
570
|
+
Inputmask.extendDefaults = function(options) {
|
571
|
+
$.extend(true, Inputmask.prototype.defaults, options);
|
572
|
+
};
|
573
|
+
Inputmask.extendDefinitions = function(definition) {
|
574
|
+
$.extend(true, Inputmask.prototype.definitions, definition);
|
575
|
+
};
|
576
|
+
Inputmask.extendAliases = function(alias) {
|
577
|
+
$.extend(true, Inputmask.prototype.aliases, alias);
|
578
|
+
};
|
579
|
+
Inputmask.format = function(value, options, metadata) {
|
580
|
+
return Inputmask(options).format(value, metadata);
|
581
|
+
};
|
582
|
+
Inputmask.unmask = function(value, options) {
|
583
|
+
return Inputmask(options).unmaskedvalue(value);
|
584
|
+
};
|
585
|
+
Inputmask.isValid = function(value, options) {
|
586
|
+
return Inputmask(options).isValid(value);
|
587
|
+
};
|
588
|
+
Inputmask.remove = function(elems) {
|
589
|
+
if (typeof elems === "string") {
|
590
|
+
elems = document.getElementById(elems) || document.querySelectorAll(elems);
|
591
|
+
}
|
592
|
+
elems = elems.nodeName ? [ elems ] : elems;
|
593
|
+
$.each(elems, function(ndx, el) {
|
594
|
+
if (el.inputmask) el.inputmask.remove();
|
595
|
+
});
|
596
|
+
};
|
597
|
+
Inputmask.setValue = function(elems, value) {
|
598
|
+
if (typeof elems === "string") {
|
599
|
+
elems = document.getElementById(elems) || document.querySelectorAll(elems);
|
600
|
+
}
|
601
|
+
elems = elems.nodeName ? [ elems ] : elems;
|
602
|
+
$.each(elems, function(ndx, el) {
|
603
|
+
if (el.inputmask) el.inputmask.setValue(value); else $(el).trigger("setvalue", [ value ]);
|
604
|
+
});
|
605
|
+
};
|
606
|
+
Inputmask.escapeRegex = function(str) {
|
607
|
+
var specials = [ "/", ".", "*", "+", "?", "|", "(", ")", "[", "]", "{", "}", "\\", "$", "^" ];
|
608
|
+
return str.replace(new RegExp("(\\" + specials.join("|\\") + ")", "gim"), "\\$1");
|
609
|
+
};
|
610
|
+
Inputmask.keyCode = {
|
611
|
+
BACKSPACE: 8,
|
612
|
+
BACKSPACE_SAFARI: 127,
|
613
|
+
DELETE: 46,
|
614
|
+
DOWN: 40,
|
615
|
+
END: 35,
|
616
|
+
ENTER: 13,
|
617
|
+
ESCAPE: 27,
|
618
|
+
HOME: 36,
|
619
|
+
INSERT: 45,
|
620
|
+
LEFT: 37,
|
621
|
+
PAGE_DOWN: 34,
|
622
|
+
PAGE_UP: 33,
|
623
|
+
RIGHT: 39,
|
624
|
+
SPACE: 32,
|
625
|
+
TAB: 9,
|
626
|
+
UP: 38,
|
627
|
+
X: 88,
|
628
|
+
CONTROL: 17
|
629
|
+
};
|
630
|
+
Inputmask.dependencyLib = $;
|
631
|
+
function resolveAlias(aliasStr, options, opts) {
|
632
|
+
var aliasDefinition = Inputmask.prototype.aliases[aliasStr];
|
633
|
+
if (aliasDefinition) {
|
634
|
+
if (aliasDefinition.alias) resolveAlias(aliasDefinition.alias, undefined, opts);
|
635
|
+
$.extend(true, opts, aliasDefinition);
|
636
|
+
$.extend(true, opts, options);
|
637
|
+
return true;
|
638
|
+
} else if (opts.mask === null) {
|
639
|
+
opts.mask = aliasStr;
|
640
|
+
}
|
641
|
+
return false;
|
642
|
+
}
|
643
|
+
function generateMaskSet(opts, nocache) {
|
644
|
+
function generateMask(mask, metadata, opts) {
|
645
|
+
var regexMask = false;
|
646
|
+
if (mask === null || mask === "") {
|
647
|
+
regexMask = opts.regex !== null;
|
648
|
+
if (regexMask) {
|
649
|
+
mask = opts.regex;
|
650
|
+
mask = mask.replace(/^(\^)(.*)(\$)$/, "$2");
|
651
|
+
} else {
|
652
|
+
regexMask = true;
|
653
|
+
mask = ".*";
|
654
|
+
}
|
655
|
+
}
|
656
|
+
if (mask.length === 1 && opts.greedy === false && opts.repeat !== 0) {
|
657
|
+
opts.placeholder = "";
|
658
|
+
}
|
659
|
+
if (opts.repeat > 0 || opts.repeat === "*" || opts.repeat === "+") {
|
660
|
+
var repeatStart = opts.repeat === "*" ? 0 : opts.repeat === "+" ? 1 : opts.repeat;
|
661
|
+
mask = opts.groupmarker[0] + mask + opts.groupmarker[1] + opts.quantifiermarker[0] + repeatStart + "," + opts.repeat + opts.quantifiermarker[1];
|
662
|
+
}
|
663
|
+
var masksetDefinition, maskdefKey = regexMask ? "regex_" + opts.regex : opts.numericInput ? mask.split("").reverse().join("") : mask;
|
664
|
+
if (Inputmask.prototype.masksCache[maskdefKey] === undefined || nocache === true) {
|
665
|
+
masksetDefinition = {
|
666
|
+
mask: mask,
|
667
|
+
maskToken: Inputmask.prototype.analyseMask(mask, regexMask, opts),
|
668
|
+
validPositions: {},
|
669
|
+
_buffer: undefined,
|
670
|
+
buffer: undefined,
|
671
|
+
tests: {},
|
672
|
+
excludes: {},
|
673
|
+
metadata: metadata,
|
674
|
+
maskLength: undefined,
|
675
|
+
jitOffset: {}
|
676
|
+
};
|
677
|
+
if (nocache !== true) {
|
678
|
+
Inputmask.prototype.masksCache[maskdefKey] = masksetDefinition;
|
679
|
+
masksetDefinition = $.extend(true, {}, Inputmask.prototype.masksCache[maskdefKey]);
|
680
|
+
}
|
681
|
+
} else masksetDefinition = $.extend(true, {}, Inputmask.prototype.masksCache[maskdefKey]);
|
682
|
+
return masksetDefinition;
|
683
|
+
}
|
684
|
+
var ms;
|
685
|
+
if ($.isFunction(opts.mask)) {
|
686
|
+
opts.mask = opts.mask(opts);
|
687
|
+
}
|
688
|
+
if ($.isArray(opts.mask)) {
|
689
|
+
if (opts.mask.length > 1) {
|
690
|
+
if (opts.keepStatic === null) {
|
691
|
+
opts.keepStatic = "auto";
|
692
|
+
for (var i = 0; i < opts.mask.length; i++) {
|
693
|
+
if (opts.mask[i].charAt(0) !== opts.mask[0].charAt(0)) {
|
694
|
+
opts.keepStatic = true;
|
695
|
+
break;
|
696
|
+
}
|
697
|
+
}
|
698
|
+
}
|
699
|
+
var altMask = opts.groupmarker[0];
|
700
|
+
$.each(opts.isRTL ? opts.mask.reverse() : opts.mask, function(ndx, msk) {
|
701
|
+
if (altMask.length > 1) {
|
702
|
+
altMask += opts.groupmarker[1] + opts.alternatormarker + opts.groupmarker[0];
|
703
|
+
}
|
704
|
+
if (msk.mask !== undefined && !$.isFunction(msk.mask)) {
|
705
|
+
altMask += msk.mask;
|
706
|
+
} else {
|
707
|
+
altMask += msk;
|
708
|
+
}
|
709
|
+
});
|
710
|
+
altMask += opts.groupmarker[1];
|
711
|
+
return generateMask(altMask, opts.mask, opts);
|
712
|
+
} else opts.mask = opts.mask.pop();
|
713
|
+
}
|
714
|
+
if (opts.mask && opts.mask.mask !== undefined && !$.isFunction(opts.mask.mask)) {
|
715
|
+
ms = generateMask(opts.mask.mask, opts.mask, opts);
|
716
|
+
} else {
|
717
|
+
ms = generateMask(opts.mask, opts.mask, opts);
|
718
|
+
}
|
719
|
+
return ms;
|
720
|
+
}
|
721
|
+
function isInputEventSupported(eventName) {
|
722
|
+
var el = document.createElement("input"), evName = "on" + eventName, isSupported = evName in el;
|
723
|
+
if (!isSupported) {
|
724
|
+
el.setAttribute(evName, "return;");
|
725
|
+
isSupported = typeof el[evName] === "function";
|
726
|
+
}
|
727
|
+
el = null;
|
728
|
+
return isSupported;
|
729
|
+
}
|
730
|
+
function maskScope(actionObj, maskset, opts) {
|
731
|
+
maskset = maskset || this.maskset;
|
732
|
+
opts = opts || this.opts;
|
733
|
+
var inputmask = this, el = this.el, isRTL = this.isRTL, undoValue, $el, skipKeyPressEvent = false, skipInputEvent = false, ignorable = false, maxLength, mouseEnter = false, colorMask, originalPlaceholder;
|
734
|
+
var getMaskTemplate = function(baseOnInput, minimalPos, includeMode, noJit, clearOptionalTail) {
|
735
|
+
var greedy = opts.greedy;
|
736
|
+
if (clearOptionalTail) opts.greedy = false;
|
737
|
+
minimalPos = minimalPos || 0;
|
738
|
+
var maskTemplate = [], ndxIntlzr, pos = 0, test, testPos, lvp = getLastValidPosition();
|
739
|
+
do {
|
740
|
+
if (baseOnInput === true && getMaskSet().validPositions[pos]) {
|
741
|
+
testPos = clearOptionalTail && getMaskSet().validPositions[pos].match.optionality === true && getMaskSet().validPositions[pos + 1] === undefined && (getMaskSet().validPositions[pos].generatedInput === true || getMaskSet().validPositions[pos].input == opts.skipOptionalPartCharacter && pos > 0) ? determineTestTemplate(pos, getTests(pos, ndxIntlzr, pos - 1)) : getMaskSet().validPositions[pos];
|
742
|
+
test = testPos.match;
|
743
|
+
ndxIntlzr = testPos.locator.slice();
|
744
|
+
maskTemplate.push(includeMode === true ? testPos.input : includeMode === false ? test.nativeDef : getPlaceholder(pos, test));
|
745
|
+
} else {
|
746
|
+
testPos = getTestTemplate(pos, ndxIntlzr, pos - 1);
|
747
|
+
test = testPos.match;
|
748
|
+
ndxIntlzr = testPos.locator.slice();
|
749
|
+
var jitMasking = noJit === true ? false : opts.jitMasking !== false ? opts.jitMasking : test.jit;
|
750
|
+
if (jitMasking === false || jitMasking === undefined || typeof jitMasking === "number" && isFinite(jitMasking) && jitMasking > pos) {
|
751
|
+
maskTemplate.push(includeMode === false ? test.nativeDef : getPlaceholder(pos, test));
|
752
|
+
}
|
753
|
+
}
|
754
|
+
if (opts.keepStatic === "auto") {
|
755
|
+
if (test.newBlockMarker && test.fn !== null) {
|
756
|
+
opts.keepStatic = pos - 1;
|
757
|
+
}
|
758
|
+
}
|
759
|
+
pos++;
|
760
|
+
} while ((maxLength === undefined || pos < maxLength) && (test.fn !== null || test.def !== "") || minimalPos > pos);
|
761
|
+
if (maskTemplate[maskTemplate.length - 1] === "") {
|
762
|
+
maskTemplate.pop();
|
763
|
+
}
|
764
|
+
if (includeMode !== false || getMaskSet().maskLength === undefined) getMaskSet().maskLength = pos - 1;
|
765
|
+
opts.greedy = greedy;
|
766
|
+
return maskTemplate;
|
767
|
+
};
|
768
|
+
function getMaskSet() {
|
769
|
+
return maskset;
|
770
|
+
}
|
771
|
+
function resetMaskSet(soft) {
|
772
|
+
var maskset = getMaskSet();
|
773
|
+
maskset.buffer = undefined;
|
774
|
+
if (soft !== true) {
|
775
|
+
maskset.validPositions = {};
|
776
|
+
maskset.p = 0;
|
777
|
+
}
|
778
|
+
}
|
779
|
+
function getLastValidPosition(closestTo, strict, validPositions) {
|
780
|
+
var before = -1, after = -1, valids = validPositions || getMaskSet().validPositions;
|
781
|
+
if (closestTo === undefined) closestTo = -1;
|
782
|
+
for (var posNdx in valids) {
|
783
|
+
var psNdx = parseInt(posNdx);
|
784
|
+
if (valids[psNdx] && (strict || valids[psNdx].generatedInput !== true)) {
|
785
|
+
if (psNdx <= closestTo) before = psNdx;
|
786
|
+
if (psNdx >= closestTo) after = psNdx;
|
787
|
+
}
|
788
|
+
}
|
789
|
+
return before === -1 || before == closestTo ? after : after == -1 ? before : closestTo - before < after - closestTo ? before : after;
|
790
|
+
}
|
791
|
+
function getDecisionTaker(tst) {
|
792
|
+
var decisionTaker = tst.locator[tst.alternation];
|
793
|
+
if (typeof decisionTaker == "string" && decisionTaker.length > 0) {
|
794
|
+
decisionTaker = decisionTaker.split(",")[0];
|
795
|
+
}
|
796
|
+
return decisionTaker !== undefined ? decisionTaker.toString() : "";
|
797
|
+
}
|
798
|
+
function getLocator(tst, align) {
|
799
|
+
var locator = (tst.alternation != undefined ? tst.mloc[getDecisionTaker(tst)] : tst.locator).join("");
|
800
|
+
if (locator !== "") while (locator.length < align) locator += "0";
|
801
|
+
return locator;
|
802
|
+
}
|
803
|
+
function determineTestTemplate(pos, tests) {
|
804
|
+
pos = pos > 0 ? pos - 1 : 0;
|
805
|
+
var altTest = getTest(pos), targetLocator = getLocator(altTest), tstLocator, closest, bestMatch;
|
806
|
+
for (var ndx = 0; ndx < tests.length; ndx++) {
|
807
|
+
var tst = tests[ndx];
|
808
|
+
tstLocator = getLocator(tst, targetLocator.length);
|
809
|
+
var distance = Math.abs(tstLocator - targetLocator);
|
810
|
+
if (closest === undefined || tstLocator !== "" && distance < closest || bestMatch && !opts.greedy && bestMatch.match.optionality && bestMatch.match.newBlockMarker === "master" && (!tst.match.optionality || !tst.match.newBlockMarker) || bestMatch && bestMatch.match.optionalQuantifier && !tst.match.optionalQuantifier) {
|
811
|
+
closest = distance;
|
812
|
+
bestMatch = tst;
|
813
|
+
}
|
814
|
+
}
|
815
|
+
return bestMatch;
|
816
|
+
}
|
817
|
+
function getTestTemplate(pos, ndxIntlzr, tstPs) {
|
818
|
+
return getMaskSet().validPositions[pos] || determineTestTemplate(pos, getTests(pos, ndxIntlzr ? ndxIntlzr.slice() : ndxIntlzr, tstPs));
|
819
|
+
}
|
820
|
+
function getTest(pos, tests) {
|
821
|
+
if (getMaskSet().validPositions[pos]) {
|
822
|
+
return getMaskSet().validPositions[pos];
|
823
|
+
}
|
824
|
+
return (tests || getTests(pos))[0];
|
825
|
+
}
|
826
|
+
function positionCanMatchDefinition(pos, def) {
|
827
|
+
var valid = false, tests = getTests(pos);
|
828
|
+
for (var tndx = 0; tndx < tests.length; tndx++) {
|
829
|
+
if (tests[tndx].match && tests[tndx].match.def === def) {
|
830
|
+
valid = true;
|
831
|
+
break;
|
832
|
+
}
|
833
|
+
}
|
834
|
+
return valid;
|
835
|
+
}
|
836
|
+
function getTests(pos, ndxIntlzr, tstPs) {
|
837
|
+
var maskTokens = getMaskSet().maskToken, testPos = ndxIntlzr ? tstPs : 0, ndxInitializer = ndxIntlzr ? ndxIntlzr.slice() : [ 0 ], matches = [], insertStop = false, latestMatch, cacheDependency = ndxIntlzr ? ndxIntlzr.join("") : "";
|
838
|
+
function resolveTestFromToken(maskToken, ndxInitializer, loopNdx, quantifierRecurse) {
|
839
|
+
function handleMatch(match, loopNdx, quantifierRecurse) {
|
840
|
+
function isFirstMatch(latestMatch, tokenGroup) {
|
841
|
+
var firstMatch = $.inArray(latestMatch, tokenGroup.matches) === 0;
|
842
|
+
if (!firstMatch) {
|
843
|
+
$.each(tokenGroup.matches, function(ndx, match) {
|
844
|
+
if (match.isQuantifier === true) firstMatch = isFirstMatch(latestMatch, tokenGroup.matches[ndx - 1]); else if (match.hasOwnProperty("matches")) firstMatch = isFirstMatch(latestMatch, match);
|
845
|
+
if (firstMatch) return false;
|
846
|
+
});
|
847
|
+
}
|
848
|
+
return firstMatch;
|
849
|
+
}
|
850
|
+
function resolveNdxInitializer(pos, alternateNdx, targetAlternation) {
|
851
|
+
var bestMatch, indexPos;
|
852
|
+
if (getMaskSet().tests[pos] || getMaskSet().validPositions[pos]) {
|
853
|
+
$.each(getMaskSet().tests[pos] || [ getMaskSet().validPositions[pos] ], function(ndx, lmnt) {
|
854
|
+
if (lmnt.mloc[alternateNdx]) {
|
855
|
+
bestMatch = lmnt;
|
856
|
+
return false;
|
857
|
+
}
|
858
|
+
var alternation = targetAlternation !== undefined ? targetAlternation : lmnt.alternation, ndxPos = lmnt.locator[alternation] !== undefined ? lmnt.locator[alternation].toString().indexOf(alternateNdx) : -1;
|
859
|
+
if ((indexPos === undefined || ndxPos < indexPos) && ndxPos !== -1) {
|
860
|
+
bestMatch = lmnt;
|
861
|
+
indexPos = ndxPos;
|
862
|
+
}
|
863
|
+
});
|
864
|
+
}
|
865
|
+
if (bestMatch) {
|
866
|
+
var bestMatchAltIndex = bestMatch.locator[bestMatch.alternation];
|
867
|
+
var locator = bestMatch.mloc[alternateNdx] || bestMatch.mloc[bestMatchAltIndex] || bestMatch.locator;
|
868
|
+
return locator.slice((targetAlternation !== undefined ? targetAlternation : bestMatch.alternation) + 1);
|
869
|
+
} else {
|
870
|
+
return targetAlternation !== undefined ? resolveNdxInitializer(pos, alternateNdx) : undefined;
|
871
|
+
}
|
872
|
+
}
|
873
|
+
function isSubsetOf(source, target) {
|
874
|
+
function expand(pattern) {
|
875
|
+
var expanded = [], start, end;
|
876
|
+
for (var i = 0, l = pattern.length; i < l; i++) {
|
877
|
+
if (pattern.charAt(i) === "-") {
|
878
|
+
end = pattern.charCodeAt(i + 1);
|
879
|
+
while (++start < end) expanded.push(String.fromCharCode(start));
|
880
|
+
} else {
|
881
|
+
start = pattern.charCodeAt(i);
|
882
|
+
expanded.push(pattern.charAt(i));
|
883
|
+
}
|
884
|
+
}
|
885
|
+
return expanded.join("");
|
886
|
+
}
|
887
|
+
if (opts.regex && source.match.fn !== null && target.match.fn !== null) {
|
888
|
+
return expand(target.match.def.replace(/[\[\]]/g, "")).indexOf(expand(source.match.def.replace(/[\[\]]/g, ""))) !== -1;
|
889
|
+
}
|
890
|
+
return source.match.def === target.match.nativeDef;
|
891
|
+
}
|
892
|
+
function staticCanMatchDefinition(source, target) {
|
893
|
+
var sloc = source.locator.slice(source.alternation).join(""), tloc = target.locator.slice(target.alternation).join(""), canMatch = sloc == tloc;
|
894
|
+
canMatch = canMatch && source.match.fn === null && target.match.fn !== null ? target.match.fn.test(source.match.def, getMaskSet(), pos, false, opts, false) : false;
|
895
|
+
return canMatch;
|
896
|
+
}
|
897
|
+
function setMergeLocators(targetMatch, altMatch) {
|
898
|
+
if (altMatch === undefined || targetMatch.alternation === altMatch.alternation && targetMatch.locator[targetMatch.alternation].toString().indexOf(altMatch.locator[altMatch.alternation]) === -1) {
|
899
|
+
targetMatch.mloc = targetMatch.mloc || {};
|
900
|
+
var locNdx = targetMatch.locator[targetMatch.alternation];
|
901
|
+
if (locNdx === undefined) targetMatch.alternation = undefined; else {
|
902
|
+
if (typeof locNdx === "string") locNdx = locNdx.split(",")[0];
|
903
|
+
if (targetMatch.mloc[locNdx] === undefined) targetMatch.mloc[locNdx] = targetMatch.locator.slice();
|
904
|
+
if (altMatch !== undefined) {
|
905
|
+
for (var ndx in altMatch.mloc) {
|
906
|
+
if (typeof ndx === "string") ndx = ndx.split(",")[0];
|
907
|
+
if (targetMatch.mloc[ndx] === undefined) targetMatch.mloc[ndx] = altMatch.mloc[ndx];
|
908
|
+
}
|
909
|
+
targetMatch.locator[targetMatch.alternation] = Object.keys(targetMatch.mloc).join(",");
|
910
|
+
}
|
911
|
+
return true;
|
912
|
+
}
|
913
|
+
}
|
914
|
+
return false;
|
915
|
+
}
|
916
|
+
if (testPos > 500 && quantifierRecurse !== undefined) {
|
917
|
+
throw "Inputmask: There is probably an error in your mask definition or in the code. Create an issue on github with an example of the mask you are using. " + getMaskSet().mask;
|
918
|
+
}
|
919
|
+
if (testPos === pos && match.matches === undefined) {
|
920
|
+
matches.push({
|
921
|
+
match: match,
|
922
|
+
locator: loopNdx.reverse(),
|
923
|
+
cd: cacheDependency,
|
924
|
+
mloc: {}
|
925
|
+
});
|
926
|
+
return true;
|
927
|
+
} else if (match.matches !== undefined) {
|
928
|
+
if (match.isGroup && quantifierRecurse !== match) {
|
929
|
+
match = handleMatch(maskToken.matches[$.inArray(match, maskToken.matches) + 1], loopNdx, quantifierRecurse);
|
930
|
+
if (match) return true;
|
931
|
+
} else if (match.isOptional) {
|
932
|
+
var optionalToken = match;
|
933
|
+
match = resolveTestFromToken(match, ndxInitializer, loopNdx, quantifierRecurse);
|
934
|
+
if (match) {
|
935
|
+
$.each(matches, function(ndx, mtch) {
|
936
|
+
mtch.match.optionality = true;
|
937
|
+
});
|
938
|
+
latestMatch = matches[matches.length - 1].match;
|
939
|
+
if (quantifierRecurse === undefined && isFirstMatch(latestMatch, optionalToken)) {
|
940
|
+
insertStop = true;
|
941
|
+
testPos = pos;
|
942
|
+
} else return true;
|
943
|
+
}
|
944
|
+
} else if (match.isAlternator) {
|
945
|
+
var alternateToken = match, malternateMatches = [], maltMatches, currentMatches = matches.slice(), loopNdxCnt = loopNdx.length;
|
946
|
+
var altIndex = ndxInitializer.length > 0 ? ndxInitializer.shift() : -1;
|
947
|
+
if (altIndex === -1 || typeof altIndex === "string") {
|
948
|
+
var currentPos = testPos, ndxInitializerClone = ndxInitializer.slice(), altIndexArr = [], amndx;
|
949
|
+
if (typeof altIndex == "string") {
|
950
|
+
altIndexArr = altIndex.split(",");
|
951
|
+
} else {
|
952
|
+
for (amndx = 0; amndx < alternateToken.matches.length; amndx++) {
|
953
|
+
altIndexArr.push(amndx.toString());
|
954
|
+
}
|
955
|
+
}
|
956
|
+
if (getMaskSet().excludes[pos]) {
|
957
|
+
var altIndexArrClone = altIndexArr.slice();
|
958
|
+
for (var i = 0, el = getMaskSet().excludes[pos].length; i < el; i++) {
|
959
|
+
altIndexArr.splice(altIndexArr.indexOf(getMaskSet().excludes[pos][i].toString()), 1);
|
960
|
+
}
|
961
|
+
if (altIndexArr.length === 0) {
|
962
|
+
getMaskSet().excludes[pos] = undefined;
|
963
|
+
altIndexArr = altIndexArrClone;
|
964
|
+
}
|
965
|
+
}
|
966
|
+
if (opts.keepStatic === true || isFinite(parseInt(opts.keepStatic)) && currentPos >= opts.keepStatic) altIndexArr = altIndexArr.slice(0, 1);
|
967
|
+
var unMatchedAlternation = false;
|
968
|
+
for (var ndx = 0; ndx < altIndexArr.length; ndx++) {
|
969
|
+
amndx = parseInt(altIndexArr[ndx]);
|
970
|
+
matches = [];
|
971
|
+
ndxInitializer = typeof altIndex === "string" ? resolveNdxInitializer(testPos, amndx, loopNdxCnt) || ndxInitializerClone.slice() : ndxInitializerClone.slice();
|
972
|
+
if (alternateToken.matches[amndx] && handleMatch(alternateToken.matches[amndx], [ amndx ].concat(loopNdx), quantifierRecurse)) match = true; else if (ndx === 0) {
|
973
|
+
unMatchedAlternation = true;
|
974
|
+
}
|
975
|
+
maltMatches = matches.slice();
|
976
|
+
testPos = currentPos;
|
977
|
+
matches = [];
|
978
|
+
for (var ndx1 = 0; ndx1 < maltMatches.length; ndx1++) {
|
979
|
+
var altMatch = maltMatches[ndx1], dropMatch = false;
|
980
|
+
altMatch.match.jit = altMatch.match.jit || unMatchedAlternation;
|
981
|
+
altMatch.alternation = altMatch.alternation || loopNdxCnt;
|
982
|
+
setMergeLocators(altMatch);
|
983
|
+
for (var ndx2 = 0; ndx2 < malternateMatches.length; ndx2++) {
|
984
|
+
var altMatch2 = malternateMatches[ndx2];
|
985
|
+
if (typeof altIndex !== "string" || altMatch.alternation !== undefined && $.inArray(altMatch.locator[altMatch.alternation].toString(), altIndexArr) !== -1) {
|
986
|
+
if (altMatch.match.nativeDef === altMatch2.match.nativeDef) {
|
987
|
+
dropMatch = true;
|
988
|
+
setMergeLocators(altMatch2, altMatch);
|
989
|
+
break;
|
990
|
+
} else if (isSubsetOf(altMatch, altMatch2)) {
|
991
|
+
if (setMergeLocators(altMatch, altMatch2)) {
|
992
|
+
dropMatch = true;
|
993
|
+
malternateMatches.splice(malternateMatches.indexOf(altMatch2), 0, altMatch);
|
994
|
+
}
|
995
|
+
break;
|
996
|
+
} else if (isSubsetOf(altMatch2, altMatch)) {
|
997
|
+
setMergeLocators(altMatch2, altMatch);
|
998
|
+
break;
|
999
|
+
} else if (staticCanMatchDefinition(altMatch, altMatch2)) {
|
1000
|
+
if (setMergeLocators(altMatch, altMatch2)) {
|
1001
|
+
dropMatch = true;
|
1002
|
+
malternateMatches.splice(malternateMatches.indexOf(altMatch2), 0, altMatch);
|
1003
|
+
}
|
1004
|
+
break;
|
1005
|
+
}
|
1006
|
+
}
|
1007
|
+
}
|
1008
|
+
if (!dropMatch) {
|
1009
|
+
malternateMatches.push(altMatch);
|
1010
|
+
}
|
1011
|
+
}
|
1012
|
+
}
|
1013
|
+
matches = currentMatches.concat(malternateMatches);
|
1014
|
+
testPos = pos;
|
1015
|
+
insertStop = matches.length > 0;
|
1016
|
+
match = malternateMatches.length > 0;
|
1017
|
+
ndxInitializer = ndxInitializerClone.slice();
|
1018
|
+
} else match = handleMatch(alternateToken.matches[altIndex] || maskToken.matches[altIndex], [ altIndex ].concat(loopNdx), quantifierRecurse);
|
1019
|
+
if (match) return true;
|
1020
|
+
} else if (match.isQuantifier && quantifierRecurse !== maskToken.matches[$.inArray(match, maskToken.matches) - 1]) {
|
1021
|
+
var qt = match;
|
1022
|
+
for (var qndx = ndxInitializer.length > 0 ? ndxInitializer.shift() : 0; qndx < (isNaN(qt.quantifier.max) ? qndx + 1 : qt.quantifier.max) && testPos <= pos; qndx++) {
|
1023
|
+
var tokenGroup = maskToken.matches[$.inArray(qt, maskToken.matches) - 1];
|
1024
|
+
match = handleMatch(tokenGroup, [ qndx ].concat(loopNdx), tokenGroup);
|
1025
|
+
if (match) {
|
1026
|
+
latestMatch = matches[matches.length - 1].match;
|
1027
|
+
latestMatch.optionalQuantifier = qndx >= qt.quantifier.min;
|
1028
|
+
latestMatch.jit = (qndx || 1) * tokenGroup.matches.indexOf(latestMatch) >= qt.quantifier.jit;
|
1029
|
+
if (latestMatch.optionalQuantifier && isFirstMatch(latestMatch, tokenGroup)) {
|
1030
|
+
insertStop = true;
|
1031
|
+
testPos = pos;
|
1032
|
+
break;
|
1033
|
+
}
|
1034
|
+
if (latestMatch.jit) {
|
1035
|
+
getMaskSet().jitOffset[pos] = tokenGroup.matches.indexOf(latestMatch);
|
1036
|
+
}
|
1037
|
+
return true;
|
1038
|
+
}
|
1039
|
+
}
|
1040
|
+
} else {
|
1041
|
+
match = resolveTestFromToken(match, ndxInitializer, loopNdx, quantifierRecurse);
|
1042
|
+
if (match) return true;
|
1043
|
+
}
|
1044
|
+
} else {
|
1045
|
+
testPos++;
|
1046
|
+
}
|
1047
|
+
}
|
1048
|
+
for (var tndx = ndxInitializer.length > 0 ? ndxInitializer.shift() : 0; tndx < maskToken.matches.length; tndx++) {
|
1049
|
+
if (maskToken.matches[tndx].isQuantifier !== true) {
|
1050
|
+
var match = handleMatch(maskToken.matches[tndx], [ tndx ].concat(loopNdx), quantifierRecurse);
|
1051
|
+
if (match && testPos === pos) {
|
1052
|
+
return match;
|
1053
|
+
} else if (testPos > pos) {
|
1054
|
+
break;
|
1055
|
+
}
|
1056
|
+
}
|
1057
|
+
}
|
1058
|
+
}
|
1059
|
+
function mergeLocators(pos, tests) {
|
1060
|
+
var locator = [];
|
1061
|
+
if (!$.isArray(tests)) tests = [ tests ];
|
1062
|
+
if (tests.length > 0) {
|
1063
|
+
if (tests[0].alternation === undefined) {
|
1064
|
+
locator = determineTestTemplate(pos, tests.slice()).locator.slice();
|
1065
|
+
if (locator.length === 0) locator = tests[0].locator.slice();
|
1066
|
+
} else {
|
1067
|
+
$.each(tests, function(ndx, tst) {
|
1068
|
+
if (tst.def !== "") {
|
1069
|
+
if (locator.length === 0) locator = tst.locator.slice(); else {
|
1070
|
+
for (var i = 0; i < locator.length; i++) {
|
1071
|
+
if (tst.locator[i] && locator[i].toString().indexOf(tst.locator[i]) === -1) {
|
1072
|
+
locator[i] += "," + tst.locator[i];
|
1073
|
+
}
|
1074
|
+
}
|
1075
|
+
}
|
1076
|
+
}
|
1077
|
+
});
|
1078
|
+
}
|
1079
|
+
}
|
1080
|
+
return locator;
|
1081
|
+
}
|
1082
|
+
if (pos > -1) {
|
1083
|
+
if (ndxIntlzr === undefined) {
|
1084
|
+
var previousPos = pos - 1, test;
|
1085
|
+
while ((test = getMaskSet().validPositions[previousPos] || getMaskSet().tests[previousPos]) === undefined && previousPos > -1) {
|
1086
|
+
previousPos--;
|
1087
|
+
}
|
1088
|
+
if (test !== undefined && previousPos > -1) {
|
1089
|
+
ndxInitializer = mergeLocators(previousPos, test);
|
1090
|
+
cacheDependency = ndxInitializer.join("");
|
1091
|
+
testPos = previousPos;
|
1092
|
+
}
|
1093
|
+
}
|
1094
|
+
if (getMaskSet().tests[pos] && getMaskSet().tests[pos][0].cd === cacheDependency) {
|
1095
|
+
return getMaskSet().tests[pos];
|
1096
|
+
}
|
1097
|
+
for (var mtndx = ndxInitializer.shift(); mtndx < maskTokens.length; mtndx++) {
|
1098
|
+
var match = resolveTestFromToken(maskTokens[mtndx], ndxInitializer, [ mtndx ]);
|
1099
|
+
if (match && testPos === pos || testPos > pos) {
|
1100
|
+
break;
|
1101
|
+
}
|
1102
|
+
}
|
1103
|
+
}
|
1104
|
+
if (matches.length === 0 || insertStop) {
|
1105
|
+
matches.push({
|
1106
|
+
match: {
|
1107
|
+
fn: null,
|
1108
|
+
optionality: false,
|
1109
|
+
casing: null,
|
1110
|
+
def: "",
|
1111
|
+
placeholder: ""
|
1112
|
+
},
|
1113
|
+
locator: [],
|
1114
|
+
mloc: {},
|
1115
|
+
cd: cacheDependency
|
1116
|
+
});
|
1117
|
+
}
|
1118
|
+
if (ndxIntlzr !== undefined && getMaskSet().tests[pos]) {
|
1119
|
+
return $.extend(true, [], matches);
|
1120
|
+
}
|
1121
|
+
getMaskSet().tests[pos] = $.extend(true, [], matches);
|
1122
|
+
return getMaskSet().tests[pos];
|
1123
|
+
}
|
1124
|
+
function getBufferTemplate() {
|
1125
|
+
if (getMaskSet()._buffer === undefined) {
|
1126
|
+
getMaskSet()._buffer = getMaskTemplate(false, 1);
|
1127
|
+
if (getMaskSet().buffer === undefined) getMaskSet().buffer = getMaskSet()._buffer.slice();
|
1128
|
+
}
|
1129
|
+
return getMaskSet()._buffer;
|
1130
|
+
}
|
1131
|
+
function getBuffer(noCache) {
|
1132
|
+
if (getMaskSet().buffer === undefined || noCache === true) {
|
1133
|
+
getMaskSet().buffer = getMaskTemplate(true, getLastValidPosition(), true);
|
1134
|
+
if (getMaskSet()._buffer === undefined) getMaskSet()._buffer = getMaskSet().buffer.slice();
|
1135
|
+
}
|
1136
|
+
return getMaskSet().buffer;
|
1137
|
+
}
|
1138
|
+
function refreshFromBuffer(start, end, buffer) {
|
1139
|
+
var i, p;
|
1140
|
+
if (start === true) {
|
1141
|
+
resetMaskSet();
|
1142
|
+
start = 0;
|
1143
|
+
end = buffer.length;
|
1144
|
+
} else {
|
1145
|
+
for (i = start; i < end; i++) {
|
1146
|
+
delete getMaskSet().validPositions[i];
|
1147
|
+
}
|
1148
|
+
}
|
1149
|
+
p = start;
|
1150
|
+
for (i = start; i < end; i++) {
|
1151
|
+
resetMaskSet(true);
|
1152
|
+
if (buffer[i] !== opts.skipOptionalPartCharacter) {
|
1153
|
+
var valResult = isValid(p, buffer[i], true, true);
|
1154
|
+
if (valResult !== false) {
|
1155
|
+
resetMaskSet(true);
|
1156
|
+
p = valResult.caret !== undefined ? valResult.caret : valResult.pos + 1;
|
1157
|
+
}
|
1158
|
+
}
|
1159
|
+
}
|
1160
|
+
}
|
1161
|
+
function casing(elem, test, pos) {
|
1162
|
+
switch (opts.casing || test.casing) {
|
1163
|
+
case "upper":
|
1164
|
+
elem = elem.toUpperCase();
|
1165
|
+
break;
|
1166
|
+
|
1167
|
+
case "lower":
|
1168
|
+
elem = elem.toLowerCase();
|
1169
|
+
break;
|
1170
|
+
|
1171
|
+
case "title":
|
1172
|
+
var posBefore = getMaskSet().validPositions[pos - 1];
|
1173
|
+
if (pos === 0 || posBefore && posBefore.input === String.fromCharCode(Inputmask.keyCode.SPACE)) {
|
1174
|
+
elem = elem.toUpperCase();
|
1175
|
+
} else {
|
1176
|
+
elem = elem.toLowerCase();
|
1177
|
+
}
|
1178
|
+
break;
|
1179
|
+
|
1180
|
+
default:
|
1181
|
+
if ($.isFunction(opts.casing)) {
|
1182
|
+
var args = Array.prototype.slice.call(arguments);
|
1183
|
+
args.push(getMaskSet().validPositions);
|
1184
|
+
elem = opts.casing.apply(this, args);
|
1185
|
+
}
|
1186
|
+
}
|
1187
|
+
return elem;
|
1188
|
+
}
|
1189
|
+
function checkAlternationMatch(altArr1, altArr2, na) {
|
1190
|
+
var altArrC = opts.greedy ? altArr2 : altArr2.slice(0, 1), isMatch = false, naArr = na !== undefined ? na.split(",") : [], naNdx;
|
1191
|
+
for (var i = 0; i < naArr.length; i++) {
|
1192
|
+
if ((naNdx = altArr1.indexOf(naArr[i])) !== -1) {
|
1193
|
+
altArr1.splice(naNdx, 1);
|
1194
|
+
}
|
1195
|
+
}
|
1196
|
+
for (var alndx = 0; alndx < altArr1.length; alndx++) {
|
1197
|
+
if ($.inArray(altArr1[alndx], altArrC) !== -1) {
|
1198
|
+
isMatch = true;
|
1199
|
+
break;
|
1200
|
+
}
|
1201
|
+
}
|
1202
|
+
return isMatch;
|
1203
|
+
}
|
1204
|
+
function alternate(pos, c, strict, fromSetValid, rAltPos) {
|
1205
|
+
var validPsClone = $.extend(true, {}, getMaskSet().validPositions), lastAlt, alternation, isValidRslt = false, altPos, prevAltPos, i, validPos, decisionPos, lAltPos = rAltPos !== undefined ? rAltPos : getLastValidPosition();
|
1206
|
+
if (lAltPos === -1 && rAltPos === undefined) {
|
1207
|
+
lastAlt = 0;
|
1208
|
+
prevAltPos = getTest(lastAlt);
|
1209
|
+
alternation = prevAltPos.alternation;
|
1210
|
+
} else {
|
1211
|
+
for (;lAltPos >= 0; lAltPos--) {
|
1212
|
+
altPos = getMaskSet().validPositions[lAltPos];
|
1213
|
+
if (altPos && altPos.alternation !== undefined) {
|
1214
|
+
if (prevAltPos && prevAltPos.locator[altPos.alternation] !== altPos.locator[altPos.alternation]) {
|
1215
|
+
break;
|
1216
|
+
}
|
1217
|
+
lastAlt = lAltPos;
|
1218
|
+
alternation = getMaskSet().validPositions[lastAlt].alternation;
|
1219
|
+
prevAltPos = altPos;
|
1220
|
+
}
|
1221
|
+
}
|
1222
|
+
}
|
1223
|
+
if (alternation !== undefined) {
|
1224
|
+
decisionPos = parseInt(lastAlt);
|
1225
|
+
getMaskSet().excludes[decisionPos] = getMaskSet().excludes[decisionPos] || [];
|
1226
|
+
if (pos !== true) {
|
1227
|
+
getMaskSet().excludes[decisionPos].push(getDecisionTaker(prevAltPos));
|
1228
|
+
}
|
1229
|
+
var validInputsClone = [], staticInputsBeforePos = 0;
|
1230
|
+
for (i = decisionPos; i < getLastValidPosition(undefined, true) + 1; i++) {
|
1231
|
+
validPos = getMaskSet().validPositions[i];
|
1232
|
+
if (validPos && validPos.generatedInput !== true) {
|
1233
|
+
validInputsClone.push(validPos.input);
|
1234
|
+
} else if (i < pos) staticInputsBeforePos++;
|
1235
|
+
delete getMaskSet().validPositions[i];
|
1236
|
+
}
|
1237
|
+
while (getMaskSet().excludes[decisionPos] && getMaskSet().excludes[decisionPos].length < 10) {
|
1238
|
+
var posOffset = staticInputsBeforePos * -1, validInputs = validInputsClone.slice();
|
1239
|
+
getMaskSet().tests[decisionPos] = undefined;
|
1240
|
+
resetMaskSet(true);
|
1241
|
+
isValidRslt = true;
|
1242
|
+
while (validInputs.length > 0) {
|
1243
|
+
var input = validInputs.shift();
|
1244
|
+
if (!(isValidRslt = isValid(getLastValidPosition(undefined, true) + 1, input, false, fromSetValid, true))) {
|
1245
|
+
break;
|
1246
|
+
}
|
1247
|
+
}
|
1248
|
+
if (isValidRslt && c !== undefined) {
|
1249
|
+
var targetLvp = getLastValidPosition(pos) + 1;
|
1250
|
+
for (i = decisionPos; i < getLastValidPosition() + 1; i++) {
|
1251
|
+
validPos = getMaskSet().validPositions[i];
|
1252
|
+
if ((validPos === undefined || validPos.match.fn == null) && i < pos + posOffset) {
|
1253
|
+
posOffset++;
|
1254
|
+
}
|
1255
|
+
}
|
1256
|
+
pos = pos + posOffset;
|
1257
|
+
isValidRslt = isValid(pos > targetLvp ? targetLvp : pos, c, strict, fromSetValid, true);
|
1258
|
+
}
|
1259
|
+
if (!isValidRslt) {
|
1260
|
+
resetMaskSet();
|
1261
|
+
prevAltPos = getTest(decisionPos);
|
1262
|
+
getMaskSet().validPositions = $.extend(true, {}, validPsClone);
|
1263
|
+
if (getMaskSet().excludes[decisionPos]) {
|
1264
|
+
var decisionTaker = getDecisionTaker(prevAltPos);
|
1265
|
+
if (getMaskSet().excludes[decisionPos].indexOf(decisionTaker) !== -1) {
|
1266
|
+
isValidRslt = alternate(pos, c, strict, fromSetValid, decisionPos - 1);
|
1267
|
+
break;
|
1268
|
+
}
|
1269
|
+
getMaskSet().excludes[decisionPos].push(decisionTaker);
|
1270
|
+
for (i = decisionPos; i < getLastValidPosition(undefined, true) + 1; i++) delete getMaskSet().validPositions[i];
|
1271
|
+
} else {
|
1272
|
+
isValidRslt = alternate(pos, c, strict, fromSetValid, decisionPos - 1);
|
1273
|
+
break;
|
1274
|
+
}
|
1275
|
+
} else break;
|
1276
|
+
}
|
1277
|
+
}
|
1278
|
+
getMaskSet().excludes[decisionPos] = undefined;
|
1279
|
+
return isValidRslt;
|
1280
|
+
}
|
1281
|
+
function isValid(pos, c, strict, fromSetValid, fromAlternate, validateOnly) {
|
1282
|
+
function isSelection(posObj) {
|
1283
|
+
return isRTL ? posObj.begin - posObj.end > 1 || posObj.begin - posObj.end === 1 : posObj.end - posObj.begin > 1 || posObj.end - posObj.begin === 1;
|
1284
|
+
}
|
1285
|
+
strict = strict === true;
|
1286
|
+
var maskPos = pos;
|
1287
|
+
if (pos.begin !== undefined) {
|
1288
|
+
maskPos = isRTL ? pos.end : pos.begin;
|
1289
|
+
}
|
1290
|
+
function _isValid(position, c, strict) {
|
1291
|
+
var rslt = false;
|
1292
|
+
$.each(getTests(position), function(ndx, tst) {
|
1293
|
+
var test = tst.match;
|
1294
|
+
getBuffer(true);
|
1295
|
+
rslt = test.fn != null ? test.fn.test(c, getMaskSet(), position, strict, opts, isSelection(pos)) : (c === test.def || c === opts.skipOptionalPartCharacter) && test.def !== "" ? {
|
1296
|
+
c: getPlaceholder(position, test, true) || test.def,
|
1297
|
+
pos: position
|
1298
|
+
} : false;
|
1299
|
+
if (rslt !== false) {
|
1300
|
+
var elem = rslt.c !== undefined ? rslt.c : c, validatedPos = position;
|
1301
|
+
elem = elem === opts.skipOptionalPartCharacter && test.fn === null ? getPlaceholder(position, test, true) || test.def : elem;
|
1302
|
+
if (rslt.remove !== undefined) {
|
1303
|
+
if (!$.isArray(rslt.remove)) rslt.remove = [ rslt.remove ];
|
1304
|
+
$.each(rslt.remove.sort(function(a, b) {
|
1305
|
+
return b - a;
|
1306
|
+
}), function(ndx, lmnt) {
|
1307
|
+
revalidateMask({
|
1308
|
+
begin: lmnt,
|
1309
|
+
end: lmnt + 1
|
1310
|
+
});
|
1311
|
+
});
|
1312
|
+
}
|
1313
|
+
if (rslt.insert !== undefined) {
|
1314
|
+
if (!$.isArray(rslt.insert)) rslt.insert = [ rslt.insert ];
|
1315
|
+
$.each(rslt.insert.sort(function(a, b) {
|
1316
|
+
return a - b;
|
1317
|
+
}), function(ndx, lmnt) {
|
1318
|
+
isValid(lmnt.pos, lmnt.c, true, fromSetValid);
|
1319
|
+
});
|
1320
|
+
}
|
1321
|
+
if (rslt !== true && rslt.pos !== undefined && rslt.pos !== position) {
|
1322
|
+
validatedPos = rslt.pos;
|
1323
|
+
}
|
1324
|
+
if (rslt !== true && rslt.pos === undefined && rslt.c === undefined) {
|
1325
|
+
return false;
|
1326
|
+
}
|
1327
|
+
if (!revalidateMask(pos, $.extend({}, tst, {
|
1328
|
+
input: casing(elem, test, validatedPos)
|
1329
|
+
}), fromSetValid, validatedPos)) {
|
1330
|
+
rslt = false;
|
1331
|
+
}
|
1332
|
+
return false;
|
1333
|
+
}
|
1334
|
+
});
|
1335
|
+
return rslt;
|
1336
|
+
}
|
1337
|
+
var result = true, positionsClone = $.extend(true, {}, getMaskSet().validPositions);
|
1338
|
+
if ($.isFunction(opts.preValidation) && !strict && fromSetValid !== true && validateOnly !== true) {
|
1339
|
+
result = opts.preValidation(getBuffer(), maskPos, c, isSelection(pos), opts, getMaskSet());
|
1340
|
+
}
|
1341
|
+
if (result === true) {
|
1342
|
+
trackbackPositions(undefined, maskPos, true);
|
1343
|
+
if (maxLength === undefined || maskPos < maxLength) {
|
1344
|
+
result = _isValid(maskPos, c, strict);
|
1345
|
+
if ((!strict || fromSetValid === true) && result === false && validateOnly !== true) {
|
1346
|
+
var currentPosValid = getMaskSet().validPositions[maskPos];
|
1347
|
+
if (currentPosValid && currentPosValid.match.fn === null && (currentPosValid.match.def === c || c === opts.skipOptionalPartCharacter)) {
|
1348
|
+
result = {
|
1349
|
+
caret: seekNext(maskPos)
|
1350
|
+
};
|
1351
|
+
} else {
|
1352
|
+
if ((opts.insertMode || getMaskSet().validPositions[seekNext(maskPos)] === undefined) && (!isMask(maskPos, true) || getMaskSet().jitOffset[maskPos])) {
|
1353
|
+
if (getMaskSet().jitOffset[maskPos] && getMaskSet().validPositions[seekNext(maskPos)] === undefined) {
|
1354
|
+
result = isValid(maskPos + getMaskSet().jitOffset[maskPos], c, strict);
|
1355
|
+
if (result !== false) result.caret = maskPos;
|
1356
|
+
} else for (var nPos = maskPos + 1, snPos = seekNext(maskPos); nPos <= snPos; nPos++) {
|
1357
|
+
result = _isValid(nPos, c, strict);
|
1358
|
+
if (result !== false) {
|
1359
|
+
result = trackbackPositions(maskPos, result.pos !== undefined ? result.pos : nPos) || result;
|
1360
|
+
maskPos = nPos;
|
1361
|
+
break;
|
1362
|
+
}
|
1363
|
+
}
|
1364
|
+
}
|
1365
|
+
}
|
1366
|
+
}
|
1367
|
+
}
|
1368
|
+
if (result === false && opts.keepStatic !== false && (opts.regex == null || isComplete(getBuffer())) && !strict && fromAlternate !== true) {
|
1369
|
+
result = alternate(maskPos, c, strict, fromSetValid);
|
1370
|
+
}
|
1371
|
+
if (result === true) {
|
1372
|
+
result = {
|
1373
|
+
pos: maskPos
|
1374
|
+
};
|
1375
|
+
}
|
1376
|
+
}
|
1377
|
+
if ($.isFunction(opts.postValidation) && result !== false && !strict && fromSetValid !== true && validateOnly !== true) {
|
1378
|
+
var postResult = opts.postValidation(getBuffer(true), pos.begin !== undefined ? isRTL ? pos.end : pos.begin : pos, result, opts);
|
1379
|
+
if (postResult !== undefined) {
|
1380
|
+
if (postResult.refreshFromBuffer && postResult.buffer) {
|
1381
|
+
var refresh = postResult.refreshFromBuffer;
|
1382
|
+
refreshFromBuffer(refresh === true ? refresh : refresh.start, refresh.end, postResult.buffer);
|
1383
|
+
}
|
1384
|
+
result = postResult === true ? result : postResult;
|
1385
|
+
}
|
1386
|
+
}
|
1387
|
+
if (result && result.pos === undefined) {
|
1388
|
+
result.pos = maskPos;
|
1389
|
+
}
|
1390
|
+
if (result === false || validateOnly === true) {
|
1391
|
+
resetMaskSet(true);
|
1392
|
+
getMaskSet().validPositions = $.extend(true, {}, positionsClone);
|
1393
|
+
}
|
1394
|
+
return result;
|
1395
|
+
}
|
1396
|
+
function trackbackPositions(originalPos, newPos, fillOnly) {
|
1397
|
+
var result;
|
1398
|
+
if (originalPos === undefined) {
|
1399
|
+
for (originalPos = newPos - 1; originalPos > 0; originalPos--) {
|
1400
|
+
if (getMaskSet().validPositions[originalPos]) break;
|
1401
|
+
}
|
1402
|
+
}
|
1403
|
+
for (var ps = originalPos; ps < newPos; ps++) {
|
1404
|
+
if (getMaskSet().validPositions[ps] === undefined && !isMask(ps, true)) {
|
1405
|
+
var vp = ps == 0 ? getTest(ps) : getMaskSet().validPositions[ps - 1];
|
1406
|
+
if (vp) {
|
1407
|
+
var tests = getTests(ps).slice();
|
1408
|
+
if (tests[tests.length - 1].match.def === "") tests.pop();
|
1409
|
+
var bestMatch = determineTestTemplate(ps, tests);
|
1410
|
+
bestMatch = $.extend({}, bestMatch, {
|
1411
|
+
input: getPlaceholder(ps, bestMatch.match, true) || bestMatch.match.def
|
1412
|
+
});
|
1413
|
+
bestMatch.generatedInput = true;
|
1414
|
+
revalidateMask(ps, bestMatch, true);
|
1415
|
+
if (fillOnly !== true) {
|
1416
|
+
var cvpInput = getMaskSet().validPositions[newPos].input;
|
1417
|
+
getMaskSet().validPositions[newPos] = undefined;
|
1418
|
+
result = isValid(newPos, cvpInput, true, true);
|
1419
|
+
}
|
1420
|
+
}
|
1421
|
+
}
|
1422
|
+
}
|
1423
|
+
return result;
|
1424
|
+
}
|
1425
|
+
function revalidateMask(pos, validTest, fromSetValid, validatedPos) {
|
1426
|
+
function IsEnclosedStatic(pos, valids, selection) {
|
1427
|
+
var posMatch = valids[pos];
|
1428
|
+
if (posMatch !== undefined && (posMatch.match.fn === null && posMatch.match.optionality !== true || posMatch.input === opts.radixPoint)) {
|
1429
|
+
var prevMatch = selection.begin <= pos - 1 ? valids[pos - 1] && valids[pos - 1].match.fn === null && valids[pos - 1] : valids[pos - 1], nextMatch = selection.end > pos + 1 ? valids[pos + 1] && valids[pos + 1].match.fn === null && valids[pos + 1] : valids[pos + 1];
|
1430
|
+
return prevMatch && nextMatch;
|
1431
|
+
}
|
1432
|
+
return false;
|
1433
|
+
}
|
1434
|
+
var begin = pos.begin !== undefined ? pos.begin : pos, end = pos.end !== undefined ? pos.end : pos;
|
1435
|
+
if (pos.begin > pos.end) {
|
1436
|
+
begin = pos.end;
|
1437
|
+
end = pos.begin;
|
1438
|
+
}
|
1439
|
+
validatedPos = validatedPos !== undefined ? validatedPos : begin;
|
1440
|
+
if (begin !== end || opts.insertMode && getMaskSet().validPositions[validatedPos] !== undefined && fromSetValid === undefined) {
|
1441
|
+
var positionsClone = $.extend(true, {}, getMaskSet().validPositions), lvp = getLastValidPosition(undefined, true), i;
|
1442
|
+
getMaskSet().p = begin;
|
1443
|
+
for (i = lvp; i >= begin; i--) {
|
1444
|
+
if (getMaskSet().validPositions[i] && getMaskSet().validPositions[i].match.nativeDef === "+") {
|
1445
|
+
opts.isNegative = false;
|
1446
|
+
}
|
1447
|
+
delete getMaskSet().validPositions[i];
|
1448
|
+
}
|
1449
|
+
var valid = true, j = validatedPos, vps = getMaskSet().validPositions, needsValidation = false, posMatch = j, i = j;
|
1450
|
+
if (validTest) {
|
1451
|
+
getMaskSet().validPositions[validatedPos] = $.extend(true, {}, validTest);
|
1452
|
+
posMatch++;
|
1453
|
+
j++;
|
1454
|
+
if (begin < end) i++;
|
1455
|
+
}
|
1456
|
+
for (;i <= lvp; i++) {
|
1457
|
+
var t = positionsClone[i];
|
1458
|
+
if (t !== undefined && (i >= end || i >= begin && t.generatedInput !== true && IsEnclosedStatic(i, positionsClone, {
|
1459
|
+
begin: begin,
|
1460
|
+
end: end
|
1461
|
+
}))) {
|
1462
|
+
while (getTest(posMatch).match.def !== "") {
|
1463
|
+
if (needsValidation === false && positionsClone[posMatch] && positionsClone[posMatch].match.nativeDef === t.match.nativeDef) {
|
1464
|
+
getMaskSet().validPositions[posMatch] = $.extend(true, {}, positionsClone[posMatch]);
|
1465
|
+
getMaskSet().validPositions[posMatch].input = t.input;
|
1466
|
+
trackbackPositions(undefined, posMatch, true);
|
1467
|
+
j = posMatch + 1;
|
1468
|
+
valid = true;
|
1469
|
+
} else if (opts.shiftPositions && positionCanMatchDefinition(posMatch, t.match.def)) {
|
1470
|
+
var result = isValid(posMatch, t.input, true, true);
|
1471
|
+
valid = result !== false;
|
1472
|
+
j = result.caret || result.insert ? getLastValidPosition() : posMatch + 1;
|
1473
|
+
needsValidation = true;
|
1474
|
+
} else {
|
1475
|
+
valid = t.generatedInput === true || t.input === opts.radixPoint && opts.numericInput === true;
|
1476
|
+
}
|
1477
|
+
if (valid) break;
|
1478
|
+
if (!valid && posMatch > end && isMask(posMatch, true) && (t.match.fn !== null || posMatch > getMaskSet().maskLength)) {
|
1479
|
+
break;
|
1480
|
+
}
|
1481
|
+
posMatch++;
|
1482
|
+
}
|
1483
|
+
if (getTest(posMatch).match.def == "") valid = false;
|
1484
|
+
posMatch = j;
|
1485
|
+
}
|
1486
|
+
if (!valid) break;
|
1487
|
+
}
|
1488
|
+
if (!valid) {
|
1489
|
+
getMaskSet().validPositions = $.extend(true, {}, positionsClone);
|
1490
|
+
resetMaskSet(true);
|
1491
|
+
return false;
|
1492
|
+
}
|
1493
|
+
} else if (validTest) {
|
1494
|
+
getMaskSet().validPositions[validatedPos] = $.extend(true, {}, validTest);
|
1495
|
+
}
|
1496
|
+
resetMaskSet(true);
|
1497
|
+
return true;
|
1498
|
+
}
|
1499
|
+
function isMask(pos, strict) {
|
1500
|
+
var test = getTestTemplate(pos).match;
|
1501
|
+
if (test.def === "") test = getTest(pos).match;
|
1502
|
+
if (test.fn != null) {
|
1503
|
+
return test.fn;
|
1504
|
+
}
|
1505
|
+
if (strict !== true && pos > -1) {
|
1506
|
+
var tests = getTests(pos);
|
1507
|
+
return tests.length > 1 + (tests[tests.length - 1].match.def === "" ? 1 : 0);
|
1508
|
+
}
|
1509
|
+
return false;
|
1510
|
+
}
|
1511
|
+
function seekNext(pos, newBlock) {
|
1512
|
+
var position = pos + 1;
|
1513
|
+
while (getTest(position).match.def !== "" && (newBlock === true && (getTest(position).match.newBlockMarker !== true || !isMask(position)) || newBlock !== true && !isMask(position))) {
|
1514
|
+
position++;
|
1515
|
+
}
|
1516
|
+
return position;
|
1517
|
+
}
|
1518
|
+
function seekPrevious(pos, newBlock) {
|
1519
|
+
var position = pos, tests;
|
1520
|
+
if (position <= 0) return 0;
|
1521
|
+
while (--position > 0 && (newBlock === true && getTest(position).match.newBlockMarker !== true || newBlock !== true && !isMask(position) && (tests = getTests(position),
|
1522
|
+
tests.length < 2 || tests.length === 2 && tests[1].match.def === ""))) {}
|
1523
|
+
return position;
|
1524
|
+
}
|
1525
|
+
function writeBuffer(input, buffer, caretPos, event, triggerEvents) {
|
1526
|
+
if (event && $.isFunction(opts.onBeforeWrite)) {
|
1527
|
+
var result = opts.onBeforeWrite.call(inputmask, event, buffer, caretPos, opts);
|
1528
|
+
if (result) {
|
1529
|
+
if (result.refreshFromBuffer) {
|
1530
|
+
var refresh = result.refreshFromBuffer;
|
1531
|
+
refreshFromBuffer(refresh === true ? refresh : refresh.start, refresh.end, result.buffer || buffer);
|
1532
|
+
buffer = getBuffer(true);
|
1533
|
+
}
|
1534
|
+
if (caretPos !== undefined) caretPos = result.caret !== undefined ? result.caret : caretPos;
|
1535
|
+
}
|
1536
|
+
}
|
1537
|
+
if (input !== undefined) {
|
1538
|
+
input.inputmask._valueSet(buffer.join(""));
|
1539
|
+
if (caretPos !== undefined && (event === undefined || event.type !== "blur")) {
|
1540
|
+
caret(input, caretPos);
|
1541
|
+
} else renderColorMask(input, caretPos, buffer.length === 0);
|
1542
|
+
if (triggerEvents === true) {
|
1543
|
+
var $input = $(input), nptVal = input.inputmask._valueGet();
|
1544
|
+
skipInputEvent = true;
|
1545
|
+
$input.trigger("input");
|
1546
|
+
setTimeout(function() {
|
1547
|
+
if (nptVal === getBufferTemplate().join("")) {
|
1548
|
+
$input.trigger("cleared");
|
1549
|
+
} else if (isComplete(buffer) === true) {
|
1550
|
+
$input.trigger("complete");
|
1551
|
+
}
|
1552
|
+
}, 0);
|
1553
|
+
}
|
1554
|
+
}
|
1555
|
+
}
|
1556
|
+
function getPlaceholder(pos, test, returnPL) {
|
1557
|
+
test = test || getTest(pos).match;
|
1558
|
+
if (test.placeholder !== undefined || returnPL === true) {
|
1559
|
+
return $.isFunction(test.placeholder) ? test.placeholder(opts) : test.placeholder;
|
1560
|
+
} else if (test.fn === null) {
|
1561
|
+
if (pos > -1 && getMaskSet().validPositions[pos] === undefined) {
|
1562
|
+
var tests = getTests(pos), staticAlternations = [], prevTest;
|
1563
|
+
if (tests.length > 1 + (tests[tests.length - 1].match.def === "" ? 1 : 0)) {
|
1564
|
+
for (var i = 0; i < tests.length; i++) {
|
1565
|
+
if (tests[i].match.optionality !== true && tests[i].match.optionalQuantifier !== true && (tests[i].match.fn === null || (prevTest === undefined || tests[i].match.fn.test(prevTest.match.def, getMaskSet(), pos, true, opts) !== false))) {
|
1566
|
+
staticAlternations.push(tests[i]);
|
1567
|
+
if (tests[i].match.fn === null) prevTest = tests[i];
|
1568
|
+
if (staticAlternations.length > 1) {
|
1569
|
+
if (/[0-9a-bA-Z]/.test(staticAlternations[0].match.def)) {
|
1570
|
+
return opts.placeholder.charAt(pos % opts.placeholder.length);
|
1571
|
+
}
|
1572
|
+
}
|
1573
|
+
}
|
1574
|
+
}
|
1575
|
+
}
|
1576
|
+
}
|
1577
|
+
return test.def;
|
1578
|
+
}
|
1579
|
+
return opts.placeholder.charAt(pos % opts.placeholder.length);
|
1580
|
+
}
|
1581
|
+
function HandleNativePlaceholder(npt, value) {
|
1582
|
+
if (ie) {
|
1583
|
+
if (npt.inputmask._valueGet() !== value && (npt.placeholder !== value || npt.placeholder === "")) {
|
1584
|
+
var buffer = getBuffer().slice(), nptValue = npt.inputmask._valueGet();
|
1585
|
+
if (nptValue !== value) {
|
1586
|
+
var lvp = getLastValidPosition();
|
1587
|
+
if (lvp === -1 && nptValue === getBufferTemplate().join("")) {
|
1588
|
+
buffer = [];
|
1589
|
+
} else if (lvp !== -1) {
|
1590
|
+
clearOptionalTail(buffer);
|
1591
|
+
}
|
1592
|
+
writeBuffer(npt, buffer);
|
1593
|
+
}
|
1594
|
+
}
|
1595
|
+
} else if (npt.placeholder !== value) {
|
1596
|
+
npt.placeholder = value;
|
1597
|
+
if (npt.placeholder === "") npt.removeAttribute("placeholder");
|
1598
|
+
}
|
1599
|
+
}
|
1600
|
+
var EventRuler = {
|
1601
|
+
on: function(input, eventName, eventHandler) {
|
1602
|
+
var ev = function(e) {
|
1603
|
+
var that = this;
|
1604
|
+
if (that.inputmask === undefined && this.nodeName !== "FORM") {
|
1605
|
+
var imOpts = $.data(that, "_inputmask_opts");
|
1606
|
+
if (imOpts) new Inputmask(imOpts).mask(that); else EventRuler.off(that);
|
1607
|
+
} else if (e.type !== "setvalue" && this.nodeName !== "FORM" && (that.disabled || that.readOnly && !(e.type === "keydown" && (e.ctrlKey && e.keyCode === 67) || opts.tabThrough === false && e.keyCode === Inputmask.keyCode.TAB))) {
|
1608
|
+
e.preventDefault();
|
1609
|
+
} else {
|
1610
|
+
switch (e.type) {
|
1611
|
+
case "input":
|
1612
|
+
if (skipInputEvent === true) {
|
1613
|
+
skipInputEvent = false;
|
1614
|
+
return e.preventDefault();
|
1615
|
+
}
|
1616
|
+
if (mobile) {
|
1617
|
+
var args = arguments;
|
1618
|
+
setTimeout(function() {
|
1619
|
+
eventHandler.apply(that, args);
|
1620
|
+
caret(that, that.inputmask.caretPos, undefined, true);
|
1621
|
+
}, 0);
|
1622
|
+
return false;
|
1623
|
+
}
|
1624
|
+
break;
|
1625
|
+
|
1626
|
+
case "keydown":
|
1627
|
+
skipKeyPressEvent = false;
|
1628
|
+
skipInputEvent = false;
|
1629
|
+
break;
|
1630
|
+
|
1631
|
+
case "keypress":
|
1632
|
+
if (skipKeyPressEvent === true) {
|
1633
|
+
return e.preventDefault();
|
1634
|
+
}
|
1635
|
+
skipKeyPressEvent = true;
|
1636
|
+
break;
|
1637
|
+
|
1638
|
+
case "click":
|
1639
|
+
if (iemobile || iphone) {
|
1640
|
+
var args = arguments;
|
1641
|
+
setTimeout(function() {
|
1642
|
+
eventHandler.apply(that, args);
|
1643
|
+
}, 0);
|
1644
|
+
return false;
|
1645
|
+
}
|
1646
|
+
break;
|
1647
|
+
}
|
1648
|
+
var returnVal = eventHandler.apply(that, arguments);
|
1649
|
+
if (returnVal === false) {
|
1650
|
+
e.preventDefault();
|
1651
|
+
e.stopPropagation();
|
1652
|
+
}
|
1653
|
+
return returnVal;
|
1654
|
+
}
|
1655
|
+
};
|
1656
|
+
input.inputmask.events[eventName] = input.inputmask.events[eventName] || [];
|
1657
|
+
input.inputmask.events[eventName].push(ev);
|
1658
|
+
if ($.inArray(eventName, [ "submit", "reset" ]) !== -1) {
|
1659
|
+
if (input.form !== null) $(input.form).on(eventName, ev);
|
1660
|
+
} else {
|
1661
|
+
$(input).on(eventName, ev);
|
1662
|
+
}
|
1663
|
+
},
|
1664
|
+
off: function(input, event) {
|
1665
|
+
if (input.inputmask && input.inputmask.events) {
|
1666
|
+
var events;
|
1667
|
+
if (event) {
|
1668
|
+
events = [];
|
1669
|
+
events[event] = input.inputmask.events[event];
|
1670
|
+
} else {
|
1671
|
+
events = input.inputmask.events;
|
1672
|
+
}
|
1673
|
+
$.each(events, function(eventName, evArr) {
|
1674
|
+
while (evArr.length > 0) {
|
1675
|
+
var ev = evArr.pop();
|
1676
|
+
if ($.inArray(eventName, [ "submit", "reset" ]) !== -1) {
|
1677
|
+
if (input.form !== null) $(input.form).off(eventName, ev);
|
1678
|
+
} else {
|
1679
|
+
$(input).off(eventName, ev);
|
1680
|
+
}
|
1681
|
+
}
|
1682
|
+
delete input.inputmask.events[eventName];
|
1683
|
+
});
|
1684
|
+
}
|
1685
|
+
}
|
1686
|
+
};
|
1687
|
+
var EventHandlers = {
|
1688
|
+
keydownEvent: function(e) {
|
1689
|
+
var input = this, $input = $(input), k = e.keyCode, pos = caret(input);
|
1690
|
+
if (k === Inputmask.keyCode.BACKSPACE || k === Inputmask.keyCode.DELETE || iphone && k === Inputmask.keyCode.BACKSPACE_SAFARI || e.ctrlKey && k === Inputmask.keyCode.X && !isInputEventSupported("cut")) {
|
1691
|
+
e.preventDefault();
|
1692
|
+
handleRemove(input, k, pos);
|
1693
|
+
writeBuffer(input, getBuffer(true), getMaskSet().p, e, input.inputmask._valueGet() !== getBuffer().join(""));
|
1694
|
+
} else if (k === Inputmask.keyCode.END || k === Inputmask.keyCode.PAGE_DOWN) {
|
1695
|
+
e.preventDefault();
|
1696
|
+
var caretPos = seekNext(getLastValidPosition());
|
1697
|
+
caret(input, e.shiftKey ? pos.begin : caretPos, caretPos, true);
|
1698
|
+
} else if (k === Inputmask.keyCode.HOME && !e.shiftKey || k === Inputmask.keyCode.PAGE_UP) {
|
1699
|
+
e.preventDefault();
|
1700
|
+
caret(input, 0, e.shiftKey ? pos.begin : 0, true);
|
1701
|
+
} else if ((opts.undoOnEscape && k === Inputmask.keyCode.ESCAPE || k === 90 && e.ctrlKey) && e.altKey !== true) {
|
1702
|
+
checkVal(input, true, false, undoValue.split(""));
|
1703
|
+
$input.trigger("click");
|
1704
|
+
} else if (k === Inputmask.keyCode.INSERT && !(e.shiftKey || e.ctrlKey)) {
|
1705
|
+
opts.insertMode = !opts.insertMode;
|
1706
|
+
input.setAttribute("im-insert", opts.insertMode);
|
1707
|
+
} else if (opts.tabThrough === true && k === Inputmask.keyCode.TAB) {
|
1708
|
+
if (e.shiftKey === true) {
|
1709
|
+
if (getTest(pos.begin).match.fn === null) {
|
1710
|
+
pos.begin = seekNext(pos.begin);
|
1711
|
+
}
|
1712
|
+
pos.end = seekPrevious(pos.begin, true);
|
1713
|
+
pos.begin = seekPrevious(pos.end, true);
|
1714
|
+
} else {
|
1715
|
+
pos.begin = seekNext(pos.begin, true);
|
1716
|
+
pos.end = seekNext(pos.begin, true);
|
1717
|
+
if (pos.end < getMaskSet().maskLength) pos.end--;
|
1718
|
+
}
|
1719
|
+
if (pos.begin < getMaskSet().maskLength) {
|
1720
|
+
e.preventDefault();
|
1721
|
+
caret(input, pos.begin, pos.end);
|
1722
|
+
}
|
1723
|
+
}
|
1724
|
+
opts.onKeyDown.call(this, e, getBuffer(), caret(input).begin, opts);
|
1725
|
+
ignorable = $.inArray(k, opts.ignorables) !== -1;
|
1726
|
+
},
|
1727
|
+
keypressEvent: function(e, checkval, writeOut, strict, ndx) {
|
1728
|
+
var input = this, $input = $(input), k = e.which || e.charCode || e.keyCode;
|
1729
|
+
if (checkval !== true && (!(e.ctrlKey && e.altKey) && (e.ctrlKey || e.metaKey || ignorable))) {
|
1730
|
+
if (k === Inputmask.keyCode.ENTER && undoValue !== getBuffer().join("")) {
|
1731
|
+
undoValue = getBuffer().join("");
|
1732
|
+
setTimeout(function() {
|
1733
|
+
$input.trigger("change");
|
1734
|
+
}, 0);
|
1735
|
+
}
|
1736
|
+
return true;
|
1737
|
+
} else {
|
1738
|
+
if (k) {
|
1739
|
+
if (k === 46 && e.shiftKey === false && opts.radixPoint !== "") k = opts.radixPoint.charCodeAt(0);
|
1740
|
+
var pos = checkval ? {
|
1741
|
+
begin: ndx,
|
1742
|
+
end: ndx
|
1743
|
+
} : caret(input), forwardPosition, c = String.fromCharCode(k), offset = 0;
|
1744
|
+
if (opts._radixDance && opts.numericInput) {
|
1745
|
+
var caretPos = getBuffer().indexOf(opts.radixPoint.charAt(0)) + 1;
|
1746
|
+
if (pos.begin <= caretPos) {
|
1747
|
+
if (k === opts.radixPoint.charCodeAt(0)) offset = 1;
|
1748
|
+
pos.begin -= 1;
|
1749
|
+
pos.end -= 1;
|
1750
|
+
}
|
1751
|
+
}
|
1752
|
+
getMaskSet().writeOutBuffer = true;
|
1753
|
+
var valResult = isValid(pos, c, strict);
|
1754
|
+
if (valResult !== false) {
|
1755
|
+
resetMaskSet(true);
|
1756
|
+
forwardPosition = valResult.caret !== undefined ? valResult.caret : seekNext(valResult.pos.begin ? valResult.pos.begin : valResult.pos);
|
1757
|
+
getMaskSet().p = forwardPosition;
|
1758
|
+
}
|
1759
|
+
forwardPosition = (opts.numericInput && valResult.caret === undefined ? seekPrevious(forwardPosition) : forwardPosition) + offset;
|
1760
|
+
if (writeOut !== false) {
|
1761
|
+
setTimeout(function() {
|
1762
|
+
opts.onKeyValidation.call(input, k, valResult, opts);
|
1763
|
+
}, 0);
|
1764
|
+
if (getMaskSet().writeOutBuffer && valResult !== false) {
|
1765
|
+
var buffer = getBuffer();
|
1766
|
+
writeBuffer(input, buffer, forwardPosition, e, checkval !== true);
|
1767
|
+
}
|
1768
|
+
}
|
1769
|
+
e.preventDefault();
|
1770
|
+
if (checkval) {
|
1771
|
+
if (valResult !== false) valResult.forwardPosition = forwardPosition;
|
1772
|
+
return valResult;
|
1773
|
+
}
|
1774
|
+
}
|
1775
|
+
}
|
1776
|
+
},
|
1777
|
+
pasteEvent: function(e) {
|
1778
|
+
var input = this, ev = e.originalEvent || e, $input = $(input), inputValue = input.inputmask._valueGet(true), caretPos = caret(input), tempValue;
|
1779
|
+
if (isRTL) {
|
1780
|
+
tempValue = caretPos.end;
|
1781
|
+
caretPos.end = caretPos.begin;
|
1782
|
+
caretPos.begin = tempValue;
|
1783
|
+
}
|
1784
|
+
var valueBeforeCaret = inputValue.substr(0, caretPos.begin), valueAfterCaret = inputValue.substr(caretPos.end, inputValue.length);
|
1785
|
+
if (valueBeforeCaret === (isRTL ? getBufferTemplate().reverse() : getBufferTemplate()).slice(0, caretPos.begin).join("")) valueBeforeCaret = "";
|
1786
|
+
if (valueAfterCaret === (isRTL ? getBufferTemplate().reverse() : getBufferTemplate()).slice(caretPos.end).join("")) valueAfterCaret = "";
|
1787
|
+
if (window.clipboardData && window.clipboardData.getData) {
|
1788
|
+
inputValue = valueBeforeCaret + window.clipboardData.getData("Text") + valueAfterCaret;
|
1789
|
+
} else if (ev.clipboardData && ev.clipboardData.getData) {
|
1790
|
+
inputValue = valueBeforeCaret + ev.clipboardData.getData("text/plain") + valueAfterCaret;
|
1791
|
+
} else return true;
|
1792
|
+
var pasteValue = inputValue;
|
1793
|
+
if ($.isFunction(opts.onBeforePaste)) {
|
1794
|
+
pasteValue = opts.onBeforePaste.call(inputmask, inputValue, opts);
|
1795
|
+
if (pasteValue === false) {
|
1796
|
+
return e.preventDefault();
|
1797
|
+
}
|
1798
|
+
if (!pasteValue) {
|
1799
|
+
pasteValue = inputValue;
|
1800
|
+
}
|
1801
|
+
}
|
1802
|
+
checkVal(input, false, false, pasteValue.toString().split(""));
|
1803
|
+
writeBuffer(input, getBuffer(), seekNext(getLastValidPosition()), e, undoValue !== getBuffer().join(""));
|
1804
|
+
return e.preventDefault();
|
1805
|
+
},
|
1806
|
+
inputFallBackEvent: function(e) {
|
1807
|
+
function radixPointHandler(input, inputValue, caretPos) {
|
1808
|
+
if (inputValue.charAt(caretPos.begin - 1) === "." && opts.radixPoint !== "") {
|
1809
|
+
inputValue = inputValue.split("");
|
1810
|
+
inputValue[caretPos.begin - 1] = opts.radixPoint.charAt(0);
|
1811
|
+
inputValue = inputValue.join("");
|
1812
|
+
}
|
1813
|
+
return inputValue;
|
1814
|
+
}
|
1815
|
+
function ieMobileHandler(input, inputValue, caretPos) {
|
1816
|
+
if (iemobile) {
|
1817
|
+
var inputChar = inputValue.replace(getBuffer().join(""), "");
|
1818
|
+
if (inputChar.length === 1) {
|
1819
|
+
var iv = inputValue.split("");
|
1820
|
+
iv.splice(caretPos.begin, 0, inputChar);
|
1821
|
+
inputValue = iv.join("");
|
1822
|
+
}
|
1823
|
+
}
|
1824
|
+
return inputValue;
|
1825
|
+
}
|
1826
|
+
var input = this, inputValue = input.inputmask._valueGet();
|
1827
|
+
if (getBuffer().join("") !== inputValue) {
|
1828
|
+
var caretPos = caret(input);
|
1829
|
+
inputValue = radixPointHandler(input, inputValue, caretPos);
|
1830
|
+
inputValue = ieMobileHandler(input, inputValue, caretPos);
|
1831
|
+
if (getBuffer().join("") !== inputValue) {
|
1832
|
+
var buffer = getBuffer().join(""), offset = !opts.numericInput && inputValue.length > buffer.length ? -1 : 0, frontPart = inputValue.substr(0, caretPos.begin), backPart = inputValue.substr(caretPos.begin), frontBufferPart = buffer.substr(0, caretPos.begin + offset), backBufferPart = buffer.substr(caretPos.begin + offset);
|
1833
|
+
var selection = caretPos, entries = "", isEntry = false;
|
1834
|
+
if (frontPart !== frontBufferPart) {
|
1835
|
+
var fpl = (isEntry = frontPart.length >= frontBufferPart.length) ? frontPart.length : frontBufferPart.length, i;
|
1836
|
+
for (i = 0; frontPart.charAt(i) === frontBufferPart.charAt(i) && i < fpl; i++) ;
|
1837
|
+
if (isEntry) {
|
1838
|
+
selection.begin = i - offset;
|
1839
|
+
entries += frontPart.slice(i, selection.end);
|
1840
|
+
}
|
1841
|
+
}
|
1842
|
+
if (backPart !== backBufferPart) {
|
1843
|
+
if (backPart.length > backBufferPart.length) {
|
1844
|
+
entries += backPart.slice(0, 1);
|
1845
|
+
} else {
|
1846
|
+
if (backPart.length < backBufferPart.length) {
|
1847
|
+
selection.end += backBufferPart.length - backPart.length;
|
1848
|
+
if (!isEntry && opts.radixPoint !== "" && backPart === "" && frontPart.charAt(selection.begin + offset - 1) === opts.radixPoint) {
|
1849
|
+
selection.begin--;
|
1850
|
+
entries = opts.radixPoint;
|
1851
|
+
}
|
1852
|
+
}
|
1853
|
+
}
|
1854
|
+
}
|
1855
|
+
writeBuffer(input, getBuffer(), {
|
1856
|
+
begin: selection.begin + offset,
|
1857
|
+
end: selection.end + offset
|
1858
|
+
});
|
1859
|
+
if (entries.length > 0) {
|
1860
|
+
$.each(entries.split(""), function(ndx, entry) {
|
1861
|
+
var keypress = new $.Event("keypress");
|
1862
|
+
keypress.which = entry.charCodeAt(0);
|
1863
|
+
ignorable = false;
|
1864
|
+
EventHandlers.keypressEvent.call(input, keypress);
|
1865
|
+
});
|
1866
|
+
} else {
|
1867
|
+
if (selection.begin === selection.end - 1) {
|
1868
|
+
selection.begin = seekPrevious(selection.begin + 1);
|
1869
|
+
if (selection.begin === selection.end - 1) {
|
1870
|
+
caret(input, selection.begin);
|
1871
|
+
} else {
|
1872
|
+
caret(input, selection.begin, selection.end);
|
1873
|
+
}
|
1874
|
+
}
|
1875
|
+
var keydown = new $.Event("keydown");
|
1876
|
+
keydown.keyCode = opts.numericInput ? Inputmask.keyCode.BACKSPACE : Inputmask.keyCode.DELETE;
|
1877
|
+
EventHandlers.keydownEvent.call(input, keydown);
|
1878
|
+
}
|
1879
|
+
e.preventDefault();
|
1880
|
+
}
|
1881
|
+
}
|
1882
|
+
},
|
1883
|
+
beforeInputEvent: function(e) {
|
1884
|
+
if (e.cancelable) {
|
1885
|
+
var input = this;
|
1886
|
+
switch (e.inputType) {
|
1887
|
+
case "insertText":
|
1888
|
+
$.each(e.data.split(""), function(ndx, entry) {
|
1889
|
+
var keypress = new $.Event("keypress");
|
1890
|
+
keypress.which = entry.charCodeAt(0);
|
1891
|
+
ignorable = false;
|
1892
|
+
EventHandlers.keypressEvent.call(input, keypress);
|
1893
|
+
});
|
1894
|
+
return e.preventDefault();
|
1895
|
+
|
1896
|
+
case "deleteContentBackward":
|
1897
|
+
var keydown = new $.Event("keydown");
|
1898
|
+
keydown.keyCode = Inputmask.keyCode.BACKSPACE;
|
1899
|
+
EventHandlers.keydownEvent.call(input, keydown);
|
1900
|
+
return e.preventDefault();
|
1901
|
+
|
1902
|
+
case "deleteContentForward":
|
1903
|
+
var keydown = new $.Event("keydown");
|
1904
|
+
keydown.keyCode = Inputmask.keyCode.DELETE;
|
1905
|
+
EventHandlers.keydownEvent.call(input, keydown);
|
1906
|
+
return e.preventDefault();
|
1907
|
+
}
|
1908
|
+
}
|
1909
|
+
},
|
1910
|
+
setValueEvent: function(e) {
|
1911
|
+
this.inputmask.refreshValue = false;
|
1912
|
+
var input = this, value = e && e.detail ? e.detail[0] : arguments[1], value = value || input.inputmask._valueGet(true);
|
1913
|
+
if ($.isFunction(opts.onBeforeMask)) value = opts.onBeforeMask.call(inputmask, value, opts) || value;
|
1914
|
+
value = value.toString().split("");
|
1915
|
+
checkVal(input, true, false, value);
|
1916
|
+
undoValue = getBuffer().join("");
|
1917
|
+
if ((opts.clearMaskOnLostFocus || opts.clearIncomplete) && input.inputmask._valueGet() === getBufferTemplate().join("")) {
|
1918
|
+
input.inputmask._valueSet("");
|
1919
|
+
}
|
1920
|
+
},
|
1921
|
+
focusEvent: function(e) {
|
1922
|
+
var input = this, nptValue = input.inputmask._valueGet();
|
1923
|
+
if (opts.showMaskOnFocus) {
|
1924
|
+
if (nptValue !== getBuffer().join("")) {
|
1925
|
+
writeBuffer(input, getBuffer(), seekNext(getLastValidPosition()));
|
1926
|
+
} else if (mouseEnter === false) {
|
1927
|
+
caret(input, seekNext(getLastValidPosition()));
|
1928
|
+
}
|
1929
|
+
}
|
1930
|
+
if (opts.positionCaretOnTab === true && mouseEnter === false) {
|
1931
|
+
EventHandlers.clickEvent.apply(input, [ e, true ]);
|
1932
|
+
}
|
1933
|
+
undoValue = getBuffer().join("");
|
1934
|
+
},
|
1935
|
+
mouseleaveEvent: function(e) {
|
1936
|
+
var input = this;
|
1937
|
+
mouseEnter = false;
|
1938
|
+
if (opts.clearMaskOnLostFocus && document.activeElement !== input) {
|
1939
|
+
HandleNativePlaceholder(input, originalPlaceholder);
|
1940
|
+
}
|
1941
|
+
},
|
1942
|
+
clickEvent: function(e, tabbed) {
|
1943
|
+
function doRadixFocus(clickPos) {
|
1944
|
+
if (opts.radixPoint !== "") {
|
1945
|
+
var vps = getMaskSet().validPositions;
|
1946
|
+
if (vps[clickPos] === undefined || vps[clickPos].input === getPlaceholder(clickPos)) {
|
1947
|
+
if (clickPos < seekNext(-1)) return true;
|
1948
|
+
var radixPos = $.inArray(opts.radixPoint, getBuffer());
|
1949
|
+
if (radixPos !== -1) {
|
1950
|
+
for (var vp in vps) {
|
1951
|
+
if (radixPos < vp && vps[vp].input !== getPlaceholder(vp)) {
|
1952
|
+
return false;
|
1953
|
+
}
|
1954
|
+
}
|
1955
|
+
return true;
|
1956
|
+
}
|
1957
|
+
}
|
1958
|
+
}
|
1959
|
+
return false;
|
1960
|
+
}
|
1961
|
+
var input = this;
|
1962
|
+
setTimeout(function() {
|
1963
|
+
if (document.activeElement === input) {
|
1964
|
+
var selectedCaret = caret(input);
|
1965
|
+
if (tabbed) {
|
1966
|
+
if (isRTL) {
|
1967
|
+
selectedCaret.end = selectedCaret.begin;
|
1968
|
+
} else {
|
1969
|
+
selectedCaret.begin = selectedCaret.end;
|
1970
|
+
}
|
1971
|
+
}
|
1972
|
+
if (selectedCaret.begin === selectedCaret.end) {
|
1973
|
+
switch (opts.positionCaretOnClick) {
|
1974
|
+
case "none":
|
1975
|
+
break;
|
1976
|
+
|
1977
|
+
case "select":
|
1978
|
+
caret(input, 0, getBuffer().length);
|
1979
|
+
break;
|
1980
|
+
|
1981
|
+
case "ignore":
|
1982
|
+
caret(input, seekNext(getLastValidPosition()));
|
1983
|
+
break;
|
1984
|
+
|
1985
|
+
case "radixFocus":
|
1986
|
+
if (doRadixFocus(selectedCaret.begin)) {
|
1987
|
+
var radixPos = getBuffer().join("").indexOf(opts.radixPoint);
|
1988
|
+
caret(input, opts.numericInput ? seekNext(radixPos) : radixPos);
|
1989
|
+
break;
|
1990
|
+
}
|
1991
|
+
|
1992
|
+
default:
|
1993
|
+
var clickPosition = selectedCaret.begin, lvclickPosition = getLastValidPosition(clickPosition, true), lastPosition = seekNext(lvclickPosition);
|
1994
|
+
if (clickPosition < lastPosition) {
|
1995
|
+
caret(input, !isMask(clickPosition, true) && !isMask(clickPosition - 1, true) ? seekNext(clickPosition) : clickPosition);
|
1996
|
+
} else {
|
1997
|
+
var lvp = getMaskSet().validPositions[lvclickPosition], tt = getTestTemplate(lastPosition, lvp ? lvp.match.locator : undefined, lvp), placeholder = getPlaceholder(lastPosition, tt.match);
|
1998
|
+
if (placeholder !== "" && getBuffer()[lastPosition] !== placeholder && tt.match.optionalQuantifier !== true && tt.match.newBlockMarker !== true || !isMask(lastPosition, opts.keepStatic) && tt.match.def === placeholder) {
|
1999
|
+
var newPos = seekNext(lastPosition);
|
2000
|
+
if (clickPosition >= newPos || clickPosition === lastPosition) {
|
2001
|
+
lastPosition = newPos;
|
2002
|
+
}
|
2003
|
+
}
|
2004
|
+
caret(input, lastPosition);
|
2005
|
+
}
|
2006
|
+
break;
|
2007
|
+
}
|
2008
|
+
}
|
2009
|
+
}
|
2010
|
+
}, 0);
|
2011
|
+
},
|
2012
|
+
cutEvent: function(e) {
|
2013
|
+
var input = this, $input = $(input), pos = caret(input), ev = e.originalEvent || e;
|
2014
|
+
var clipboardData = window.clipboardData || ev.clipboardData, clipData = isRTL ? getBuffer().slice(pos.end, pos.begin) : getBuffer().slice(pos.begin, pos.end);
|
2015
|
+
clipboardData.setData("text", isRTL ? clipData.reverse().join("") : clipData.join(""));
|
2016
|
+
if (document.execCommand) document.execCommand("copy");
|
2017
|
+
handleRemove(input, Inputmask.keyCode.DELETE, pos);
|
2018
|
+
writeBuffer(input, getBuffer(), getMaskSet().p, e, undoValue !== getBuffer().join(""));
|
2019
|
+
},
|
2020
|
+
blurEvent: function(e) {
|
2021
|
+
var $input = $(this), input = this;
|
2022
|
+
if (input.inputmask) {
|
2023
|
+
HandleNativePlaceholder(input, originalPlaceholder);
|
2024
|
+
var nptValue = input.inputmask._valueGet(), buffer = getBuffer().slice();
|
2025
|
+
if (nptValue !== "" || colorMask !== undefined) {
|
2026
|
+
if (opts.clearMaskOnLostFocus) {
|
2027
|
+
if (getLastValidPosition() === -1 && nptValue === getBufferTemplate().join("")) {
|
2028
|
+
buffer = [];
|
2029
|
+
} else {
|
2030
|
+
clearOptionalTail(buffer);
|
2031
|
+
}
|
2032
|
+
}
|
2033
|
+
if (isComplete(buffer) === false) {
|
2034
|
+
setTimeout(function() {
|
2035
|
+
$input.trigger("incomplete");
|
2036
|
+
}, 0);
|
2037
|
+
if (opts.clearIncomplete) {
|
2038
|
+
resetMaskSet();
|
2039
|
+
if (opts.clearMaskOnLostFocus) {
|
2040
|
+
buffer = [];
|
2041
|
+
} else {
|
2042
|
+
buffer = getBufferTemplate().slice();
|
2043
|
+
}
|
2044
|
+
}
|
2045
|
+
}
|
2046
|
+
writeBuffer(input, buffer, undefined, e);
|
2047
|
+
}
|
2048
|
+
if (undoValue !== getBuffer().join("")) {
|
2049
|
+
undoValue = buffer.join("");
|
2050
|
+
$input.trigger("change");
|
2051
|
+
}
|
2052
|
+
}
|
2053
|
+
},
|
2054
|
+
mouseenterEvent: function(e) {
|
2055
|
+
var input = this;
|
2056
|
+
mouseEnter = true;
|
2057
|
+
if (document.activeElement !== input && opts.showMaskOnHover) {
|
2058
|
+
HandleNativePlaceholder(input, (isRTL ? getBuffer().slice().reverse() : getBuffer()).join(""));
|
2059
|
+
}
|
2060
|
+
},
|
2061
|
+
submitEvent: function(e) {
|
2062
|
+
if (undoValue !== getBuffer().join("")) {
|
2063
|
+
$el.trigger("change");
|
2064
|
+
}
|
2065
|
+
if (opts.clearMaskOnLostFocus && getLastValidPosition() === -1 && el.inputmask._valueGet && el.inputmask._valueGet() === getBufferTemplate().join("")) {
|
2066
|
+
el.inputmask._valueSet("");
|
2067
|
+
}
|
2068
|
+
if (opts.clearIncomplete && isComplete(getBuffer()) === false) {
|
2069
|
+
el.inputmask._valueSet("");
|
2070
|
+
}
|
2071
|
+
if (opts.removeMaskOnSubmit) {
|
2072
|
+
el.inputmask._valueSet(el.inputmask.unmaskedvalue(), true);
|
2073
|
+
setTimeout(function() {
|
2074
|
+
writeBuffer(el, getBuffer());
|
2075
|
+
}, 0);
|
2076
|
+
}
|
2077
|
+
},
|
2078
|
+
resetEvent: function(e) {
|
2079
|
+
el.inputmask.refreshValue = true;
|
2080
|
+
setTimeout(function() {
|
2081
|
+
$el.trigger("setvalue");
|
2082
|
+
}, 0);
|
2083
|
+
}
|
2084
|
+
};
|
2085
|
+
function checkVal(input, writeOut, strict, nptvl, initiatingEvent) {
|
2086
|
+
var inputmask = this || input.inputmask, inputValue = nptvl.slice(), charCodes = "", initialNdx = -1, result = undefined;
|
2087
|
+
function isTemplateMatch(ndx, charCodes) {
|
2088
|
+
var charCodeNdx = getMaskTemplate(true, 0, false).slice(ndx, seekNext(ndx)).join("").replace(/'/g, "").indexOf(charCodes);
|
2089
|
+
return charCodeNdx !== -1 && !isMask(ndx) && (getTest(ndx).match.nativeDef === charCodes.charAt(0) || getTest(ndx).match.fn === null && getTest(ndx).match.nativeDef === "'" + charCodes.charAt(0) || getTest(ndx).match.nativeDef === " " && (getTest(ndx + 1).match.nativeDef === charCodes.charAt(0) || getTest(ndx + 1).match.fn === null && getTest(ndx + 1).match.nativeDef === "'" + charCodes.charAt(0)));
|
2090
|
+
}
|
2091
|
+
resetMaskSet();
|
2092
|
+
if (!strict && opts.autoUnmask !== true) {
|
2093
|
+
var staticInput = getBufferTemplate().slice(0, seekNext(-1)).join(""), matches = inputValue.join("").match(new RegExp("^" + Inputmask.escapeRegex(staticInput), "g"));
|
2094
|
+
if (matches && matches.length > 0) {
|
2095
|
+
inputValue.splice(0, matches.length * staticInput.length);
|
2096
|
+
initialNdx = seekNext(initialNdx);
|
2097
|
+
}
|
2098
|
+
} else {
|
2099
|
+
initialNdx = seekNext(initialNdx);
|
2100
|
+
}
|
2101
|
+
if (initialNdx === -1) {
|
2102
|
+
getMaskSet().p = seekNext(initialNdx);
|
2103
|
+
initialNdx = 0;
|
2104
|
+
} else getMaskSet().p = initialNdx;
|
2105
|
+
inputmask.caretPos = {
|
2106
|
+
begin: initialNdx
|
2107
|
+
};
|
2108
|
+
$.each(inputValue, function(ndx, charCode) {
|
2109
|
+
if (charCode !== undefined) {
|
2110
|
+
if (getMaskSet().validPositions[ndx] === undefined && inputValue[ndx] === getPlaceholder(ndx) && isMask(ndx, true) && isValid(ndx, inputValue[ndx], true, undefined, undefined, true) === false) {
|
2111
|
+
getMaskSet().p++;
|
2112
|
+
} else {
|
2113
|
+
var keypress = new $.Event("_checkval");
|
2114
|
+
keypress.which = charCode.charCodeAt(0);
|
2115
|
+
charCodes += charCode;
|
2116
|
+
var lvp = getLastValidPosition(undefined, true);
|
2117
|
+
if (!isTemplateMatch(initialNdx, charCodes)) {
|
2118
|
+
result = EventHandlers.keypressEvent.call(input, keypress, true, false, strict, inputmask.caretPos.begin);
|
2119
|
+
if (result) {
|
2120
|
+
initialNdx = inputmask.caretPos.begin + 1;
|
2121
|
+
charCodes = "";
|
2122
|
+
}
|
2123
|
+
} else {
|
2124
|
+
result = EventHandlers.keypressEvent.call(input, keypress, true, false, strict, lvp + 1);
|
2125
|
+
}
|
2126
|
+
if (result) {
|
2127
|
+
writeBuffer(undefined, getBuffer(), result.forwardPosition, keypress, false);
|
2128
|
+
inputmask.caretPos = {
|
2129
|
+
begin: result.forwardPosition,
|
2130
|
+
end: result.forwardPosition
|
2131
|
+
};
|
2132
|
+
}
|
2133
|
+
}
|
2134
|
+
}
|
2135
|
+
});
|
2136
|
+
if (writeOut) writeBuffer(input, getBuffer(), result ? result.forwardPosition : undefined, initiatingEvent || new $.Event("checkval"), initiatingEvent && initiatingEvent.type === "input");
|
2137
|
+
}
|
2138
|
+
function unmaskedvalue(input) {
|
2139
|
+
if (input) {
|
2140
|
+
if (input.inputmask === undefined) {
|
2141
|
+
return input.value;
|
2142
|
+
}
|
2143
|
+
if (input.inputmask && input.inputmask.refreshValue) {
|
2144
|
+
EventHandlers.setValueEvent.call(input);
|
2145
|
+
}
|
2146
|
+
}
|
2147
|
+
var umValue = [], vps = getMaskSet().validPositions;
|
2148
|
+
for (var pndx in vps) {
|
2149
|
+
if (vps[pndx].match && vps[pndx].match.fn != null) {
|
2150
|
+
umValue.push(vps[pndx].input);
|
2151
|
+
}
|
2152
|
+
}
|
2153
|
+
var unmaskedValue = umValue.length === 0 ? "" : (isRTL ? umValue.reverse() : umValue).join("");
|
2154
|
+
if ($.isFunction(opts.onUnMask)) {
|
2155
|
+
var bufferValue = (isRTL ? getBuffer().slice().reverse() : getBuffer()).join("");
|
2156
|
+
unmaskedValue = opts.onUnMask.call(inputmask, bufferValue, unmaskedValue, opts);
|
2157
|
+
}
|
2158
|
+
return unmaskedValue;
|
2159
|
+
}
|
2160
|
+
function caret(input, begin, end, notranslate) {
|
2161
|
+
function translatePosition(pos) {
|
2162
|
+
if (isRTL && typeof pos === "number" && (!opts.greedy || opts.placeholder !== "") && el) {
|
2163
|
+
pos = el.inputmask._valueGet().length - pos;
|
2164
|
+
}
|
2165
|
+
return pos;
|
2166
|
+
}
|
2167
|
+
var range;
|
2168
|
+
if (begin !== undefined) {
|
2169
|
+
if ($.isArray(begin)) {
|
2170
|
+
end = isRTL ? begin[0] : begin[1];
|
2171
|
+
begin = isRTL ? begin[1] : begin[0];
|
2172
|
+
}
|
2173
|
+
if (begin.begin !== undefined) {
|
2174
|
+
end = isRTL ? begin.begin : begin.end;
|
2175
|
+
begin = isRTL ? begin.end : begin.begin;
|
2176
|
+
}
|
2177
|
+
if (typeof begin === "number") {
|
2178
|
+
begin = notranslate ? begin : translatePosition(begin);
|
2179
|
+
end = notranslate ? end : translatePosition(end);
|
2180
|
+
end = typeof end == "number" ? end : begin;
|
2181
|
+
var scrollCalc = parseInt(((input.ownerDocument.defaultView || window).getComputedStyle ? (input.ownerDocument.defaultView || window).getComputedStyle(input, null) : input.currentStyle).fontSize) * end;
|
2182
|
+
input.scrollLeft = scrollCalc > input.scrollWidth ? scrollCalc : 0;
|
2183
|
+
input.inputmask.caretPos = {
|
2184
|
+
begin: begin,
|
2185
|
+
end: end
|
2186
|
+
};
|
2187
|
+
if (input === document.activeElement) {
|
2188
|
+
if ("selectionStart" in input) {
|
2189
|
+
input.selectionStart = begin;
|
2190
|
+
input.selectionEnd = end;
|
2191
|
+
} else if (window.getSelection) {
|
2192
|
+
range = document.createRange();
|
2193
|
+
if (input.firstChild === undefined || input.firstChild === null) {
|
2194
|
+
var textNode = document.createTextNode("");
|
2195
|
+
input.appendChild(textNode);
|
2196
|
+
}
|
2197
|
+
range.setStart(input.firstChild, begin < input.inputmask._valueGet().length ? begin : input.inputmask._valueGet().length);
|
2198
|
+
range.setEnd(input.firstChild, end < input.inputmask._valueGet().length ? end : input.inputmask._valueGet().length);
|
2199
|
+
range.collapse(true);
|
2200
|
+
var sel = window.getSelection();
|
2201
|
+
sel.removeAllRanges();
|
2202
|
+
sel.addRange(range);
|
2203
|
+
} else if (input.createTextRange) {
|
2204
|
+
range = input.createTextRange();
|
2205
|
+
range.collapse(true);
|
2206
|
+
range.moveEnd("character", end);
|
2207
|
+
range.moveStart("character", begin);
|
2208
|
+
range.select();
|
2209
|
+
}
|
2210
|
+
renderColorMask(input, {
|
2211
|
+
begin: begin,
|
2212
|
+
end: end
|
2213
|
+
});
|
2214
|
+
}
|
2215
|
+
}
|
2216
|
+
} else {
|
2217
|
+
if ("selectionStart" in input) {
|
2218
|
+
begin = input.selectionStart;
|
2219
|
+
end = input.selectionEnd;
|
2220
|
+
} else if (window.getSelection) {
|
2221
|
+
range = window.getSelection().getRangeAt(0);
|
2222
|
+
if (range.commonAncestorContainer.parentNode === input || range.commonAncestorContainer === input) {
|
2223
|
+
begin = range.startOffset;
|
2224
|
+
end = range.endOffset;
|
2225
|
+
}
|
2226
|
+
} else if (document.selection && document.selection.createRange) {
|
2227
|
+
range = document.selection.createRange();
|
2228
|
+
begin = 0 - range.duplicate().moveStart("character", -input.inputmask._valueGet().length);
|
2229
|
+
end = begin + range.text.length;
|
2230
|
+
}
|
2231
|
+
return {
|
2232
|
+
begin: notranslate ? begin : translatePosition(begin),
|
2233
|
+
end: notranslate ? end : translatePosition(end)
|
2234
|
+
};
|
2235
|
+
}
|
2236
|
+
}
|
2237
|
+
function determineLastRequiredPosition(returnDefinition) {
|
2238
|
+
var buffer = getMaskTemplate(true, getLastValidPosition(), true, true), bl = buffer.length, pos, lvp = getLastValidPosition(), positions = {}, lvTest = getMaskSet().validPositions[lvp], ndxIntlzr = lvTest !== undefined ? lvTest.locator.slice() : undefined, testPos;
|
2239
|
+
for (pos = lvp + 1; pos < buffer.length; pos++) {
|
2240
|
+
testPos = getTestTemplate(pos, ndxIntlzr, pos - 1);
|
2241
|
+
ndxIntlzr = testPos.locator.slice();
|
2242
|
+
positions[pos] = $.extend(true, {}, testPos);
|
2243
|
+
}
|
2244
|
+
var lvTestAlt = lvTest && lvTest.alternation !== undefined ? lvTest.locator[lvTest.alternation] : undefined;
|
2245
|
+
for (pos = bl - 1; pos > lvp; pos--) {
|
2246
|
+
testPos = positions[pos];
|
2247
|
+
if ((testPos.match.optionality || testPos.match.optionalQuantifier && testPos.match.newBlockMarker || lvTestAlt && (lvTestAlt !== positions[pos].locator[lvTest.alternation] && testPos.match.fn != null || testPos.match.fn === null && testPos.locator[lvTest.alternation] && checkAlternationMatch(testPos.locator[lvTest.alternation].toString().split(","), lvTestAlt.toString().split(",")) && getTests(pos)[0].def !== "")) && buffer[pos] === getPlaceholder(pos, testPos.match)) {
|
2248
|
+
bl--;
|
2249
|
+
} else break;
|
2250
|
+
}
|
2251
|
+
return returnDefinition ? {
|
2252
|
+
l: bl,
|
2253
|
+
def: positions[bl] ? positions[bl].match : undefined
|
2254
|
+
} : bl;
|
2255
|
+
}
|
2256
|
+
function clearOptionalTail(buffer) {
|
2257
|
+
buffer.length = 0;
|
2258
|
+
var template = getMaskTemplate(true, 0, true, undefined, true), lmnt, validPos;
|
2259
|
+
while (lmnt = template.shift(), lmnt !== undefined) buffer.push(lmnt);
|
2260
|
+
return buffer;
|
2261
|
+
}
|
2262
|
+
function isComplete(buffer) {
|
2263
|
+
if ($.isFunction(opts.isComplete)) return opts.isComplete(buffer, opts);
|
2264
|
+
if (opts.repeat === "*") return undefined;
|
2265
|
+
var complete = false, lrp = determineLastRequiredPosition(true), aml = seekPrevious(lrp.l);
|
2266
|
+
if (lrp.def === undefined || lrp.def.newBlockMarker || lrp.def.optionality || lrp.def.optionalQuantifier) {
|
2267
|
+
complete = true;
|
2268
|
+
for (var i = 0; i <= aml; i++) {
|
2269
|
+
var test = getTestTemplate(i).match;
|
2270
|
+
if (test.fn !== null && getMaskSet().validPositions[i] === undefined && test.optionality !== true && test.optionalQuantifier !== true || test.fn === null && buffer[i] !== getPlaceholder(i, test)) {
|
2271
|
+
complete = false;
|
2272
|
+
break;
|
2273
|
+
}
|
2274
|
+
}
|
2275
|
+
}
|
2276
|
+
return complete;
|
2277
|
+
}
|
2278
|
+
function handleRemove(input, k, pos, strict, fromIsValid) {
|
2279
|
+
if (opts.numericInput || isRTL) {
|
2280
|
+
if (k === Inputmask.keyCode.BACKSPACE) {
|
2281
|
+
k = Inputmask.keyCode.DELETE;
|
2282
|
+
} else if (k === Inputmask.keyCode.DELETE) {
|
2283
|
+
k = Inputmask.keyCode.BACKSPACE;
|
2284
|
+
}
|
2285
|
+
if (isRTL) {
|
2286
|
+
var pend = pos.end;
|
2287
|
+
pos.end = pos.begin;
|
2288
|
+
pos.begin = pend;
|
2289
|
+
}
|
2290
|
+
}
|
2291
|
+
if (k === Inputmask.keyCode.BACKSPACE && pos.end - pos.begin < 1) {
|
2292
|
+
pos.begin = seekPrevious(pos.begin);
|
2293
|
+
if (getMaskSet().validPositions[pos.begin] !== undefined && getMaskSet().validPositions[pos.begin].input === opts.groupSeparator) {
|
2294
|
+
pos.begin--;
|
2295
|
+
}
|
2296
|
+
} else if (k === Inputmask.keyCode.DELETE && pos.begin === pos.end) {
|
2297
|
+
pos.end = isMask(pos.end, true) && (getMaskSet().validPositions[pos.end] && getMaskSet().validPositions[pos.end].input !== opts.radixPoint) ? pos.end + 1 : seekNext(pos.end) + 1;
|
2298
|
+
if (getMaskSet().validPositions[pos.begin] !== undefined && getMaskSet().validPositions[pos.begin].input === opts.groupSeparator) {
|
2299
|
+
pos.end++;
|
2300
|
+
}
|
2301
|
+
}
|
2302
|
+
revalidateMask(pos);
|
2303
|
+
if (strict !== true && opts.keepStatic !== false || opts.regex !== null) {
|
2304
|
+
var result = alternate(true);
|
2305
|
+
if (result) {
|
2306
|
+
var newPos = result.caret !== undefined ? result.caret : result.pos ? seekNext(result.pos.begin ? result.pos.begin : result.pos) : getLastValidPosition(-1, true);
|
2307
|
+
if (k !== Inputmask.keyCode.DELETE || pos.begin > newPos) {
|
2308
|
+
pos.begin == newPos;
|
2309
|
+
}
|
2310
|
+
}
|
2311
|
+
}
|
2312
|
+
var lvp = getLastValidPosition(pos.begin, true);
|
2313
|
+
if (lvp < pos.begin || pos.begin === -1) {
|
2314
|
+
getMaskSet().p = seekNext(lvp);
|
2315
|
+
} else if (strict !== true) {
|
2316
|
+
getMaskSet().p = pos.begin;
|
2317
|
+
if (fromIsValid !== true) {
|
2318
|
+
while (getMaskSet().p < lvp && getMaskSet().validPositions[getMaskSet().p] === undefined) {
|
2319
|
+
getMaskSet().p++;
|
2320
|
+
}
|
2321
|
+
}
|
2322
|
+
}
|
2323
|
+
}
|
2324
|
+
function initializeColorMask(input) {
|
2325
|
+
var computedStyle = (input.ownerDocument.defaultView || window).getComputedStyle(input, null);
|
2326
|
+
function findCaretPos(clientx) {
|
2327
|
+
var e = document.createElement("span"), caretPos;
|
2328
|
+
for (var style in computedStyle) {
|
2329
|
+
if (isNaN(style) && style.indexOf("font") !== -1) {
|
2330
|
+
e.style[style] = computedStyle[style];
|
2331
|
+
}
|
2332
|
+
}
|
2333
|
+
e.style.textTransform = computedStyle.textTransform;
|
2334
|
+
e.style.letterSpacing = computedStyle.letterSpacing;
|
2335
|
+
e.style.position = "absolute";
|
2336
|
+
e.style.height = "auto";
|
2337
|
+
e.style.width = "auto";
|
2338
|
+
e.style.visibility = "hidden";
|
2339
|
+
e.style.whiteSpace = "nowrap";
|
2340
|
+
document.body.appendChild(e);
|
2341
|
+
var inputText = input.inputmask._valueGet(), previousWidth = 0, itl;
|
2342
|
+
for (caretPos = 0, itl = inputText.length; caretPos <= itl; caretPos++) {
|
2343
|
+
e.innerHTML += inputText.charAt(caretPos) || "_";
|
2344
|
+
if (e.offsetWidth >= clientx) {
|
2345
|
+
var offset1 = clientx - previousWidth;
|
2346
|
+
var offset2 = e.offsetWidth - clientx;
|
2347
|
+
e.innerHTML = inputText.charAt(caretPos);
|
2348
|
+
offset1 -= e.offsetWidth / 3;
|
2349
|
+
caretPos = offset1 < offset2 ? caretPos - 1 : caretPos;
|
2350
|
+
break;
|
2351
|
+
}
|
2352
|
+
previousWidth = e.offsetWidth;
|
2353
|
+
}
|
2354
|
+
document.body.removeChild(e);
|
2355
|
+
return caretPos;
|
2356
|
+
}
|
2357
|
+
var template = document.createElement("div");
|
2358
|
+
template.style.width = computedStyle.width;
|
2359
|
+
template.style.textAlign = computedStyle.textAlign;
|
2360
|
+
colorMask = document.createElement("div");
|
2361
|
+
input.inputmask.colorMask = colorMask;
|
2362
|
+
colorMask.className = "im-colormask";
|
2363
|
+
input.parentNode.insertBefore(colorMask, input);
|
2364
|
+
input.parentNode.removeChild(input);
|
2365
|
+
colorMask.appendChild(input);
|
2366
|
+
colorMask.appendChild(template);
|
2367
|
+
input.style.left = template.offsetLeft + "px";
|
2368
|
+
$(colorMask).on("mouseleave", function(e) {
|
2369
|
+
return EventHandlers.mouseleaveEvent.call(input, [ e ]);
|
2370
|
+
});
|
2371
|
+
$(colorMask).on("mouseenter", function(e) {
|
2372
|
+
return EventHandlers.mouseenterEvent.call(input, [ e ]);
|
2373
|
+
});
|
2374
|
+
$(colorMask).on("click", function(e) {
|
2375
|
+
caret(input, findCaretPos(e.clientX));
|
2376
|
+
return EventHandlers.clickEvent.call(input, [ e ]);
|
2377
|
+
});
|
2378
|
+
}
|
2379
|
+
function renderColorMask(input, caretPos, clear) {
|
2380
|
+
var maskTemplate = [], isStatic = false, test, testPos, ndxIntlzr, pos = 0;
|
2381
|
+
function setEntry(entry) {
|
2382
|
+
if (entry === undefined) entry = "";
|
2383
|
+
if (!isStatic && (test.fn === null || testPos.input === undefined)) {
|
2384
|
+
isStatic = true;
|
2385
|
+
maskTemplate.push("<span class='im-static'>" + entry);
|
2386
|
+
} else if (isStatic && (test.fn !== null && testPos.input !== undefined || test.def === "")) {
|
2387
|
+
isStatic = false;
|
2388
|
+
var mtl = maskTemplate.length;
|
2389
|
+
maskTemplate[mtl - 1] = maskTemplate[mtl - 1] + "</span>";
|
2390
|
+
maskTemplate.push(entry);
|
2391
|
+
} else maskTemplate.push(entry);
|
2392
|
+
}
|
2393
|
+
function setCaret() {
|
2394
|
+
if (document.activeElement === input) {
|
2395
|
+
maskTemplate.splice(caretPos.begin, 0, caretPos.begin === caretPos.end || caretPos.end > getMaskSet().maskLength ? '<mark class="im-caret" style="border-right-width: 1px;border-right-style: solid;">' : '<mark class="im-caret-select">');
|
2396
|
+
maskTemplate.splice(caretPos.end + 1, 0, "</mark>");
|
2397
|
+
}
|
2398
|
+
}
|
2399
|
+
if (colorMask !== undefined) {
|
2400
|
+
var buffer = getBuffer();
|
2401
|
+
if (caretPos === undefined) {
|
2402
|
+
caretPos = caret(input);
|
2403
|
+
} else if (caretPos.begin === undefined) {
|
2404
|
+
caretPos = {
|
2405
|
+
begin: caretPos,
|
2406
|
+
end: caretPos
|
2407
|
+
};
|
2408
|
+
}
|
2409
|
+
if (clear !== true) {
|
2410
|
+
var lvp = getLastValidPosition();
|
2411
|
+
do {
|
2412
|
+
if (getMaskSet().validPositions[pos]) {
|
2413
|
+
testPos = getMaskSet().validPositions[pos];
|
2414
|
+
test = testPos.match;
|
2415
|
+
ndxIntlzr = testPos.locator.slice();
|
2416
|
+
setEntry(buffer[pos]);
|
2417
|
+
} else {
|
2418
|
+
testPos = getTestTemplate(pos, ndxIntlzr, pos - 1);
|
2419
|
+
test = testPos.match;
|
2420
|
+
ndxIntlzr = testPos.locator.slice();
|
2421
|
+
if (opts.jitMasking === false || pos < lvp || typeof opts.jitMasking === "number" && isFinite(opts.jitMasking) && opts.jitMasking > pos) {
|
2422
|
+
setEntry(getPlaceholder(pos, test));
|
2423
|
+
} else isStatic = false;
|
2424
|
+
}
|
2425
|
+
pos++;
|
2426
|
+
} while ((maxLength === undefined || pos < maxLength) && (test.fn !== null || test.def !== "") || lvp > pos || isStatic);
|
2427
|
+
if (isStatic) setEntry();
|
2428
|
+
setCaret();
|
2429
|
+
}
|
2430
|
+
var template = colorMask.getElementsByTagName("div")[0];
|
2431
|
+
template.innerHTML = maskTemplate.join("");
|
2432
|
+
input.inputmask.positionColorMask(input, template);
|
2433
|
+
}
|
2434
|
+
}
|
2435
|
+
function mask(elem) {
|
2436
|
+
function isElementTypeSupported(input, opts) {
|
2437
|
+
function patchValueProperty(npt) {
|
2438
|
+
var valueGet;
|
2439
|
+
var valueSet;
|
2440
|
+
function patchValhook(type) {
|
2441
|
+
if ($.valHooks && ($.valHooks[type] === undefined || $.valHooks[type].inputmaskpatch !== true)) {
|
2442
|
+
var valhookGet = $.valHooks[type] && $.valHooks[type].get ? $.valHooks[type].get : function(elem) {
|
2443
|
+
return elem.value;
|
2444
|
+
};
|
2445
|
+
var valhookSet = $.valHooks[type] && $.valHooks[type].set ? $.valHooks[type].set : function(elem, value) {
|
2446
|
+
elem.value = value;
|
2447
|
+
return elem;
|
2448
|
+
};
|
2449
|
+
$.valHooks[type] = {
|
2450
|
+
get: function(elem) {
|
2451
|
+
if (elem.inputmask) {
|
2452
|
+
if (elem.inputmask.opts.autoUnmask) {
|
2453
|
+
return elem.inputmask.unmaskedvalue();
|
2454
|
+
} else {
|
2455
|
+
var result = valhookGet(elem);
|
2456
|
+
return getLastValidPosition(undefined, undefined, elem.inputmask.maskset.validPositions) !== -1 || opts.nullable !== true ? result : "";
|
2457
|
+
}
|
2458
|
+
} else return valhookGet(elem);
|
2459
|
+
},
|
2460
|
+
set: function(elem, value) {
|
2461
|
+
var $elem = $(elem), result;
|
2462
|
+
result = valhookSet(elem, value);
|
2463
|
+
if (elem.inputmask) {
|
2464
|
+
$elem.trigger("setvalue", [ value ]);
|
2465
|
+
}
|
2466
|
+
return result;
|
2467
|
+
},
|
2468
|
+
inputmaskpatch: true
|
2469
|
+
};
|
2470
|
+
}
|
2471
|
+
}
|
2472
|
+
function getter() {
|
2473
|
+
if (this.inputmask) {
|
2474
|
+
return this.inputmask.opts.autoUnmask ? this.inputmask.unmaskedvalue() : getLastValidPosition() !== -1 || opts.nullable !== true ? document.activeElement === this && opts.clearMaskOnLostFocus ? (isRTL ? clearOptionalTail(getBuffer().slice()).reverse() : clearOptionalTail(getBuffer().slice())).join("") : valueGet.call(this) : "";
|
2475
|
+
} else return valueGet.call(this);
|
2476
|
+
}
|
2477
|
+
function setter(value) {
|
2478
|
+
valueSet.call(this, value);
|
2479
|
+
if (this.inputmask) {
|
2480
|
+
$(this).trigger("setvalue", [ value ]);
|
2481
|
+
}
|
2482
|
+
}
|
2483
|
+
function installNativeValueSetFallback(npt) {
|
2484
|
+
EventRuler.on(npt, "mouseenter", function(event) {
|
2485
|
+
var $input = $(this), input = this, value = input.inputmask._valueGet();
|
2486
|
+
if (value !== getBuffer().join("")) {
|
2487
|
+
$input.trigger("setvalue");
|
2488
|
+
}
|
2489
|
+
});
|
2490
|
+
}
|
2491
|
+
if (!npt.inputmask.__valueGet) {
|
2492
|
+
if (opts.noValuePatching !== true) {
|
2493
|
+
if (Object.getOwnPropertyDescriptor) {
|
2494
|
+
if (typeof Object.getPrototypeOf !== "function") {
|
2495
|
+
Object.getPrototypeOf = typeof "test".__proto__ === "object" ? function(object) {
|
2496
|
+
return object.__proto__;
|
2497
|
+
} : function(object) {
|
2498
|
+
return object.constructor.prototype;
|
2499
|
+
};
|
2500
|
+
}
|
2501
|
+
var valueProperty = Object.getPrototypeOf ? Object.getOwnPropertyDescriptor(Object.getPrototypeOf(npt), "value") : undefined;
|
2502
|
+
if (valueProperty && valueProperty.get && valueProperty.set) {
|
2503
|
+
valueGet = valueProperty.get;
|
2504
|
+
valueSet = valueProperty.set;
|
2505
|
+
Object.defineProperty(npt, "value", {
|
2506
|
+
get: getter,
|
2507
|
+
set: setter,
|
2508
|
+
configurable: true
|
2509
|
+
});
|
2510
|
+
} else if (npt.tagName !== "INPUT") {
|
2511
|
+
valueGet = function() {
|
2512
|
+
return this.textContent;
|
2513
|
+
};
|
2514
|
+
valueSet = function(value) {
|
2515
|
+
this.textContent = value;
|
2516
|
+
};
|
2517
|
+
Object.defineProperty(npt, "value", {
|
2518
|
+
get: getter,
|
2519
|
+
set: setter,
|
2520
|
+
configurable: true
|
2521
|
+
});
|
2522
|
+
}
|
2523
|
+
} else if (document.__lookupGetter__ && npt.__lookupGetter__("value")) {
|
2524
|
+
valueGet = npt.__lookupGetter__("value");
|
2525
|
+
valueSet = npt.__lookupSetter__("value");
|
2526
|
+
npt.__defineGetter__("value", getter);
|
2527
|
+
npt.__defineSetter__("value", setter);
|
2528
|
+
}
|
2529
|
+
npt.inputmask.__valueGet = valueGet;
|
2530
|
+
npt.inputmask.__valueSet = valueSet;
|
2531
|
+
}
|
2532
|
+
npt.inputmask._valueGet = function(overruleRTL) {
|
2533
|
+
return isRTL && overruleRTL !== true ? valueGet.call(this.el).split("").reverse().join("") : valueGet.call(this.el);
|
2534
|
+
};
|
2535
|
+
npt.inputmask._valueSet = function(value, overruleRTL) {
|
2536
|
+
valueSet.call(this.el, value === null || value === undefined ? "" : overruleRTL !== true && isRTL ? value.split("").reverse().join("") : value);
|
2537
|
+
};
|
2538
|
+
if (valueGet === undefined) {
|
2539
|
+
valueGet = function() {
|
2540
|
+
return this.value;
|
2541
|
+
};
|
2542
|
+
valueSet = function(value) {
|
2543
|
+
this.value = value;
|
2544
|
+
};
|
2545
|
+
patchValhook(npt.type);
|
2546
|
+
installNativeValueSetFallback(npt);
|
2547
|
+
}
|
2548
|
+
}
|
2549
|
+
}
|
2550
|
+
var elementType = input.getAttribute("type");
|
2551
|
+
var isSupported = input.tagName === "INPUT" && $.inArray(elementType, opts.supportsInputType) !== -1 || input.isContentEditable || input.tagName === "TEXTAREA";
|
2552
|
+
if (!isSupported) {
|
2553
|
+
if (input.tagName === "INPUT") {
|
2554
|
+
var el = document.createElement("input");
|
2555
|
+
el.setAttribute("type", elementType);
|
2556
|
+
isSupported = el.type === "text";
|
2557
|
+
el = null;
|
2558
|
+
} else isSupported = "partial";
|
2559
|
+
}
|
2560
|
+
if (isSupported !== false) {
|
2561
|
+
patchValueProperty(input);
|
2562
|
+
} else input.inputmask = undefined;
|
2563
|
+
return isSupported;
|
2564
|
+
}
|
2565
|
+
EventRuler.off(elem);
|
2566
|
+
var isSupported = isElementTypeSupported(elem, opts);
|
2567
|
+
if (isSupported !== false) {
|
2568
|
+
el = elem;
|
2569
|
+
$el = $(el);
|
2570
|
+
originalPlaceholder = el.placeholder;
|
2571
|
+
maxLength = el !== undefined ? el.maxLength : undefined;
|
2572
|
+
if (maxLength === -1) maxLength = undefined;
|
2573
|
+
if (opts.colorMask === true) {
|
2574
|
+
initializeColorMask(el);
|
2575
|
+
}
|
2576
|
+
if (mobile) {
|
2577
|
+
if ("inputMode" in el) {
|
2578
|
+
el.inputmode = opts.inputmode;
|
2579
|
+
el.setAttribute("inputmode", opts.inputmode);
|
2580
|
+
}
|
2581
|
+
if (opts.disablePredictiveText === true) {
|
2582
|
+
if ("autocorrect" in el) {
|
2583
|
+
el.autocorrect = false;
|
2584
|
+
} else {
|
2585
|
+
if (opts.colorMask !== true) {
|
2586
|
+
initializeColorMask(el);
|
2587
|
+
}
|
2588
|
+
el.type = "password";
|
2589
|
+
}
|
2590
|
+
}
|
2591
|
+
}
|
2592
|
+
if (isSupported === true) {
|
2593
|
+
el.setAttribute("im-insert", opts.insertMode);
|
2594
|
+
EventRuler.on(el, "submit", EventHandlers.submitEvent);
|
2595
|
+
EventRuler.on(el, "reset", EventHandlers.resetEvent);
|
2596
|
+
EventRuler.on(el, "blur", EventHandlers.blurEvent);
|
2597
|
+
EventRuler.on(el, "focus", EventHandlers.focusEvent);
|
2598
|
+
if (opts.colorMask !== true) {
|
2599
|
+
EventRuler.on(el, "click", EventHandlers.clickEvent);
|
2600
|
+
EventRuler.on(el, "mouseleave", EventHandlers.mouseleaveEvent);
|
2601
|
+
EventRuler.on(el, "mouseenter", EventHandlers.mouseenterEvent);
|
2602
|
+
}
|
2603
|
+
EventRuler.on(el, "paste", EventHandlers.pasteEvent);
|
2604
|
+
EventRuler.on(el, "cut", EventHandlers.cutEvent);
|
2605
|
+
EventRuler.on(el, "complete", opts.oncomplete);
|
2606
|
+
EventRuler.on(el, "incomplete", opts.onincomplete);
|
2607
|
+
EventRuler.on(el, "cleared", opts.oncleared);
|
2608
|
+
if (!mobile && opts.inputEventOnly !== true) {
|
2609
|
+
EventRuler.on(el, "keydown", EventHandlers.keydownEvent);
|
2610
|
+
EventRuler.on(el, "keypress", EventHandlers.keypressEvent);
|
2611
|
+
} else {
|
2612
|
+
el.removeAttribute("maxLength");
|
2613
|
+
}
|
2614
|
+
EventRuler.on(el, "input", EventHandlers.inputFallBackEvent);
|
2615
|
+
EventRuler.on(el, "beforeinput", EventHandlers.beforeInputEvent);
|
2616
|
+
}
|
2617
|
+
EventRuler.on(el, "setvalue", EventHandlers.setValueEvent);
|
2618
|
+
undoValue = getBufferTemplate().join("");
|
2619
|
+
if (el.inputmask._valueGet(true) !== "" || opts.clearMaskOnLostFocus === false || document.activeElement === el) {
|
2620
|
+
var initialValue = $.isFunction(opts.onBeforeMask) ? opts.onBeforeMask.call(inputmask, el.inputmask._valueGet(true), opts) || el.inputmask._valueGet(true) : el.inputmask._valueGet(true);
|
2621
|
+
if (initialValue !== "") checkVal(el, true, false, initialValue.split(""));
|
2622
|
+
var buffer = getBuffer().slice();
|
2623
|
+
undoValue = buffer.join("");
|
2624
|
+
if (isComplete(buffer) === false) {
|
2625
|
+
if (opts.clearIncomplete) {
|
2626
|
+
resetMaskSet();
|
2627
|
+
}
|
2628
|
+
}
|
2629
|
+
if (opts.clearMaskOnLostFocus && document.activeElement !== el) {
|
2630
|
+
if (getLastValidPosition() === -1) {
|
2631
|
+
buffer = [];
|
2632
|
+
} else {
|
2633
|
+
clearOptionalTail(buffer);
|
2634
|
+
}
|
2635
|
+
}
|
2636
|
+
if (opts.clearMaskOnLostFocus === false || opts.showMaskOnFocus && document.activeElement === el || el.inputmask._valueGet(true) !== "") writeBuffer(el, buffer);
|
2637
|
+
if (document.activeElement === el) {
|
2638
|
+
caret(el, seekNext(getLastValidPosition()));
|
2639
|
+
}
|
2640
|
+
}
|
2641
|
+
}
|
2642
|
+
}
|
2643
|
+
var valueBuffer;
|
2644
|
+
if (actionObj !== undefined) {
|
2645
|
+
switch (actionObj.action) {
|
2646
|
+
case "isComplete":
|
2647
|
+
el = actionObj.el;
|
2648
|
+
return isComplete(getBuffer());
|
2649
|
+
|
2650
|
+
case "unmaskedvalue":
|
2651
|
+
if (el === undefined || actionObj.value !== undefined) {
|
2652
|
+
valueBuffer = actionObj.value;
|
2653
|
+
valueBuffer = ($.isFunction(opts.onBeforeMask) ? opts.onBeforeMask.call(inputmask, valueBuffer, opts) || valueBuffer : valueBuffer).split("");
|
2654
|
+
checkVal.call(this, undefined, false, false, valueBuffer);
|
2655
|
+
if ($.isFunction(opts.onBeforeWrite)) opts.onBeforeWrite.call(inputmask, undefined, getBuffer(), 0, opts);
|
2656
|
+
}
|
2657
|
+
return unmaskedvalue(el);
|
2658
|
+
|
2659
|
+
case "mask":
|
2660
|
+
mask(el);
|
2661
|
+
break;
|
2662
|
+
|
2663
|
+
case "format":
|
2664
|
+
valueBuffer = ($.isFunction(opts.onBeforeMask) ? opts.onBeforeMask.call(inputmask, actionObj.value, opts) || actionObj.value : actionObj.value).split("");
|
2665
|
+
checkVal.call(this, undefined, true, false, valueBuffer);
|
2666
|
+
if (actionObj.metadata) {
|
2667
|
+
return {
|
2668
|
+
value: isRTL ? getBuffer().slice().reverse().join("") : getBuffer().join(""),
|
2669
|
+
metadata: maskScope.call(this, {
|
2670
|
+
action: "getmetadata"
|
2671
|
+
}, maskset, opts)
|
2672
|
+
};
|
2673
|
+
}
|
2674
|
+
return isRTL ? getBuffer().slice().reverse().join("") : getBuffer().join("");
|
2675
|
+
|
2676
|
+
case "isValid":
|
2677
|
+
if (actionObj.value) {
|
2678
|
+
valueBuffer = actionObj.value.split("");
|
2679
|
+
checkVal.call(this, undefined, true, true, valueBuffer);
|
2680
|
+
} else {
|
2681
|
+
actionObj.value = getBuffer().join("");
|
2682
|
+
}
|
2683
|
+
var buffer = getBuffer();
|
2684
|
+
var rl = determineLastRequiredPosition(), lmib = buffer.length - 1;
|
2685
|
+
for (;lmib > rl; lmib--) {
|
2686
|
+
if (isMask(lmib)) break;
|
2687
|
+
}
|
2688
|
+
buffer.splice(rl, lmib + 1 - rl);
|
2689
|
+
return isComplete(buffer) && actionObj.value === getBuffer().join("");
|
2690
|
+
|
2691
|
+
case "getemptymask":
|
2692
|
+
return getBufferTemplate().join("");
|
2693
|
+
|
2694
|
+
case "remove":
|
2695
|
+
if (el && el.inputmask) {
|
2696
|
+
$.data(el, "_inputmask_opts", null);
|
2697
|
+
$el = $(el);
|
2698
|
+
el.inputmask._valueSet(opts.autoUnmask ? unmaskedvalue(el) : el.inputmask._valueGet(true));
|
2699
|
+
EventRuler.off(el);
|
2700
|
+
if (el.inputmask.colorMask) {
|
2701
|
+
colorMask = el.inputmask.colorMask;
|
2702
|
+
colorMask.removeChild(el);
|
2703
|
+
colorMask.parentNode.insertBefore(el, colorMask);
|
2704
|
+
colorMask.parentNode.removeChild(colorMask);
|
2705
|
+
}
|
2706
|
+
var valueProperty;
|
2707
|
+
if (Object.getOwnPropertyDescriptor && Object.getPrototypeOf) {
|
2708
|
+
valueProperty = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(el), "value");
|
2709
|
+
if (valueProperty) {
|
2710
|
+
if (el.inputmask.__valueGet) {
|
2711
|
+
Object.defineProperty(el, "value", {
|
2712
|
+
get: el.inputmask.__valueGet,
|
2713
|
+
set: el.inputmask.__valueSet,
|
2714
|
+
configurable: true
|
2715
|
+
});
|
2716
|
+
}
|
2717
|
+
}
|
2718
|
+
} else if (document.__lookupGetter__ && el.__lookupGetter__("value")) {
|
2719
|
+
if (el.inputmask.__valueGet) {
|
2720
|
+
el.__defineGetter__("value", el.inputmask.__valueGet);
|
2721
|
+
el.__defineSetter__("value", el.inputmask.__valueSet);
|
2722
|
+
}
|
2723
|
+
}
|
2724
|
+
el.inputmask = undefined;
|
2725
|
+
}
|
2726
|
+
return el;
|
2727
|
+
break;
|
2728
|
+
|
2729
|
+
case "getmetadata":
|
2730
|
+
if ($.isArray(maskset.metadata)) {
|
2731
|
+
var maskTarget = getMaskTemplate(true, 0, false).join("");
|
2732
|
+
$.each(maskset.metadata, function(ndx, mtdt) {
|
2733
|
+
if (mtdt.mask === maskTarget) {
|
2734
|
+
maskTarget = mtdt;
|
2735
|
+
return false;
|
2736
|
+
}
|
2737
|
+
});
|
2738
|
+
return maskTarget;
|
2739
|
+
}
|
2740
|
+
return maskset.metadata;
|
2741
|
+
}
|
2742
|
+
}
|
2743
|
+
}
|
2744
|
+
return Inputmask;
|
2745
|
+
});
|