Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 1 | espaco | 1 | /*! |
| 2 | * jquery.inputmask.js |
||
| 3 | * http://github.com/RobinHerbots/jquery.inputmask |
||
| 4 | * Copyright (c) 2010 - 2014 Robin Herbots |
||
| 5 | * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php) |
||
| 6 | * Version: 3.1.34 |
||
| 7 | */ |
||
| 8 | !function(factory) { |
||
| 9 | "function" == typeof define && define.amd ? define([ "jquery" ], factory) : factory(jQuery); |
||
| 10 | }(function($) { |
||
| 11 | function isInputEventSupported(eventName) { |
||
| 12 | var el = document.createElement("input"), evName = "on" + eventName, isSupported = evName in el; |
||
| 13 | return isSupported || (el.setAttribute(evName, "return;"), isSupported = "function" == typeof el[evName]), |
||
| 14 | el = null, isSupported; |
||
| 15 | } |
||
| 16 | function isInputTypeSupported(inputType) { |
||
| 17 | var isSupported = "text" == inputType || "tel" == inputType; |
||
| 18 | if (!isSupported) { |
||
| 19 | var el = document.createElement("input"); |
||
| 20 | el.setAttribute("type", inputType), isSupported = "text" === el.type, el = null; |
||
| 21 | } |
||
| 22 | return isSupported; |
||
| 23 | } |
||
| 24 | function resolveAlias(aliasStr, options, opts) { |
||
| 25 | var aliasDefinition = opts.aliases[aliasStr]; |
||
| 26 | return aliasDefinition ? (aliasDefinition.alias && resolveAlias(aliasDefinition.alias, void 0, opts), |
||
| 27 | $.extend(!0, opts, aliasDefinition), $.extend(!0, opts, options), !0) : !1; |
||
| 28 | } |
||
| 29 | function generateMaskSet(opts, multi) { |
||
| 30 | function analyseMask(mask) { |
||
| 31 | function maskToken(isGroup, isOptional, isQuantifier, isAlternator) { |
||
| 32 | this.matches = [], this.isGroup = isGroup || !1, this.isOptional = isOptional || !1, |
||
| 33 | this.isQuantifier = isQuantifier || !1, this.isAlternator = isAlternator || !1, |
||
| 34 | this.quantifier = { |
||
| 35 | min: 1, |
||
| 36 | max: 1 |
||
| 37 | }; |
||
| 38 | } |
||
| 39 | function insertTestDefinition(mtoken, element, position) { |
||
| 40 | var maskdef = opts.definitions[element], newBlockMarker = 0 == mtoken.matches.length; |
||
| 41 | if (position = void 0 != position ? position : mtoken.matches.length, maskdef && !escaped) { |
||
| 42 | for (var prevalidators = maskdef.prevalidator, prevalidatorsL = prevalidators ? prevalidators.length : 0, i = 1; i < maskdef.cardinality; i++) { |
||
| 43 | var prevalidator = prevalidatorsL >= i ? prevalidators[i - 1] : [], validator = prevalidator.validator, cardinality = prevalidator.cardinality; |
||
| 44 | mtoken.matches.splice(position++, 0, { |
||
| 45 | fn: validator ? "string" == typeof validator ? new RegExp(validator) : new function() { |
||
| 46 | this.test = validator; |
||
| 47 | }() : new RegExp("."), |
||
| 48 | cardinality: cardinality ? cardinality : 1, |
||
| 49 | optionality: mtoken.isOptional, |
||
| 50 | newBlockMarker: newBlockMarker, |
||
| 51 | casing: maskdef.casing, |
||
| 52 | def: maskdef.definitionSymbol || element, |
||
| 53 | placeholder: maskdef.placeholder, |
||
| 54 | mask: element |
||
| 55 | }); |
||
| 56 | } |
||
| 57 | mtoken.matches.splice(position++, 0, { |
||
| 58 | fn: maskdef.validator ? "string" == typeof maskdef.validator ? new RegExp(maskdef.validator) : new function() { |
||
| 59 | this.test = maskdef.validator; |
||
| 60 | }() : new RegExp("."), |
||
| 61 | cardinality: maskdef.cardinality, |
||
| 62 | optionality: mtoken.isOptional, |
||
| 63 | newBlockMarker: newBlockMarker, |
||
| 64 | casing: maskdef.casing, |
||
| 65 | def: maskdef.definitionSymbol || element, |
||
| 66 | placeholder: maskdef.placeholder, |
||
| 67 | mask: element |
||
| 68 | }); |
||
| 69 | } else mtoken.matches.splice(position++, 0, { |
||
| 70 | fn: null, |
||
| 71 | cardinality: 0, |
||
| 72 | optionality: mtoken.isOptional, |
||
| 73 | newBlockMarker: newBlockMarker, |
||
| 74 | casing: null, |
||
| 75 | def: element, |
||
| 76 | placeholder: void 0, |
||
| 77 | mask: element |
||
| 78 | }), escaped = !1; |
||
| 79 | } |
||
| 80 | for (var match, m, openingToken, currentOpeningToken, alternator, lastMatch, tokenizer = /(?:[?*+]|\{[0-9\+\*]+(?:,[0-9\+\*]*)?\})\??|[^.?*+^${[]()|\\]+|./g, escaped = !1, currentToken = new maskToken(), openenings = [], maskTokens = []; match = tokenizer.exec(mask); ) switch (m = match[0], |
||
| 81 | m.charAt(0)) { |
||
| 82 | case opts.optionalmarker.end: |
||
| 83 | case opts.groupmarker.end: |
||
| 84 | if (openingToken = openenings.pop(), openenings.length > 0) { |
||
| 85 | if (currentOpeningToken = openenings[openenings.length - 1], currentOpeningToken.matches.push(openingToken), |
||
| 86 | currentOpeningToken.isAlternator) { |
||
| 87 | alternator = openenings.pop(); |
||
| 88 | for (var mndx = 0; mndx < alternator.matches.length; mndx++) alternator.matches[mndx].isGroup = !1; |
||
| 89 | openenings.length > 0 ? (currentOpeningToken = openenings[openenings.length - 1], |
||
| 90 | currentOpeningToken.matches.push(alternator)) : currentToken.matches.push(alternator); |
||
| 91 | } |
||
| 92 | } else currentToken.matches.push(openingToken); |
||
| 93 | break; |
||
| 94 | |||
| 95 | case opts.optionalmarker.start: |
||
| 96 | openenings.push(new maskToken(!1, !0)); |
||
| 97 | break; |
||
| 98 | |||
| 99 | case opts.groupmarker.start: |
||
| 100 | openenings.push(new maskToken(!0)); |
||
| 101 | break; |
||
| 102 | |||
| 103 | case opts.quantifiermarker.start: |
||
| 104 | var quantifier = new maskToken(!1, !1, !0); |
||
| 105 | m = m.replace(/[{}]/g, ""); |
||
| 106 | var mq = m.split(","), mq0 = isNaN(mq[0]) ? mq[0] : parseInt(mq[0]), mq1 = 1 == mq.length ? mq0 : isNaN(mq[1]) ? mq[1] : parseInt(mq[1]); |
||
| 107 | if (("*" == mq1 || "+" == mq1) && (mq0 = "*" == mq1 ? 0 : 1), quantifier.quantifier = { |
||
| 108 | min: mq0, |
||
| 109 | max: mq1 |
||
| 110 | }, openenings.length > 0) { |
||
| 111 | var matches = openenings[openenings.length - 1].matches; |
||
| 112 | if (match = matches.pop(), !match.isGroup) { |
||
| 113 | var groupToken = new maskToken(!0); |
||
| 114 | groupToken.matches.push(match), match = groupToken; |
||
| 115 | } |
||
| 116 | matches.push(match), matches.push(quantifier); |
||
| 117 | } else { |
||
| 118 | if (match = currentToken.matches.pop(), !match.isGroup) { |
||
| 119 | var groupToken = new maskToken(!0); |
||
| 120 | groupToken.matches.push(match), match = groupToken; |
||
| 121 | } |
||
| 122 | currentToken.matches.push(match), currentToken.matches.push(quantifier); |
||
| 123 | } |
||
| 124 | break; |
||
| 125 | |||
| 126 | case opts.escapeChar: |
||
| 127 | escaped = !0; |
||
| 128 | break; |
||
| 129 | |||
| 130 | case opts.alternatormarker: |
||
| 131 | openenings.length > 0 ? (currentOpeningToken = openenings[openenings.length - 1], |
||
| 132 | lastMatch = currentOpeningToken.matches.pop()) : lastMatch = currentToken.matches.pop(), |
||
| 133 | lastMatch.isAlternator ? openenings.push(lastMatch) : (alternator = new maskToken(!1, !1, !1, !0), |
||
| 134 | alternator.matches.push(lastMatch), openenings.push(alternator)); |
||
| 135 | break; |
||
| 136 | |||
| 137 | default: |
||
| 138 | if (openenings.length > 0) { |
||
| 139 | if (currentOpeningToken = openenings[openenings.length - 1], currentOpeningToken.matches.length > 0 && (lastMatch = currentOpeningToken.matches[currentOpeningToken.matches.length - 1], |
||
| 140 | lastMatch.isGroup && (lastMatch.isGroup = !1, insertTestDefinition(lastMatch, opts.groupmarker.start, 0), |
||
| 141 | insertTestDefinition(lastMatch, opts.groupmarker.end))), insertTestDefinition(currentOpeningToken, m), |
||
| 142 | currentOpeningToken.isAlternator) { |
||
| 143 | alternator = openenings.pop(); |
||
| 144 | for (var mndx = 0; mndx < alternator.matches.length; mndx++) alternator.matches[mndx].isGroup = !1; |
||
| 145 | openenings.length > 0 ? (currentOpeningToken = openenings[openenings.length - 1], |
||
| 146 | currentOpeningToken.matches.push(alternator)) : currentToken.matches.push(alternator); |
||
| 147 | } |
||
| 148 | } else currentToken.matches.length > 0 && (lastMatch = currentToken.matches[currentToken.matches.length - 1], |
||
| 149 | lastMatch.isGroup && (lastMatch.isGroup = !1, insertTestDefinition(lastMatch, opts.groupmarker.start, 0), |
||
| 150 | insertTestDefinition(lastMatch, opts.groupmarker.end))), insertTestDefinition(currentToken, m); |
||
| 151 | } |
||
| 152 | return currentToken.matches.length > 0 && (lastMatch = currentToken.matches[currentToken.matches.length - 1], |
||
| 153 | lastMatch.isGroup && (lastMatch.isGroup = !1, insertTestDefinition(lastMatch, opts.groupmarker.start, 0), |
||
| 154 | insertTestDefinition(lastMatch, opts.groupmarker.end)), maskTokens.push(currentToken)), |
||
| 155 | maskTokens; |
||
| 156 | } |
||
| 157 | function generateMask(mask, metadata) { |
||
| 158 | if (opts.numericInput && opts.multi !== !0) { |
||
| 159 | mask = mask.split("").reverse(); |
||
| 160 | for (var ndx = 0; ndx < mask.length; ndx++) mask[ndx] == opts.optionalmarker.start ? mask[ndx] = opts.optionalmarker.end : mask[ndx] == opts.optionalmarker.end ? mask[ndx] = opts.optionalmarker.start : mask[ndx] == opts.groupmarker.start ? mask[ndx] = opts.groupmarker.end : mask[ndx] == opts.groupmarker.end && (mask[ndx] = opts.groupmarker.start); |
||
| 161 | mask = mask.join(""); |
||
| 162 | } |
||
| 163 | if (void 0 == mask || "" == mask) return void 0; |
||
| 164 | if (1 == mask.length && 0 == opts.greedy && 0 != opts.repeat && (opts.placeholder = ""), |
||
| 165 | opts.repeat > 0 || "*" == opts.repeat || "+" == opts.repeat) { |
||
| 166 | var repeatStart = "*" == opts.repeat ? 0 : "+" == opts.repeat ? 1 : opts.repeat; |
||
| 167 | mask = opts.groupmarker.start + mask + opts.groupmarker.end + opts.quantifiermarker.start + repeatStart + "," + opts.repeat + opts.quantifiermarker.end; |
||
| 168 | } |
||
| 169 | return void 0 == $.inputmask.masksCache[mask] && ($.inputmask.masksCache[mask] = { |
||
| 170 | mask: mask, |
||
| 171 | maskToken: analyseMask(mask), |
||
| 172 | validPositions: {}, |
||
| 173 | _buffer: void 0, |
||
| 174 | buffer: void 0, |
||
| 175 | tests: {}, |
||
| 176 | metadata: metadata |
||
| 177 | }), $.extend(!0, {}, $.inputmask.masksCache[mask]); |
||
| 178 | } |
||
| 179 | var ms = void 0; |
||
| 180 | if ($.isFunction(opts.mask) && (opts.mask = opts.mask.call(this, opts)), $.isArray(opts.mask)) if (multi) ms = [], |
||
| 181 | $.each(opts.mask, function(ndx, msk) { |
||
| 182 | ms.push(void 0 == msk.mask || $.isFunction(msk.mask) ? generateMask(msk.toString(), msk) : generateMask(msk.mask.toString(), msk)); |
||
| 183 | }); else { |
||
| 184 | opts.keepStatic = void 0 == opts.keepStatic ? !0 : opts.keepStatic; |
||
| 185 | var altMask = "("; |
||
| 186 | $.each(opts.mask, function(ndx, msk) { |
||
| 187 | altMask.length > 1 && (altMask += ")|("), altMask += void 0 == msk.mask || $.isFunction(msk.mask) ? msk.toString() : msk.mask.toString(); |
||
| 188 | }), altMask += ")", ms = generateMask(altMask, opts.mask); |
||
| 189 | } else opts.mask && (ms = void 0 == opts.mask.mask || $.isFunction(opts.mask.mask) ? generateMask(opts.mask.toString(), opts.mask) : generateMask(opts.mask.mask.toString(), opts.mask)); |
||
| 190 | return ms; |
||
| 191 | } |
||
| 192 | function maskScope(actionObj, maskset, opts) { |
||
| 193 | function getMaskTemplate(baseOnInput, minimalPos, includeInput) { |
||
| 194 | minimalPos = minimalPos || 0; |
||
| 195 | var ndxIntlzr, test, testPos, maskTemplate = [], pos = 0; |
||
| 196 | do { |
||
| 197 | if (baseOnInput === !0 && getMaskSet().validPositions[pos]) { |
||
| 198 | var validPos = getMaskSet().validPositions[pos]; |
||
| 199 | test = validPos.match, ndxIntlzr = validPos.locator.slice(), maskTemplate.push(includeInput === !0 ? validPos.input : getPlaceholder(pos, test)); |
||
| 200 | } else { |
||
| 201 | if (minimalPos > pos) { |
||
| 202 | var testPositions = getTests(pos, ndxIntlzr, pos - 1); |
||
| 203 | testPos = testPositions[0]; |
||
| 204 | } else testPos = getTestTemplate(pos, ndxIntlzr, pos - 1); |
||
| 205 | test = testPos.match, ndxIntlzr = testPos.locator.slice(), maskTemplate.push(getPlaceholder(pos, test)); |
||
| 206 | } |
||
| 207 | pos++; |
||
| 208 | } while ((void 0 == maxLength || maxLength > pos - 1) && null != test.fn || null == test.fn && "" != test.def || minimalPos >= pos); |
||
| 209 | return maskTemplate.pop(), maskTemplate; |
||
| 210 | } |
||
| 211 | function getMaskSet() { |
||
| 212 | return maskset; |
||
| 213 | } |
||
| 214 | function resetMaskSet(soft) { |
||
| 215 | var maskset = getMaskSet(); |
||
| 216 | maskset.buffer = void 0, maskset.tests = {}, soft !== !0 && (maskset._buffer = void 0, |
||
| 217 | maskset.validPositions = {}, maskset.p = 0); |
||
| 218 | } |
||
| 219 | function getLastValidPosition(closestTo) { |
||
| 220 | var maskset = getMaskSet(), lastValidPosition = -1, valids = maskset.validPositions; |
||
| 221 | void 0 == closestTo && (closestTo = -1); |
||
| 222 | var before = lastValidPosition, after = lastValidPosition; |
||
| 223 | for (var posNdx in valids) { |
||
| 224 | var psNdx = parseInt(posNdx); |
||
| 225 | (-1 == closestTo || null != valids[psNdx].match.fn) && (closestTo >= psNdx && (before = psNdx), |
||
| 226 | psNdx >= closestTo && (after = psNdx)); |
||
| 227 | } |
||
| 228 | return lastValidPosition = closestTo - before > 1 || closestTo > after ? before : after; |
||
| 229 | } |
||
| 230 | function setValidPosition(pos, validTest, fromSetValid) { |
||
| 231 | if (opts.insertMode && void 0 != getMaskSet().validPositions[pos] && void 0 == fromSetValid) { |
||
| 232 | var i, positionsClone = $.extend(!0, {}, getMaskSet().validPositions), lvp = getLastValidPosition(); |
||
| 233 | for (i = pos; lvp >= i; i++) delete getMaskSet().validPositions[i]; |
||
| 234 | getMaskSet().validPositions[pos] = validTest; |
||
| 235 | var j, valid = !0; |
||
| 236 | for (i = pos; lvp >= i; i++) { |
||
| 237 | var t = positionsClone[i]; |
||
| 238 | if (void 0 != t) { |
||
| 239 | var vps = getMaskSet().validPositions; |
||
| 240 | j = !opts.keepStatic && (void 0 != vps[i + 1] && getTests(i + 1, vps[i].locator.slice(), i).length > 1 || vps[i] && void 0 != vps[i].alternation) ? i + 1 : seekNext(i), |
||
| 241 | valid = positionCanMatchDefinition(j, t.match.def) ? valid && isValid(j, t.input, !0, !0) !== !1 : null == t.match.fn; |
||
| 242 | } |
||
| 243 | if (!valid) break; |
||
| 244 | } |
||
| 245 | if (!valid) return getMaskSet().validPositions = $.extend(!0, {}, positionsClone), |
||
| 246 | !1; |
||
| 247 | } else getMaskSet().validPositions[pos] = validTest; |
||
| 248 | return !0; |
||
| 249 | } |
||
| 250 | function stripValidPositions(start, end) { |
||
| 251 | var i, startPos = start; |
||
| 252 | for (void 0 != getMaskSet().validPositions[start] && getMaskSet().validPositions[start].input == opts.radixPoint && (end++, |
||
| 253 | startPos++), i = startPos; end > i; i++) void 0 == getMaskSet().validPositions[i] || getMaskSet().validPositions[i].input == opts.radixPoint && i != getLastValidPosition() || delete getMaskSet().validPositions[i]; |
||
| 254 | for (i = end; i <= getLastValidPosition(); ) { |
||
| 255 | var t = getMaskSet().validPositions[i], s = getMaskSet().validPositions[startPos]; |
||
| 256 | void 0 != t && void 0 == s ? (positionCanMatchDefinition(startPos, t.match.def) && isValid(startPos, t.input, !0) !== !1 && (delete getMaskSet().validPositions[i], |
||
| 257 | i++), startPos++) : i++; |
||
| 258 | } |
||
| 259 | var lvp = getLastValidPosition(); |
||
| 260 | lvp >= start && void 0 != getMaskSet().validPositions[lvp] && getMaskSet().validPositions[lvp].input == opts.radixPoint && delete getMaskSet().validPositions[lvp], |
||
| 261 | resetMaskSet(!0); |
||
| 262 | } |
||
| 263 | function getTestTemplate(pos, ndxIntlzr, tstPs) { |
||
| 264 | function checkAlternationMatch(test, altNdx, altArr) { |
||
| 265 | for (var altArrC = opts.greedy ? altArr : altArr.slice(0, 1), isMatch = !1, altLocArr = test.locator[altNdx].toString().split(","), alndx = 0; alndx < altLocArr.length; alndx++) if (-1 != $.inArray(altLocArr[alndx], altArrC)) { |
||
| 266 | isMatch = !0; |
||
| 267 | break; |
||
| 268 | } |
||
| 269 | return isMatch; |
||
| 270 | } |
||
| 271 | for (var testPos, testPositions = getTests(pos, ndxIntlzr, tstPs), lvp = getLastValidPosition(), lvTest = getMaskSet().validPositions[lvp] || getTests(0)[0], lvTestAltArr = void 0 != lvTest.alternation ? lvTest.locator[lvTest.alternation].split(",") : [], ndx = 0; ndx < testPositions.length && (testPos = testPositions[ndx], |
||
| 272 | !(opts.greedy || testPos.match && (testPos.match.optionality === !1 || testPos.match.newBlockMarker === !1) && testPos.match.optionalQuantifier !== !0 && (void 0 == lvTest.alternation || void 0 != testPos.locator[lvTest.alternation] && checkAlternationMatch(testPos, lvTest.alternation, lvTestAltArr)))); ndx++) ; |
||
| 273 | return testPos; |
||
| 274 | } |
||
| 275 | function getTest(pos) { |
||
| 276 | return getMaskSet().validPositions[pos] ? getMaskSet().validPositions[pos].match : getTests(pos)[0].match; |
||
| 277 | } |
||
| 278 | function positionCanMatchDefinition(pos, def) { |
||
| 279 | for (var valid = !1, tests = getTests(pos), tndx = 0; tndx < tests.length; tndx++) if (tests[tndx].match && tests[tndx].match.def == def) { |
||
| 280 | valid = !0; |
||
| 281 | break; |
||
| 282 | } |
||
| 283 | return valid; |
||
| 284 | } |
||
| 285 | function getTests(pos, ndxIntlzr, tstPs) { |
||
| 286 | function ResolveTestFromToken(maskToken, ndxInitializer, loopNdx, quantifierRecurse) { |
||
| 287 | function handleMatch(match, loopNdx, quantifierRecurse) { |
||
| 288 | if (testPos > 1e4) return alert("jquery.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), |
||
| 289 | !0; |
||
| 290 | if (testPos == pos && void 0 == match.matches) return matches.push({ |
||
| 291 | match: match, |
||
| 292 | locator: loopNdx.reverse() |
||
| 293 | }), !0; |
||
| 294 | if (void 0 != match.matches) { |
||
| 295 | if (match.isGroup && quantifierRecurse !== !0) { |
||
| 296 | if (match = handleMatch(maskToken.matches[tndx + 1], loopNdx)) return !0; |
||
| 297 | } else if (match.isOptional) { |
||
| 298 | var optionalToken = match; |
||
| 299 | if (match = ResolveTestFromToken(match, ndxInitializer, loopNdx, quantifierRecurse)) { |
||
| 300 | var latestMatch = matches[matches.length - 1].match, isFirstMatch = 0 == $.inArray(latestMatch, optionalToken.matches); |
||
| 301 | isFirstMatch && (insertStop = !0), testPos = pos; |
||
| 302 | } |
||
| 303 | } else if (match.isAlternator) { |
||
| 304 | var maltMatches, alternateToken = match, malternateMatches = [], currentMatches = matches.slice(), loopNdxCnt = loopNdx.length, altIndex = ndxInitializer.length > 0 ? ndxInitializer.shift() : -1; |
||
| 305 | if (-1 == altIndex || "string" == typeof altIndex) { |
||
| 306 | var altIndexArr, currentPos = testPos, ndxInitializerClone = ndxInitializer.slice(); |
||
| 307 | "string" == typeof altIndex && (altIndexArr = altIndex.split(",")); |
||
| 308 | for (var amndx = 0; amndx < alternateToken.matches.length; amndx++) { |
||
| 309 | matches = [], match = handleMatch(alternateToken.matches[amndx], [ amndx ].concat(loopNdx), quantifierRecurse) || match, |
||
| 310 | maltMatches = matches.slice(), testPos = currentPos, matches = []; |
||
| 311 | for (var i = 0; i < ndxInitializerClone.length; i++) ndxInitializer[i] = ndxInitializerClone[i]; |
||
| 312 | for (var ndx1 = 0; ndx1 < maltMatches.length; ndx1++) for (var altMatch = maltMatches[ndx1], ndx2 = 0; ndx2 < malternateMatches.length; ndx2++) { |
||
| 313 | var altMatch2 = malternateMatches[ndx2]; |
||
| 314 | if (altMatch.match.mask == altMatch2.match.mask && ("string" != typeof altIndex || -1 != $.inArray(altMatch.locator[loopNdxCnt].toString(), altIndexArr))) { |
||
| 315 | maltMatches.splice(ndx1, 1), altMatch2.locator[loopNdxCnt] = altMatch2.locator[loopNdxCnt] + "," + altMatch.locator[loopNdxCnt], |
||
| 316 | altMatch2.alternation = loopNdxCnt; |
||
| 317 | break; |
||
| 318 | } |
||
| 319 | } |
||
| 320 | malternateMatches = malternateMatches.concat(maltMatches); |
||
| 321 | } |
||
| 322 | "string" == typeof altIndex && (malternateMatches = $.map(malternateMatches, function(lmnt, ndx) { |
||
| 323 | if (isFinite(ndx)) { |
||
| 324 | var mamatch, altLocArr = lmnt.locator[loopNdxCnt].toString().split(","); |
||
| 325 | lmnt.locator[loopNdxCnt] = void 0, lmnt.alternation = void 0; |
||
| 326 | for (var alndx = 0; alndx < altLocArr.length; alndx++) mamatch = -1 != $.inArray(altLocArr[alndx], altIndexArr), |
||
| 327 | mamatch && (void 0 != lmnt.locator[loopNdxCnt] ? (lmnt.locator[loopNdxCnt] += ",", |
||
| 328 | lmnt.alternation = loopNdxCnt, lmnt.locator[loopNdxCnt] += altLocArr[alndx]) : lmnt.locator[loopNdxCnt] = parseInt(altLocArr[alndx])); |
||
| 329 | if (void 0 != lmnt.locator[loopNdxCnt]) return lmnt; |
||
| 330 | } |
||
| 331 | })), matches = currentMatches.concat(malternateMatches), insertStop = !0; |
||
| 332 | } else match = handleMatch(alternateToken.matches[altIndex], [ altIndex ].concat(loopNdx), quantifierRecurse); |
||
| 333 | if (match) return !0; |
||
| 334 | } else if (match.isQuantifier && quantifierRecurse !== !0) { |
||
| 335 | var qt = match; |
||
| 336 | opts.greedy = opts.greedy && isFinite(qt.quantifier.max); |
||
| 337 | for (var qndx = ndxInitializer.length > 0 && quantifierRecurse !== !0 ? ndxInitializer.shift() : 0; qndx < (isNaN(qt.quantifier.max) ? qndx + 1 : qt.quantifier.max) && pos >= testPos; qndx++) { |
||
| 338 | var tokenGroup = maskToken.matches[$.inArray(qt, maskToken.matches) - 1]; |
||
| 339 | if (match = handleMatch(tokenGroup, [ qndx ].concat(loopNdx), !0)) { |
||
| 340 | var latestMatch = matches[matches.length - 1].match; |
||
| 341 | latestMatch.optionalQuantifier = qndx > qt.quantifier.min - 1; |
||
| 342 | var isFirstMatch = 0 == $.inArray(latestMatch, tokenGroup.matches); |
||
| 343 | if (isFirstMatch) { |
||
| 344 | if (qndx > qt.quantifier.min - 1) { |
||
| 345 | insertStop = !0, testPos = pos; |
||
| 346 | break; |
||
| 347 | } |
||
| 348 | return !0; |
||
| 349 | } |
||
| 350 | return !0; |
||
| 351 | } |
||
| 352 | } |
||
| 353 | } else if (match = ResolveTestFromToken(match, ndxInitializer, loopNdx, quantifierRecurse)) return !0; |
||
| 354 | } else testPos++; |
||
| 355 | } |
||
| 356 | for (var tndx = ndxInitializer.length > 0 ? ndxInitializer.shift() : 0; tndx < maskToken.matches.length; tndx++) if (maskToken.matches[tndx].isQuantifier !== !0) { |
||
| 357 | var match = handleMatch(maskToken.matches[tndx], [ tndx ].concat(loopNdx), quantifierRecurse); |
||
| 358 | if (match && testPos == pos) return match; |
||
| 359 | if (testPos > pos) break; |
||
| 360 | } |
||
| 361 | } |
||
| 362 | var maskTokens = getMaskSet().maskToken, testPos = ndxIntlzr ? tstPs : 0, ndxInitializer = ndxIntlzr || [ 0 ], matches = [], insertStop = !1; |
||
| 363 | if (void 0 == ndxIntlzr) { |
||
| 364 | for (var test, previousPos = pos - 1; void 0 == (test = getMaskSet().validPositions[previousPos]) && previousPos > -1; ) previousPos--; |
||
| 365 | if (void 0 != test && previousPos > -1) testPos = previousPos, ndxInitializer = test.locator.slice(); else { |
||
| 366 | for (previousPos = pos - 1; void 0 == (test = getMaskSet().tests[previousPos]) && previousPos > -1; ) previousPos--; |
||
| 367 | void 0 != test && previousPos > -1 && (testPos = previousPos, ndxInitializer = test[0].locator.slice()); |
||
| 368 | } |
||
| 369 | } |
||
| 370 | for (var mtndx = ndxInitializer.shift(); mtndx < maskTokens.length; mtndx++) { |
||
| 371 | var match = ResolveTestFromToken(maskTokens[mtndx], ndxInitializer, [ mtndx ]); |
||
| 372 | if (match && testPos == pos || testPos > pos) break; |
||
| 373 | } |
||
| 374 | return (0 == matches.length || insertStop) && matches.push({ |
||
| 375 | match: { |
||
| 376 | fn: null, |
||
| 377 | cardinality: 0, |
||
| 378 | optionality: !0, |
||
| 379 | casing: null, |
||
| 380 | def: "" |
||
| 381 | }, |
||
| 382 | locator: [] |
||
| 383 | }), getMaskSet().tests[pos] = $.extend(!0, [], matches), getMaskSet().tests[pos]; |
||
| 384 | } |
||
| 385 | function getBufferTemplate() { |
||
| 386 | return void 0 == getMaskSet()._buffer && (getMaskSet()._buffer = getMaskTemplate(!1, 1)), |
||
| 387 | getMaskSet()._buffer; |
||
| 388 | } |
||
| 389 | function getBuffer() { |
||
| 390 | return void 0 == getMaskSet().buffer && (getMaskSet().buffer = getMaskTemplate(!0, getLastValidPosition(), !0)), |
||
| 391 | getMaskSet().buffer; |
||
| 392 | } |
||
| 393 | function refreshFromBuffer(start, end) { |
||
| 394 | var buffer = getBuffer().slice(); |
||
| 395 | if (start === !0) resetMaskSet(), start = 0, end = buffer.length; else for (var i = start; end > i; i++) delete getMaskSet().validPositions[i], |
||
| 396 | delete getMaskSet().tests[i]; |
||
| 397 | for (var i = start; end > i; i++) buffer[i] != opts.skipOptionalPartCharacter && isValid(i, buffer[i], !0, !0); |
||
| 398 | } |
||
| 399 | function casing(elem, test) { |
||
| 400 | switch (test.casing) { |
||
| 401 | case "upper": |
||
| 402 | elem = elem.toUpperCase(); |
||
| 403 | break; |
||
| 404 | |||
| 405 | case "lower": |
||
| 406 | elem = elem.toLowerCase(); |
||
| 407 | } |
||
| 408 | return elem; |
||
| 409 | } |
||
| 410 | function isValid(pos, c, strict, fromSetValid) { |
||
| 411 | function _isValid(position, c, strict, fromSetValid) { |
||
| 412 | var rslt = !1; |
||
| 413 | return $.each(getTests(position), function(ndx, tst) { |
||
| 414 | for (var test = tst.match, loopend = c ? 1 : 0, chrs = "", i = (getBuffer(), test.cardinality); i > loopend; i--) chrs += getBufferElement(position - (i - 1)); |
||
| 415 | if (c && (chrs += c), rslt = null != test.fn ? test.fn.test(chrs, getMaskSet(), position, strict, opts) : c != test.def && c != opts.skipOptionalPartCharacter || "" == test.def ? !1 : { |
||
| 416 | c: test.def, |
||
| 417 | pos: position |
||
| 418 | }, rslt !== !1) { |
||
| 419 | var elem = void 0 != rslt.c ? rslt.c : c; |
||
| 420 | elem = elem == opts.skipOptionalPartCharacter && null === test.fn ? test.def : elem; |
||
| 421 | var validatedPos = position; |
||
| 422 | if (void 0 != rslt.remove && stripValidPositions(rslt.remove, rslt.remove + 1), |
||
| 423 | rslt.refreshFromBuffer) { |
||
| 424 | var refresh = rslt.refreshFromBuffer; |
||
| 425 | if (strict = !0, refreshFromBuffer(refresh === !0 ? refresh : refresh.start, refresh.end), |
||
| 426 | void 0 == rslt.pos && void 0 == rslt.c) return rslt.pos = getLastValidPosition(), |
||
| 427 | !1; |
||
| 428 | if (validatedPos = void 0 != rslt.pos ? rslt.pos : position, validatedPos != position) return rslt = $.extend(rslt, isValid(validatedPos, elem, !0)), |
||
| 429 | !1; |
||
| 430 | } else if (rslt !== !0 && void 0 != rslt.pos && rslt.pos != position && (validatedPos = rslt.pos, |
||
| 431 | refreshFromBuffer(position, validatedPos), validatedPos != position)) return rslt = $.extend(rslt, isValid(validatedPos, elem, !0)), |
||
| 432 | !1; |
||
| 433 | return 1 != rslt && void 0 == rslt.pos && void 0 == rslt.c ? !1 : (ndx > 0 && resetMaskSet(!0), |
||
| 434 | setValidPosition(validatedPos, $.extend({}, tst, { |
||
| 435 | input: casing(elem, test) |
||
| 436 | }), fromSetValid) || (rslt = !1), !1); |
||
| 437 | } |
||
| 438 | }), rslt; |
||
| 439 | } |
||
| 440 | function alternate(pos, c, strict, fromSetValid) { |
||
| 441 | var lastAlt, alternation, validPsClone = $.extend(!0, {}, getMaskSet().validPositions); |
||
| 442 | for (lastAlt = getLastValidPosition(); lastAlt >= 0; lastAlt--) if (getMaskSet().validPositions[lastAlt] && void 0 != getMaskSet().validPositions[lastAlt].alternation) { |
||
| 443 | alternation = getMaskSet().validPositions[lastAlt].alternation; |
||
| 444 | break; |
||
| 445 | } |
||
| 446 | if (void 0 != alternation) for (var decisionPos in getMaskSet().validPositions) if (parseInt(decisionPos) > parseInt(lastAlt) && void 0 === getMaskSet().validPositions[decisionPos].alternation) { |
||
| 447 | for (var altPos = getMaskSet().validPositions[decisionPos], decisionTaker = altPos.locator[alternation], altNdxs = getMaskSet().validPositions[lastAlt].locator[alternation].split(","), mndx = 0; mndx < altNdxs.length; mndx++) if (decisionTaker < altNdxs[mndx]) { |
||
| 448 | for (var possibilityPos, possibilities, dp = decisionPos - 1; dp >= 0; dp--) if (possibilityPos = getMaskSet().validPositions[dp], |
||
| 449 | void 0 != possibilityPos) { |
||
| 450 | possibilities = possibilityPos.locator[alternation], possibilityPos.locator[alternation] = altNdxs[mndx]; |
||
| 451 | break; |
||
| 452 | } |
||
| 453 | if (decisionTaker != possibilityPos.locator[alternation]) { |
||
| 454 | for (var buffer = getBuffer().slice(), i = decisionPos; i < getLastValidPosition() + 1; i++) delete getMaskSet().validPositions[i], |
||
| 455 | delete getMaskSet().tests[i]; |
||
| 456 | resetMaskSet(!0), opts.keepStatic = !opts.keepStatic; |
||
| 457 | for (var i = decisionPos; i < buffer.length; i++) buffer[i] != opts.skipOptionalPartCharacter && isValid(getLastValidPosition() + 1, buffer[i], !1, !0); |
||
| 458 | possibilityPos.locator[alternation] = possibilities; |
||
| 459 | var isValidRslt = isValid(pos, c, strict, fromSetValid); |
||
| 460 | if (opts.keepStatic = !opts.keepStatic, isValidRslt) return isValidRslt; |
||
| 461 | resetMaskSet(), getMaskSet().validPositions = $.extend(!0, {}, validPsClone); |
||
| 462 | } |
||
| 463 | } |
||
| 464 | break; |
||
| 465 | } |
||
| 466 | return !1; |
||
| 467 | } |
||
| 468 | function trackbackAlternations(originalPos, newPos) { |
||
| 469 | for (var vp = getMaskSet().validPositions[newPos], targetLocator = vp.locator, tll = targetLocator.length, ps = originalPos; newPos > ps; ps++) if (!isMask(ps)) { |
||
| 470 | var bestMatch, tests = getTests(ps), equality = -1; |
||
| 471 | for (var tndx in tests) for (var activeTest = tests[tndx], i = 0; tll > i; i++) targetLocator[i] == activeTest.locator[i] && i > equality && (equality = i, |
||
| 472 | bestMatch = activeTest); |
||
| 473 | setValidPosition(ps, $.extend({}, bestMatch, { |
||
| 474 | input: bestMatch.match.def |
||
| 475 | }), !0); |
||
| 476 | } |
||
| 477 | } |
||
| 478 | strict = strict === !0; |
||
| 479 | for (var buffer = getBuffer(), pndx = pos - 1; pndx > -1 && (!getMaskSet().validPositions[pndx] || null != getMaskSet().validPositions[pndx].match.fn); pndx--) void 0 == getMaskSet().validPositions[pndx] && (!isMask(pndx) || buffer[pndx] != getPlaceholder(pndx)) && getTests(pndx).length > 1 && _isValid(pndx, buffer[pndx], !0); |
||
| 480 | var maskPos = pos, result = !1; |
||
| 481 | if (fromSetValid && maskPos >= getMaskLength() && resetMaskSet(!0), maskPos < getMaskLength() && (result = _isValid(maskPos, c, strict, fromSetValid), |
||
| 482 | !strict && result === !1)) { |
||
| 483 | var currentPosValid = getMaskSet().validPositions[maskPos]; |
||
| 484 | if (!currentPosValid || null != currentPosValid.match.fn || currentPosValid.match.def != c && c != opts.skipOptionalPartCharacter) { |
||
| 485 | if ((opts.insertMode || void 0 == getMaskSet().validPositions[seekNext(maskPos)]) && !isMask(maskPos)) for (var nPos = maskPos + 1, snPos = seekNext(maskPos); snPos >= nPos; nPos++) if (result = _isValid(nPos, c, strict, fromSetValid), |
||
| 486 | result !== !1) { |
||
| 487 | trackbackAlternations(maskPos, nPos), maskPos = nPos; |
||
| 488 | break; |
||
| 489 | } |
||
| 490 | } else result = { |
||
| 491 | caret: seekNext(maskPos) |
||
| 492 | }; |
||
| 493 | } |
||
| 494 | return result === !1 && opts.keepStatic && isComplete(buffer) && (result = alternate(pos, c, strict, fromSetValid)), |
||
| 495 | result === !0 && (result = { |
||
| 496 | pos: maskPos |
||
| 497 | }), result; |
||
| 498 | } |
||
| 499 | function isMask(pos) { |
||
| 500 | var test = getTest(pos); |
||
| 501 | return null != test.fn ? test.fn : !1; |
||
| 502 | } |
||
| 503 | function getMaskLength() { |
||
| 504 | var maskLength; |
||
| 505 | if (maxLength = $el.prop("maxLength"), -1 == maxLength && (maxLength = void 0), |
||
| 506 | |||
| 507 | var pos, lvp = getLastValidPosition(), testPos = getMaskSet().validPositions[lvp], ndxIntlzr = void 0 != testPos ? testPos.locator.slice() : void 0; |
||
| 508 | for (pos = lvp + 1; void 0 == testPos || null != testPos.match.fn || null == testPos.match.fn && "" != testPos.match.def; pos++) testPos = getTestTemplate(pos, ndxIntlzr, pos - 1), |
||
| 509 | ndxIntlzr = testPos.locator.slice(); |
||
| 510 | maskLength = pos; |
||
| 511 | } else maskLength = getBuffer().length; |
||
| 512 | return void 0 == maxLength || maxLength > maskLength ? maskLength : maxLength; |
||
| 513 | } |
||
| 514 | function seekNext(pos) { |
||
| 515 | var maskL = getMaskLength(); |
||
| 516 | if (pos >= maskL) return maskL; |
||
| 517 | for (var position = pos; ++position < maskL && !isMask(position) && (opts.nojumps !== !0 || opts.nojumpsThreshold > position); ) ; |
||
| 518 | return position; |
||
| 519 | } |
||
| 520 | function seekPrevious(pos) { |
||
| 521 | var position = pos; |
||
| 522 | if (0 >= position) return 0; |
||
| 523 | for (;--position > 0 && !isMask(position); ) ; |
||
| 524 | return position; |
||
| 525 | } |
||
| 526 | function getBufferElement(position) { |
||
| 527 | return void 0 == getMaskSet().validPositions[position] ? getPlaceholder(position) : getMaskSet().validPositions[position].input; |
||
| 528 | } |
||
| 529 | function writeBuffer(input, buffer, caretPos) { |
||
| 530 | input._valueSet(buffer.join("")), void 0 != caretPos && caret(input, caretPos); |
||
| 531 | } |
||
| 532 | function getPlaceholder(pos, test) { |
||
| 533 | test = test || getTest(pos); |
||
| 534 | var placeholder = $.isFunction(test.placeholder) ? test.placeholder.call(this, opts) : test.placeholder; |
||
| 535 | return void 0 != placeholder ? placeholder : null == test.fn ? test.def : opts.placeholder.charAt(pos % opts.placeholder.length); |
||
| 536 | } |
||
| 537 | function checkVal(input, writeOut, strict, nptvl) { |
||
| 538 | var inputValue = void 0 != nptvl ? nptvl.slice() : input._valueGet().split(""); |
||
| 539 | resetMaskSet(), writeOut && input._valueSet(""); |
||
| 540 | var staticInput = getBufferTemplate().slice(0, seekNext(-1)).join(""), matches = inputValue.join("").match(new RegExp(escapeRegex(staticInput), "g")); |
||
| 541 | if (matches && matches.length > 1 && inputValue.splice(0, staticInput.length), $.each(inputValue, function(ndx, charCode) { |
||
| 542 | var lvp = getLastValidPosition(); |
||
| 543 | -1 == $.inArray(charCode, getBufferTemplate().slice(lvp + 1, getMaskSet().p)) || strict ? (keypressEvent.call(input, void 0, !0, charCode.charCodeAt(0), !1, strict, strict ? ndx : getMaskSet().p), |
||
| 544 | strict = strict || ndx > 0 && ndx > getMaskSet().p) : keypressEvent.call(input, void 0, !0, charCode.charCodeAt(0), !1, !0, lvp + 1); |
||
| 545 | }), writeOut) { |
||
| 546 | var keypressResult = opts.onKeyPress.call(this, void 0, getBuffer(), 0, opts); |
||
| 547 | handleOnKeyResult(input, keypressResult), writeBuffer(input, getBuffer(), $(input).is(":focus") ? seekNext(getLastValidPosition(0)) : void 0); |
||
| 548 | } |
||
| 549 | } |
||
| 550 | function escapeRegex(str) { |
||
| 551 | return $.inputmask.escapeRegex.call(this, str); |
||
| 552 | } |
||
| 553 | function unmaskedvalue($input) { |
||
| 554 | if ($input.data("_inputmask") && !$input.hasClass("hasDatepicker")) { |
||
| 555 | var umValue = [], vps = getMaskSet().validPositions; |
||
| 556 | for (var pndx in vps) vps[pndx].match && null != vps[pndx].match.fn && umValue.push(vps[pndx].input); |
||
| 557 | var unmaskedValue = (isRTL ? umValue.reverse() : umValue).join(""), bufferValue = (isRTL ? getBuffer().slice().reverse() : getBuffer()).join(""); |
||
| 558 | return $.isFunction(opts.onUnMask) && (unmaskedValue = opts.onUnMask.call($input, bufferValue, unmaskedValue, opts) || unmaskedValue), |
||
| 559 | unmaskedValue; |
||
| 560 | } |
||
| 561 | return $input[0]._valueGet(); |
||
| 562 | } |
||
| 563 | function TranslatePosition(pos) { |
||
| 564 | if (isRTL && "number" == typeof pos && (!opts.greedy || "" != opts.placeholder)) { |
||
| 565 | var bffrLght = getBuffer().length; |
||
| 566 | pos = bffrLght - pos; |
||
| 567 | } |
||
| 568 | return pos; |
||
| 569 | } |
||
| 570 | function caret(input, begin, end) { |
||
| 571 | var range, npt = input.jquery && input.length > 0 ? input[0] : input; |
||
| 572 | if ("number" != typeof begin) { |
||
| 573 | var data = $(npt).data("_inputmask"); |
||
| 574 | return !$(npt).is(":visible") && data && void 0 != data.caret ? (begin = data.caret.begin, |
||
| 575 | end = data.caret.end) : npt.setSelectionRange ? (begin = npt.selectionStart, end = npt.selectionEnd) : document.selection && document.selection.createRange && (range = document.selection.createRange(), |
||
| 576 | begin = 0 - range.duplicate().moveStart("character", -1e5), end = begin + range.text.length), |
||
| 577 | begin = TranslatePosition(begin), end = TranslatePosition(end), { |
||
| 578 | begin: begin, |
||
| 579 | end: end |
||
| 580 | }; |
||
| 581 | } |
||
| 582 | begin = TranslatePosition(begin), end = TranslatePosition(end), end = "number" == typeof end ? end : begin; |
||
| 583 | var data = $(npt).data("_inputmask") || {}; |
||
| 584 | data.caret = { |
||
| 585 | begin: begin, |
||
| 586 | end: end |
||
| 587 | }, $(npt).data("_inputmask", data), $(npt).is(":visible") && (npt.scrollLeft = npt.scrollWidth, |
||
| 588 | |||
| 589 | npt.selectionEnd = end) : npt.createTextRange && (range = npt.createTextRange(), |
||
| 590 | range.collapse(!0), range.moveEnd("character", end), range.moveStart("character", begin), |
||
| 591 | range.select())); |
||
| 592 | } |
||
| 593 | function determineLastRequiredPosition(returnDefinition) { |
||
| 594 | var pos, testPos, buffer = getBuffer(), bl = buffer.length, lvp = getLastValidPosition(), positions = {}, lvTest = getMaskSet().validPositions[lvp], ndxIntlzr = void 0 != lvTest ? lvTest.locator.slice() : void 0; |
||
| 595 | for (pos = lvp + 1; pos < buffer.length; pos++) testPos = getTestTemplate(pos, ndxIntlzr, pos - 1), |
||
| 596 | ndxIntlzr = testPos.locator.slice(), positions[pos] = $.extend(!0, {}, testPos); |
||
| 597 | var lvTestAltArr = lvTest && void 0 != lvTest.alternation ? lvTest.locator[lvTest.alternation].split(",") : []; |
||
| 598 | for (pos = bl - 1; pos > lvp && (testPos = positions[pos].match, (testPos.optionality || testPos.optionalQuantifier || lvTest && void 0 != lvTest.alternation && void 0 != positions[pos].locator[lvTest.alternation] && -1 != $.inArray(positions[pos].locator[lvTest.alternation].toString(), lvTestAltArr)) && buffer[pos] == getPlaceholder(pos, testPos)); pos--) bl--; |
||
| 599 | return returnDefinition ? { |
||
| 600 | l: bl, |
||
| 601 | def: positions[bl] ? positions[bl].match : void 0 |
||
| 602 | } : bl; |
||
| 603 | } |
||
| 604 | function clearOptionalTail(input) { |
||
| 605 | var buffer = getBuffer(), tmpBuffer = buffer.slice(); |
||
| 606 | if ($.isFunction(opts.postProcessOnBlur)) opts.postProcessOnBlur.call(input, tmpBuffer, opts); else { |
||
| 607 | for (var rl = determineLastRequiredPosition(), lmib = tmpBuffer.length - 1; lmib > rl && !isMask(lmib); lmib--) ; |
||
| 608 | tmpBuffer.splice(rl, lmib + 1 - rl); |
||
| 609 | } |
||
| 610 | writeBuffer(input, tmpBuffer); |
||
| 611 | } |
||
| 612 | function isComplete(buffer) { |
||
| 613 | if ($.isFunction(opts.isComplete)) return opts.isComplete.call($el, buffer, opts); |
||
| 614 | if ("*" == opts.repeat) return void 0; |
||
| 615 | var complete = !1, lrp = determineLastRequiredPosition(!0), aml = seekPrevious(lrp.l), lvp = getLastValidPosition(); |
||
| 616 | if (lvp == aml && (void 0 == lrp.def || lrp.def.newBlockMarker || lrp.def.optionalQuantifier)) { |
||
| 617 | complete = !0; |
||
| 618 | for (var i = 0; aml >= i; i++) { |
||
| 619 | var mask = isMask(i); |
||
| 620 | if (mask && (void 0 == buffer[i] || buffer[i] == getPlaceholder(i)) || !mask && buffer[i] != getPlaceholder(i)) { |
||
| 621 | complete = !1; |
||
| 622 | break; |
||
| 623 | } |
||
| 624 | } |
||
| 625 | } |
||
| 626 | return complete; |
||
| 627 | } |
||
| 628 | function isSelection(begin, end) { |
||
| 629 | return isRTL ? begin - end > 1 || begin - end == 1 && opts.insertMode : end - begin > 1 || end - begin == 1 && opts.insertMode; |
||
| 630 | } |
||
| 631 | function installEventRuler(npt) { |
||
| 632 | var events = $._data(npt).events; |
||
| 633 | $.each(events, function(eventType, eventHandlers) { |
||
| 634 | $.each(eventHandlers, function(ndx, eventHandler) { |
||
| 635 | if ("inputmask" == eventHandler.namespace && "setvalue" != eventHandler.type) { |
||
| 636 | var handler = eventHandler.handler; |
||
| 637 | eventHandler.handler = function(e) { |
||
| 638 | return this.readOnly || this.disabled ? void e.preventDefault : handler.apply(this, arguments); |
||
| 639 | }; |
||
| 640 | } |
||
| 641 | }); |
||
| 642 | }); |
||
| 643 | } |
||
| 644 | function patchValueProperty(npt) { |
||
| 645 | function PatchValhook(type) { |
||
| 646 | if (void 0 == $.valHooks[type] || 1 != $.valHooks[type].inputmaskpatch) { |
||
| 647 | var valueGet = $.valHooks[type] && $.valHooks[type].get ? $.valHooks[type].get : function(elem) { |
||
| 648 | return elem.value; |
||
| 649 | }, valueSet = $.valHooks[type] && $.valHooks[type].set ? $.valHooks[type].set : function(elem, value) { |
||
| 650 | return elem.value = value, elem; |
||
| 651 | }; |
||
| 652 | $.valHooks[type] = { |
||
| 653 | get: function(elem) { |
||
| 654 | var $elem = $(elem); |
||
| 655 | if ($elem.data("_inputmask")) { |
||
| 656 | if ($elem.data("_inputmask").opts.autoUnmask) return $elem.inputmask("unmaskedvalue"); |
||
| 657 | var result = valueGet(elem), inputData = $elem.data("_inputmask"), maskset = inputData.maskset, bufferTemplate = maskset._buffer; |
||
| 658 | return bufferTemplate = bufferTemplate ? bufferTemplate.join("") : "", result != bufferTemplate ? result : ""; |
||
| 659 | } |
||
| 660 | return valueGet(elem); |
||
| 661 | }, |
||
| 662 | set: function(elem, value) { |
||
| 663 | var result, $elem = $(elem), inputData = $elem.data("_inputmask"); |
||
| 664 | return inputData ? (result = valueSet(elem, $.isFunction(inputData.opts.onBeforeMask) ? inputData.opts.onBeforeMask.call(el, value, inputData.opts) || value : value), |
||
| 665 | $elem.triggerHandler("setvalue.inputmask")) : result = valueSet(elem, value), result; |
||
| 666 | }, |
||
| 667 | inputmaskpatch: !0 |
||
| 668 | }; |
||
| 669 | } |
||
| 670 | } |
||
| 671 | function getter() { |
||
| 672 | var $self = $(this), inputData = $(this).data("_inputmask"); |
||
| 673 | return inputData ? inputData.opts.autoUnmask ? $self.inputmask("unmaskedvalue") : valueGet.call(this) != getBufferTemplate().join("") ? valueGet.call(this) : "" : valueGet.call(this); |
||
| 674 | } |
||
| 675 | function setter(value) { |
||
| 676 | var inputData = $(this).data("_inputmask"); |
||
| 677 | inputData ? (valueSet.call(this, $.isFunction(inputData.opts.onBeforeMask) ? inputData.opts.onBeforeMask.call(el, value, inputData.opts) || value : value), |
||
| 678 | $(this).triggerHandler("setvalue.inputmask")) : valueSet.call(this, value); |
||
| 679 | } |
||
| 680 | function InstallNativeValueSetFallback(npt) { |
||
| 681 | $(npt).bind("mouseenter.inputmask", function() { |
||
| 682 | var $input = $(this), input = this, value = input._valueGet(); |
||
| 683 | "" != value && value != getBuffer().join("") && (valueSet.call(this, $.isFunction(opts.onBeforeMask) ? opts.onBeforeMask.call(el, value, opts) || value : value), |
||
| 684 | $input.trigger("setvalue")); |
||
| 685 | }); |
||
| 686 | //!! the bound handlers are executed in the order they where bound |
||
| 687 | var events = $._data(npt).events, handlers = events.mouseover; |
||
| 688 | if (handlers) { |
||
| 689 | for (var ourHandler = handlers[handlers.length - 1], i = handlers.length - 1; i > 0; i--) handlers[i] = handlers[i - 1]; |
||
| 690 | handlers[0] = ourHandler; |
||
| 691 | } |
||
| 692 | } |
||
| 693 | var valueGet, valueSet; |
||
| 694 | if (!npt._valueGet) { |
||
| 695 | if (Object.getOwnPropertyDescriptor) { |
||
| 696 | Object.getOwnPropertyDescriptor(npt, "value"); |
||
| 697 | } |
||
| 698 | document.__lookupGetter__ && npt.__lookupGetter__("value") ? (valueGet = npt.__lookupGetter__("value"), |
||
| 699 | valueSet = npt.__lookupSetter__("value"), npt.__defineGetter__("value", getter), |
||
| 700 | npt.__defineSetter__("value", setter)) : (valueGet = function() { |
||
| 701 | return npt.value; |
||
| 702 | }, valueSet = function(value) { |
||
| 703 | npt.value = value; |
||
| 704 | }, PatchValhook(npt.type), InstallNativeValueSetFallback(npt)), npt._valueGet = function() { |
||
| 705 | return isRTL ? valueGet.call(this).split("").reverse().join("") : valueGet.call(this); |
||
| 706 | }, npt._valueSet = function(value) { |
||
| 707 | valueSet.call(this, isRTL ? value.split("").reverse().join("") : value); |
||
| 708 | }; |
||
| 709 | } |
||
| 710 | } |
||
| 711 | function handleRemove(input, k, pos) { |
||
| 712 | function generalize() { |
||
| 713 | if (opts.keepStatic) { |
||
| 714 | resetMaskSet(!0); |
||
| 715 | var lastAlt, validInputs = []; |
||
| 716 | for (lastAlt = getLastValidPosition(); lastAlt >= 0; lastAlt--) if (getMaskSet().validPositions[lastAlt]) { |
||
| 717 | if (void 0 != getMaskSet().validPositions[lastAlt].alternation) break; |
||
| 718 | validInputs.push(getMaskSet().validPositions[lastAlt].input), delete getMaskSet().validPositions[lastAlt]; |
||
| 719 | } |
||
| 720 | if (lastAlt > 0) for (;validInputs.length > 0; ) getMaskSet().p = seekNext(getLastValidPosition()), |
||
| 721 | keypressEvent.call(input, void 0, !0, validInputs.pop().charCodeAt(0), !1, !1, getMaskSet().p); |
||
| 722 | } |
||
| 723 | } |
||
| 724 | if ((opts.numericInput || isRTL) && (k == $.inputmask.keyCode.BACKSPACE ? k = $.inputmask.keyCode.DELETE : k == $.inputmask.keyCode.DELETE && (k = $.inputmask.keyCode.BACKSPACE), |
||
| 725 | isRTL)) { |
||
| 726 | var pend = pos.end; |
||
| 727 | pos.end = pos.begin, pos.begin = pend; |
||
| 728 | } |
||
| 729 | k == $.inputmask.keyCode.BACKSPACE && pos.end - pos.begin <= 1 ? pos.begin = seekPrevious(pos.begin) : k == $.inputmask.keyCode.DELETE && pos.begin == pos.end && pos.end++, |
||
| 730 | stripValidPositions(pos.begin, pos.end), generalize(); |
||
| 731 | var firstMaskedPos = getLastValidPosition(pos.begin); |
||
| 732 | firstMaskedPos < pos.begin ? (-1 == firstMaskedPos && resetMaskSet(), getMaskSet().p = seekNext(firstMaskedPos)) : getMaskSet().p = pos.begin; |
||
| 733 | } |
||
| 734 | function handleOnKeyResult(input, keyResult, caretPos) { |
||
| 735 | if (keyResult && keyResult.refreshFromBuffer) { |
||
| 736 | var refresh = keyResult.refreshFromBuffer; |
||
| 737 | refreshFromBuffer(refresh === !0 ? refresh : refresh.start, refresh.end), resetMaskSet(!0), |
||
| 738 | void 0 != caretPos && (writeBuffer(input, getBuffer()), caret(input, keyResult.caret || caretPos.begin, keyResult.caret || caretPos.end)); |
||
| 739 | } |
||
| 740 | } |
||
| 741 | function keydownEvent(e) { |
||
| 742 | skipKeyPressEvent = !1; |
||
| 743 | var input = this, $input = $(input), k = e.keyCode, pos = caret(input); |
||
| 744 | k == $.inputmask.keyCode.BACKSPACE || k == $.inputmask.keyCode.DELETE || iphone && 127 == k || e.ctrlKey && 88 == k && !isInputEventSupported("cut") ? (e.preventDefault(), |
||
| 745 | 88 == k && (valueOnFocus = getBuffer().join("")), handleRemove(input, k, pos), writeBuffer(input, getBuffer(), getMaskSet().p), |
||
| 746 | input._valueGet() == getBufferTemplate().join("") && $input.trigger("cleared"), |
||
| 747 | opts.showTooltip && $input.prop("title", getMaskSet().mask)) : k == $.inputmask.keyCode.END || k == $.inputmask.keyCode.PAGE_DOWN ? setTimeout(function() { |
||
| 748 | var caretPos = seekNext(getLastValidPosition()); |
||
| 749 | opts.insertMode || caretPos != getMaskLength() || e.shiftKey || caretPos--, caret(input, e.shiftKey ? pos.begin : caretPos, caretPos); |
||
| 750 | }, 0) : k == $.inputmask.keyCode.HOME && !e.shiftKey || k == $.inputmask.keyCode.PAGE_UP ? caret(input, 0, e.shiftKey ? pos.begin : 0) : k == $.inputmask.keyCode.ESCAPE || 90 == k && e.ctrlKey ? (checkVal(input, !0, !1, valueOnFocus.split("")), |
||
| 751 | $input.click()) : k != $.inputmask.keyCode.INSERT || e.shiftKey || e.ctrlKey ? 0 != opts.insertMode || e.shiftKey || (k == $.inputmask.keyCode.RIGHT ? setTimeout(function() { |
||
| 752 | var caretPos = caret(input); |
||
| 753 | caret(input, caretPos.begin); |
||
| 754 | }, 0) : k == $.inputmask.keyCode.LEFT && setTimeout(function() { |
||
| 755 | var caretPos = caret(input); |
||
| 756 | caret(input, isRTL ? caretPos.begin + 1 : caretPos.begin - 1); |
||
| 757 | }, 0)) : (opts.insertMode = !opts.insertMode, caret(input, opts.insertMode || pos.begin != getMaskLength() ? pos.begin : pos.begin - 1)); |
||
| 758 | var currentCaretPos = caret(input), keydownResult = opts.onKeyDown.call(this, e, getBuffer(), currentCaretPos.begin, opts); |
||
| 759 | handleOnKeyResult(input, keydownResult, currentCaretPos), ignorable = -1 != $.inArray(k, opts.ignorables); |
||
| 760 | } |
||
| 761 | function keypressEvent(e, checkval, k, writeOut, strict, ndx) { |
||
| 762 | if (void 0 == k && skipKeyPressEvent) return !1; |
||
| 763 | skipKeyPressEvent = !0; |
||
| 764 | var input = this, $input = $(input); |
||
| 765 | e = e || window.event; |
||
| 766 | var k = checkval ? k : e.which || e.charCode || e.keyCode; |
||
| 767 | if (!(checkval === !0 || e.ctrlKey && e.altKey) && (e.ctrlKey || e.metaKey || ignorable)) return !0; |
||
| 768 | if (k) { |
||
| 769 | checkval !== !0 && 46 == k && 0 == e.shiftKey && "," == opts.radixPoint && (k = 44); |
||
| 770 | var forwardPosition, pos = checkval ? { |
||
| 771 | begin: ndx, |
||
| 772 | end: ndx |
||
| 773 | } : caret(input), c = String.fromCharCode(k), isSlctn = isSelection(pos.begin, pos.end); |
||
| 774 | isSlctn && (getMaskSet().undoPositions = $.extend(!0, {}, getMaskSet().validPositions), |
||
| 775 | handleRemove(input, $.inputmask.keyCode.DELETE, pos), opts.insertMode || (opts.insertMode = !opts.insertMode, |
||
| 776 | setValidPosition(pos.begin, strict), opts.insertMode = !opts.insertMode), isSlctn = !opts.multi), |
||
| 777 | getMaskSet().writeOutBuffer = !0; |
||
| 778 | var p = isRTL && !isSlctn ? pos.end : pos.begin, valResult = isValid(p, c, strict); |
||
| 779 | if (valResult !== !1) { |
||
| 780 | if (valResult !== !0 && (p = void 0 != valResult.pos ? valResult.pos : p, c = void 0 != valResult.c ? valResult.c : c), |
||
| 781 | resetMaskSet(!0), void 0 != valResult.caret) forwardPosition = valResult.caret; else { |
||
| 782 | var vps = getMaskSet().validPositions; |
||
| 783 | forwardPosition = !opts.keepStatic && (void 0 != vps[p + 1] && getTests(p + 1, vps[p].locator.slice(), p).length > 1 || void 0 != vps[p].alternation) ? p + 1 : seekNext(p); |
||
| 784 | } |
||
| 785 | getMaskSet().p = forwardPosition; |
||
| 786 | } |
||
| 787 | if (writeOut !== !1) { |
||
| 788 | var self = this; |
||
| 789 | if (setTimeout(function() { |
||
| 790 | opts.onKeyValidation.call(self, valResult, opts); |
||
| 791 | }, 0), getMaskSet().writeOutBuffer && valResult !== !1) { |
||
| 792 | var buffer = getBuffer(); |
||
| 793 | writeBuffer(input, buffer, checkval ? void 0 : opts.numericInput ? seekPrevious(forwardPosition) : forwardPosition), |
||
| 794 | checkval !== !0 && setTimeout(function() { |
||
| 795 | isComplete(buffer) === !0 && $input.trigger("complete"), skipInputEvent = !0, $input.trigger("input"); |
||
| 796 | }, 0); |
||
| 797 | } else isSlctn && (getMaskSet().buffer = void 0, getMaskSet().validPositions = getMaskSet().undoPositions); |
||
| 798 | } else isSlctn && (getMaskSet().buffer = void 0, getMaskSet().validPositions = getMaskSet().undoPositions); |
||
| 799 | if (opts.showTooltip && $input.prop("title", getMaskSet().mask), e && 1 != checkval) { |
||
| 800 | e.preventDefault(); |
||
| 801 | var currentCaretPos = caret(input), keypressResult = opts.onKeyPress.call(this, e, getBuffer(), currentCaretPos.begin, opts); |
||
| 802 | handleOnKeyResult(input, keypressResult, currentCaretPos); |
||
| 803 | } |
||
| 804 | } |
||
| 805 | } |
||
| 806 | function keyupEvent(e) { |
||
| 807 | var $input = $(this), input = this, k = e.keyCode, buffer = getBuffer(), currentCaretPos = caret(input), keyupResult = opts.onKeyUp.call(this, e, buffer, currentCaretPos.begin, opts); |
||
| 808 | handleOnKeyResult(input, keyupResult, currentCaretPos), k == $.inputmask.keyCode.TAB && opts.showMaskOnFocus && ($input.is(":focus") && 0 == input._valueGet().length ? (resetMaskSet(), |
||
| 809 | buffer = getBuffer(), writeBuffer(input, buffer), caret(input, 0), valueOnFocus = getBuffer().join("")) : (writeBuffer(input, buffer), |
||
| 810 | caret(input, TranslatePosition(0), TranslatePosition(getMaskLength())))); |
||
| 811 | } |
||
| 812 | function pasteEvent(e) { |
||
| 813 | if (skipInputEvent === !0 && "input" == e.type) return skipInputEvent = !1, !0; |
||
| 814 | var input = this, $input = $(input), inputValue = input._valueGet(), caretPos = caret(input); |
||
| 815 | if ("propertychange" == e.type && input._valueGet().length <= getMaskLength()) return !0; |
||
| 816 | "paste" == e.type && (window.clipboardData && window.clipboardData.getData ? inputValue = inputValue.substr(0, caretPos.begin) + window.clipboardData.getData("Text") + inputValue.substr(caretPos.end, inputValue.length) : e.originalEvent && e.originalEvent.clipboardData && e.originalEvent.clipboardData.getData && (inputValue = inputValue.substr(0, caretPos.begin) + e.originalEvent.clipboardData.getData("text/plain") + inputValue.substr(caretPos.end, inputValue.length))); |
||
| 817 | var pasteValue = $.isFunction(opts.onBeforePaste) ? opts.onBeforePaste.call(input, inputValue, opts) || inputValue : inputValue; |
||
| 818 | return checkVal(input, !0, !1, isRTL ? pasteValue.split("").reverse() : pasteValue.split("")), |
||
| 819 | $input.click(), isComplete(getBuffer()) === !0 && $input.trigger("complete"), !1; |
||
| 820 | } |
||
| 821 | function mobileInputEvent(e) { |
||
| 822 | if (skipInputEvent === !0 && "input" == e.type) return skipInputEvent = !1, !0; |
||
| 823 | var input = this, caretPos = caret(input), currentValue = input._valueGet(); |
||
| 824 | currentValue = currentValue.replace(new RegExp("(" + escapeRegex(getBufferTemplate().join("")) + ")*"), ""), |
||
| 825 | caretPos.begin > currentValue.length && (caret(input, currentValue.length), caretPos = caret(input)), |
||
| 826 | getBuffer().length - currentValue.length != 1 || currentValue.charAt(caretPos.begin) == getBuffer()[caretPos.begin] || currentValue.charAt(caretPos.begin + 1) == getBuffer()[caretPos.begin] || isMask(caretPos.begin) || (e.keyCode = $.inputmask.keyCode.BACKSPACE, |
||
| 827 | keydownEvent.call(input, e)), e.preventDefault(); |
||
| 828 | } |
||
| 829 | function inputFallBackEvent(e) { |
||
| 830 | if (skipInputEvent === !0 && "input" == e.type) return skipInputEvent = !1, !0; |
||
| 831 | var input = this; |
||
| 832 | checkVal(input, !1, !1); |
||
| 833 | var forwardPosition = getMaskSet().p; |
||
| 834 | writeBuffer(input, getBuffer(), opts.numericInput ? seekPrevious(forwardPosition) : forwardPosition), |
||
| 835 | isComplete(getBuffer()) === !0 && $(input).trigger("complete"), e.preventDefault(); |
||
| 836 | } |
||
| 837 | function compositionupdateEvent(e) { |
||
| 838 | skipInputEvent = !0; |
||
| 839 | var input = this; |
||
| 840 | return setTimeout(function() { |
||
| 841 | caret(input, caret(input).begin - 1); |
||
| 842 | var keypress = $.Event("keypress"); |
||
| 843 | keypress.which = e.originalEvent.data.charCodeAt(0), skipKeyPressEvent = !1, ignorable = !1, |
||
| 844 | keypressEvent.call(input, keypress, void 0, void 0, !1); |
||
| 845 | var forwardPosition = getMaskSet().p; |
||
| 846 | writeBuffer(input, getBuffer(), opts.numericInput ? seekPrevious(forwardPosition) : forwardPosition); |
||
| 847 | }, 0), !1; |
||
| 848 | } |
||
| 849 | function mask(el) { |
||
| 850 | if ($el = $(el), $el.is(":input") && isInputTypeSupported($el.attr("type"))) { |
||
| 851 | if ($el.data("_inputmask", { |
||
| 852 | maskset: maskset, |
||
| 853 | opts: opts, |
||
| 854 | isRTL: !1 |
||
| 855 | }), opts.showTooltip && $el.prop("title", getMaskSet().mask), ("rtl" == el.dir || opts.rightAlign) && $el.css("text-align", "right"), |
||
| 856 | "rtl" == el.dir || opts.numericInput) { |
||
| 857 | el.dir = "ltr", $el.removeAttr("dir"); |
||
| 858 | var inputData = $el.data("_inputmask"); |
||
| 859 | inputData.isRTL = !0, $el.data("_inputmask", inputData), isRTL = !0; |
||
| 860 | } |
||
| 861 | $el.unbind(".inputmask"), $el.closest("form").bind("submit", function() { |
||
| 862 | valueOnFocus != getBuffer().join("") && $el.change(), $el[0]._valueGet && $el[0]._valueGet() == getBufferTemplate().join("") && $el[0]._valueSet(""), |
||
| 863 | opts.removeMaskOnSubmit && $el.inputmask("remove"); |
||
| 864 | }).bind("reset", function() { |
||
| 865 | setTimeout(function() { |
||
| 866 | $el.trigger("setvalue"); |
||
| 867 | }, 0); |
||
| 868 | }), $el.bind("mouseenter.inputmask", function() { |
||
| 869 | var $input = $(this), input = this; |
||
| 870 | !$input.is(":focus") && opts.showMaskOnHover && input._valueGet() != getBuffer().join("") && writeBuffer(input, getBuffer()); |
||
| 871 | }).bind("blur.inputmask", function() { |
||
| 872 | var $input = $(this), input = this; |
||
| 873 | if ($input.data("_inputmask")) { |
||
| 874 | var nptValue = input._valueGet(), buffer = getBuffer(); |
||
| 875 | firstClick = !0, valueOnFocus != getBuffer().join("") && ($input.change(), valueOnFocus = getBuffer().join("")), |
||
| 876 | opts.clearMaskOnLostFocus && "" != nptValue && (nptValue == getBufferTemplate().join("") ? input._valueSet("") : clearOptionalTail(input)), |
||
| 877 | isComplete(buffer) === !1 && ($input.trigger("incomplete"), opts.clearIncomplete && (resetMaskSet(), |
||
| 878 | opts.clearMaskOnLostFocus ? input._valueSet("") : (buffer = getBufferTemplate().slice(), |
||
| 879 | writeBuffer(input, buffer)))); |
||
| 880 | } |
||
| 881 | }).bind("focus.inputmask", function() { |
||
| 882 | var $input = $(this), input = this, nptValue = input._valueGet(); |
||
| 883 | opts.showMaskOnFocus && !$input.is(":focus") && (!opts.showMaskOnHover || opts.showMaskOnHover && "" == nptValue) && input._valueGet() != getBuffer().join("") && writeBuffer(input, getBuffer(), seekNext(getLastValidPosition())), |
||
| 884 | valueOnFocus = getBuffer().join(""); |
||
| 885 | }).bind("mouseleave.inputmask", function() { |
||
| 886 | var $input = $(this), input = this; |
||
| 887 | opts.clearMaskOnLostFocus && ($input.is(":focus") || input._valueGet() == $input.attr("placeholder") || (input._valueGet() == getBufferTemplate().join("") || "" == input._valueGet() ? input._valueSet("") : clearOptionalTail(input))); |
||
| 888 | }).bind("click.inputmask", function() { |
||
| 889 | var $input = $(this), input = this; |
||
| 890 | if ($input.is(":focus")) { |
||
| 891 | var selectedCaret = caret(input); |
||
| 892 | if (selectedCaret.begin == selectedCaret.end) if (opts.radixFocus && "" != opts.radixPoint && -1 != $.inArray(opts.radixPoint, getBuffer()) && (firstClick || getBuffer().join("") == getBufferTemplate().join(""))) caret(input, $.inArray(opts.radixPoint, getBuffer())), |
||
| 893 | firstClick = !1; else { |
||
| 894 | var clickPosition = isRTL ? TranslatePosition(selectedCaret.begin) : selectedCaret.begin, lastPosition = seekNext(getLastValidPosition(clickPosition)); |
||
| 895 | lastPosition > clickPosition ? caret(input, isMask(clickPosition) ? clickPosition : seekNext(clickPosition)) : caret(input, lastPosition); |
||
| 896 | } |
||
| 897 | } |
||
| 898 | }).bind("dblclick.inputmask", function() { |
||
| 899 | var input = this; |
||
| 900 | setTimeout(function() { |
||
| 901 | caret(input, 0, seekNext(getLastValidPosition())); |
||
| 902 | }, 0); |
||
| 903 | }).bind(PasteEventType + ".inputmask dragdrop.inputmask drop.inputmask", pasteEvent).bind("setvalue.inputmask", function() { |
||
| 904 | var input = this; |
||
| 905 | checkVal(input, !0, !1), valueOnFocus = getBuffer().join(""), (opts.clearMaskOnLostFocus || opts.clearIncomplete) && input._valueGet() == getBufferTemplate().join("") && input._valueSet(""); |
||
| 906 | }).bind("cut.inputmask", function(e) { |
||
| 907 | skipInputEvent = !0; |
||
| 908 | var input = this, $input = $(input), pos = caret(input); |
||
| 909 | handleRemove(input, $.inputmask.keyCode.DELETE, pos); |
||
| 910 | var keypressResult = opts.onKeyPress.call(this, e, getBuffer(), getMaskSet().p, opts); |
||
| 911 | handleOnKeyResult(input, keypressResult, { |
||
| 912 | begin: getMaskSet().p, |
||
| 913 | end: getMaskSet().p |
||
| 914 | }), input._valueGet() == getBufferTemplate().join("") && $input.trigger("cleared"), |
||
| 915 | opts.showTooltip && $input.prop("title", getMaskSet().mask); |
||
| 916 | }).bind("complete.inputmask", opts.oncomplete).bind("incomplete.inputmask", opts.onincomplete).bind("cleared.inputmask", opts.oncleared), |
||
| 917 | $el.bind("keydown.inputmask", keydownEvent).bind("keypress.inputmask", keypressEvent).bind("keyup.inputmask", keyupEvent).bind("compositionupdate.inputmask", compositionupdateEvent), |
||
| 918 | "paste" === PasteEventType && $el.bind("input.inputmask", inputFallBackEvent), (android || androidfirefox || androidchrome || kindle) && ($el.unbind("input.inputmask"), |
||
| 919 | $el.bind("input.inputmask", mobileInputEvent)), patchValueProperty(el); |
||
| 920 | var initialValue = $.isFunction(opts.onBeforeMask) ? opts.onBeforeMask.call(el, el._valueGet(), opts) || el._valueGet() : el._valueGet(); |
||
| 921 | checkVal(el, !0, !1, initialValue.split("")), valueOnFocus = getBuffer().join(""); |
||
| 922 | var activeElement; |
||
| 923 | try { |
||
| 924 | activeElement = document.activeElement; |
||
| 925 | } catch (e) {} |
||
| 926 | isComplete(getBuffer()) === !1 && opts.clearIncomplete && resetMaskSet(), opts.clearMaskOnLostFocus ? getBuffer().join("") == getBufferTemplate().join("") ? el._valueSet("") : clearOptionalTail(el) : writeBuffer(el, getBuffer()), |
||
| 927 | activeElement === el && caret(el, seekNext(getLastValidPosition())), installEventRuler(el); |
||
| 928 | } |
||
| 929 | } |
||
| 930 | var valueOnFocus, $el, maxLength, isRTL = !1, skipKeyPressEvent = !1, skipInputEvent = !1, ignorable = !1, firstClick = !0; |
||
| 931 | if (void 0 != actionObj) switch (actionObj.action) { |
||
| 932 | case "isComplete": |
||
| 933 | return $el = $(actionObj.el), maskset = $el.data("_inputmask").maskset, opts = $el.data("_inputmask").opts, |
||
| 934 | isComplete(actionObj.buffer); |
||
| 935 | |||
| 936 | case "unmaskedvalue": |
||
| 937 | return $el = actionObj.$input, maskset = $el.data("_inputmask").maskset, opts = $el.data("_inputmask").opts, |
||
| 938 | isRTL = actionObj.$input.data("_inputmask").isRTL, unmaskedvalue(actionObj.$input); |
||
| 939 | |||
| 940 | case "mask": |
||
| 941 | valueOnFocus = getBuffer().join(""), mask(actionObj.el); |
||
| 942 | break; |
||
| 943 | |||
| 944 | case "format": |
||
| 945 | $el = $({}), $el.data("_inputmask", { |
||
| 946 | maskset: maskset, |
||
| 947 | opts: opts, |
||
| 948 | isRTL: opts.numericInput |
||
| 949 | }), opts.numericInput && (isRTL = !0); |
||
| 950 | var valueBuffer = ($.isFunction(opts.onBeforeMask) ? opts.onBeforeMask.call($el, actionObj.value, opts) || actionObj.value : actionObj.value).split(""); |
||
| 951 | return checkVal($el, !1, !1, isRTL ? valueBuffer.reverse() : valueBuffer), opts.onKeyPress.call(this, void 0, getBuffer(), 0, opts), |
||
| 952 | actionObj.metadata ? { |
||
| 953 | value: isRTL ? getBuffer().slice().reverse().join("") : getBuffer().join(""), |
||
| 954 | metadata: $el.inputmask("getmetadata") |
||
| 955 | } : isRTL ? getBuffer().slice().reverse().join("") : getBuffer().join(""); |
||
| 956 | |||
| 957 | case "isValid": |
||
| 958 | $el = $({}), $el.data("_inputmask", { |
||
| 959 | maskset: maskset, |
||
| 960 | opts: opts, |
||
| 961 | isRTL: opts.numericInput |
||
| 962 | }), opts.numericInput && (isRTL = !0); |
||
| 963 | var valueBuffer = actionObj.value.split(""); |
||
| 964 | checkVal($el, !1, !0, isRTL ? valueBuffer.reverse() : valueBuffer); |
||
| 965 | for (var buffer = getBuffer(), rl = determineLastRequiredPosition(), lmib = buffer.length - 1; lmib > rl && !isMask(lmib); lmib--) ; |
||
| 966 | return buffer.splice(rl, lmib + 1 - rl), isComplete(buffer) && actionObj.value == buffer.join(""); |
||
| 967 | |||
| 968 | case "getemptymask": |
||
| 969 | return $el = $(actionObj.el), maskset = $el.data("_inputmask").maskset, opts = $el.data("_inputmask").opts, |
||
| 970 | getBufferTemplate(); |
||
| 971 | |||
| 972 | case "remove": |
||
| 973 | var el = actionObj.el; |
||
| 974 | $el = $(el), maskset = $el.data("_inputmask").maskset, opts = $el.data("_inputmask").opts, |
||
| 975 | el._valueSet(unmaskedvalue($el)), $el.unbind(".inputmask"), $el.removeData("_inputmask"); |
||
| 976 | var valueProperty; |
||
| 977 | Object.getOwnPropertyDescriptor && (valueProperty = Object.getOwnPropertyDescriptor(el, "value")), |
||
| 978 | valueProperty && valueProperty.get ? el._valueGet && Object.defineProperty(el, "value", { |
||
| 979 | get: el._valueGet, |
||
| 980 | set: el._valueSet |
||
| 981 | }) : document.__lookupGetter__ && el.__lookupGetter__("value") && el._valueGet && (el.__defineGetter__("value", el._valueGet), |
||
| 982 | el.__defineSetter__("value", el._valueSet)); |
||
| 983 | try { |
||
| 984 | delete el._valueGet, delete el._valueSet; |
||
| 985 | } catch (e) { |
||
| 986 | el._valueGet = void 0, el._valueSet = void 0; |
||
| 987 | } |
||
| 988 | break; |
||
| 989 | |||
| 990 | case "getmetadata": |
||
| 991 | if ($el = $(actionObj.el), maskset = $el.data("_inputmask").maskset, opts = $el.data("_inputmask").opts, |
||
| 992 | $.isArray(maskset.metadata)) { |
||
| 993 | for (var alternation, lvp = getLastValidPosition(), firstAlt = lvp; firstAlt >= 0; firstAlt--) if (getMaskSet().validPositions[firstAlt] && void 0 != getMaskSet().validPositions[firstAlt].alternation) { |
||
| 994 | alternation = getMaskSet().validPositions[firstAlt].alternation; |
||
| 995 | break; |
||
| 996 | } |
||
| 997 | return void 0 != alternation ? maskset.metadata[getMaskSet().validPositions[lvp].locator[alternation]] : maskset.metadata[0]; |
||
| 998 | } |
||
| 999 | return maskset.metadata; |
||
| 1000 | } |
||
| 1001 | } |
||
| 1002 | if (void 0 === $.fn.inputmask) { |
||
| 1003 | var ua = ("function" == typeof ScriptEngineMajorVersion ? ScriptEngineMajorVersion() >= 10 : /*@cc_on (@_jscript_version >= 10) ||@*/ !1, |
||
| 1004 | navigator.userAgent), iphone = null !== ua.match(new RegExp("iphone", "i")), android = null !== ua.match(new RegExp("android.*safari.*", "i")), androidchrome = null !== ua.match(new RegExp("android.*chrome.*", "i")), androidfirefox = null !== ua.match(new RegExp("android.*firefox.*", "i")), kindle = /Kindle/i.test(ua) || /Silk/i.test(ua) || /KFTT/i.test(ua) || /KFOT/i.test(ua) || /KFJWA/i.test(ua) || /KFJWI/i.test(ua) || /KFSOWI/i.test(ua) || /KFTHWA/i.test(ua) || /KFTHWI/i.test(ua) || /KFAPWA/i.test(ua) || /KFAPWI/i.test(ua), PasteEventType = isInputEventSupported("paste") ? "paste" : isInputEventSupported("input") ? "input" : "propertychange"; |
||
| 1005 | $.inputmask = { |
||
| 1006 | defaults: { |
||
| 1007 | placeholder: "_", |
||
| 1008 | optionalmarker: { |
||
| 1009 | start: "[", |
||
| 1010 | end: "]" |
||
| 1011 | }, |
||
| 1012 | quantifiermarker: { |
||
| 1013 | start: "{", |
||
| 1014 | end: "}" |
||
| 1015 | }, |
||
| 1016 | groupmarker: { |
||
| 1017 | start: "(", |
||
| 1018 | end: ")" |
||
| 1019 | }, |
||
| 1020 | alternatormarker: "|", |
||
| 1021 | escapeChar: "\\", |
||
| 1022 | mask: null, |
||
| 1023 | oncomplete: $.noop, |
||
| 1024 | onincomplete: $.noop, |
||
| 1025 | oncleared: $.noop, |
||
| 1026 | repeat: 0, |
||
| 1027 | greedy: !0, |
||
| 1028 | autoUnmask: !1, |
||
| 1029 | removeMaskOnSubmit: !0, |
||
| 1030 | clearMaskOnLostFocus: !0, |
||
| 1031 | insertMode: !0, |
||
| 1032 | clearIncomplete: !1, |
||
| 1033 | aliases: {}, |
||
| 1034 | alias: null, |
||
| 1035 | onKeyUp: $.noop, |
||
| 1036 | onKeyPress: $.noop, |
||
| 1037 | onKeyDown: $.noop, |
||
| 1038 | onBeforeMask: void 0, |
||
| 1039 | onBeforePaste: void 0, |
||
| 1040 | onUnMask: void 0, |
||
| 1041 | showMaskOnFocus: !0, |
||
| 1042 | showMaskOnHover: !0, |
||
| 1043 | onKeyValidation: $.noop, |
||
| 1044 | skipOptionalPartCharacter: " ", |
||
| 1045 | showTooltip: !1, |
||
| 1046 | numericInput: !1, |
||
| 1047 | rightAlign: !1, |
||
| 1048 | radixPoint: "", |
||
| 1049 | radixFocus: !1, |
||
| 1050 | nojumps: !1, |
||
| 1051 | nojumpsThreshold: 0, |
||
| 1052 | keepStatic: void 0, |
||
| 1053 | definitions: { |
||
| 1054 | "9": { |
||
| 1055 | validator: "[0-9]", |
||
| 1056 | cardinality: 1, |
||
| 1057 | definitionSymbol: "*" |
||
| 1058 | }, |
||
| 1059 | a: { |
||
| 1060 | validator: "[A-Za-zА-яЁёÀ-ÿµ]", |
||
| 1061 | cardinality: 1, |
||
| 1062 | definitionSymbol: "*" |
||
| 1063 | }, |
||
| 1064 | "*": { |
||
| 1065 | validator: "[0-9A-Za-zА-яЁёÀ-ÿµ]", |
||
| 1066 | cardinality: 1 |
||
| 1067 | } |
||
| 1068 | }, |
||
| 1069 | 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 ], |
||
| 1070 | isComplete: void 0, |
||
| 1071 | postProcessOnBlur: void 0 |
||
| 1072 | }, |
||
| 1073 | keyCode: { |
||
| 1074 | ALT: 18, |
||
| 1075 | BACKSPACE: 8, |
||
| 1076 | CAPS_LOCK: 20, |
||
| 1077 | COMMA: 188, |
||
| 1078 | COMMAND: 91, |
||
| 1079 | COMMAND_LEFT: 91, |
||
| 1080 | COMMAND_RIGHT: 93, |
||
| 1081 | CONTROL: 17, |
||
| 1082 | DELETE: 46, |
||
| 1083 | DOWN: 40, |
||
| 1084 | END: 35, |
||
| 1085 | ENTER: 13, |
||
| 1086 | ESCAPE: 27, |
||
| 1087 | HOME: 36, |
||
| 1088 | INSERT: 45, |
||
| 1089 | LEFT: 37, |
||
| 1090 | MENU: 93, |
||
| 1091 | NUMPAD_ADD: 107, |
||
| 1092 | NUMPAD_DECIMAL: 110, |
||
| 1093 | NUMPAD_DIVIDE: 111, |
||
| 1094 | NUMPAD_ENTER: 108, |
||
| 1095 | NUMPAD_MULTIPLY: 106, |
||
| 1096 | NUMPAD_SUBTRACT: 109, |
||
| 1097 | PAGE_DOWN: 34, |
||
| 1098 | PAGE_UP: 33, |
||
| 1099 | PERIOD: 190, |
||
| 1100 | RIGHT: 39, |
||
| 1101 | SHIFT: 16, |
||
| 1102 | SPACE: 32, |
||
| 1103 | TAB: 9, |
||
| 1104 | UP: 38, |
||
| 1105 | WINDOWS: 91 |
||
| 1106 | }, |
||
| 1107 | masksCache: {}, |
||
| 1108 | escapeRegex: function(str) { |
||
| 1109 | var specials = [ "/", ".", "*", "+", "?", "|", "(", ")", "[", "]", "{", "}", "\\" ]; |
||
| 1110 | return str.replace(new RegExp("(\\" + specials.join("|\\") + ")", "gim"), "\\$1"); |
||
| 1111 | }, |
||
| 1112 | format: function(value, options, metadata) { |
||
| 1113 | var opts = $.extend(!0, {}, $.inputmask.defaults, options); |
||
| 1114 | return resolveAlias(opts.alias, options, opts), maskScope({ |
||
| 1115 | action: "format", |
||
| 1116 | value: value, |
||
| 1117 | metadata: metadata |
||
| 1118 | }, generateMaskSet(opts), opts); |
||
| 1119 | }, |
||
| 1120 | isValid: function(value, options) { |
||
| 1121 | var opts = $.extend(!0, {}, $.inputmask.defaults, options); |
||
| 1122 | return resolveAlias(opts.alias, options, opts), maskScope({ |
||
| 1123 | action: "isValid", |
||
| 1124 | value: value |
||
| 1125 | }, generateMaskSet(opts), opts); |
||
| 1126 | } |
||
| 1127 | }, $.fn.inputmask = function(fn, options, targetScope, targetData, msk) { |
||
| 1128 | function importAttributeOptions(npt, opts, importedOptionsContainer) { |
||
| 1129 | var $npt = $(npt); |
||
| 1130 | $npt.data("inputmask-alias") && resolveAlias($npt.data("inputmask-alias"), {}, opts); |
||
| 1131 | for (var option in opts) { |
||
| 1132 | var optionData = $npt.data("inputmask-" + option.toLowerCase()); |
||
| 1133 | void 0 != optionData && ("mask" == option && 0 == optionData.indexOf("[") ? (opts[option] = optionData.replace(/[\s[\]]/g, "").split("','"), |
||
| 1134 | opts[option][0] = opts[option][0].replace("'", ""), opts[option][opts[option].length - 1] = opts[option][opts[option].length - 1].replace("'", "")) : opts[option] = "boolean" == typeof optionData ? optionData : optionData.toString(), |
||
| 1135 | importedOptionsContainer && (importedOptionsContainer[option] = opts[option])); |
||
| 1136 | } |
||
| 1137 | return opts; |
||
| 1138 | } |
||
| 1139 | targetScope = targetScope || maskScope, targetData = targetData || "_inputmask"; |
||
| 1140 | var maskset, opts = $.extend(!0, {}, $.inputmask.defaults, options); |
||
| 1141 | if ("string" == typeof fn) switch (fn) { |
||
| 1142 | case "mask": |
||
| 1143 | return resolveAlias(opts.alias, options, opts), maskset = generateMaskSet(opts, targetScope !== maskScope), |
||
| 1144 | void 0 == maskset ? this : this.each(function() { |
||
| 1145 | targetScope({ |
||
| 1146 | action: "mask", |
||
| 1147 | el: this |
||
| 1148 | }, $.extend(!0, {}, maskset), importAttributeOptions(this, opts)); |
||
| 1149 | }); |
||
| 1150 | |||
| 1151 | case "unmaskedvalue": |
||
| 1152 | var $input = $(this); |
||
| 1153 | return $input.data(targetData) ? targetScope({ |
||
| 1154 | action: "unmaskedvalue", |
||
| 1155 | $input: $input |
||
| 1156 | }) : $input.val(); |
||
| 1157 | |||
| 1158 | case "remove": |
||
| 1159 | return this.each(function() { |
||
| 1160 | var $input = $(this); |
||
| 1161 | $input.data(targetData) && targetScope({ |
||
| 1162 | action: "remove", |
||
| 1163 | el: this |
||
| 1164 | }); |
||
| 1165 | }); |
||
| 1166 | |||
| 1167 | case "getemptymask": |
||
| 1168 | return this.data(targetData) ? targetScope({ |
||
| 1169 | action: "getemptymask", |
||
| 1170 | el: this |
||
| 1171 | }) : ""; |
||
| 1172 | |||
| 1173 | case "hasMaskedValue": |
||
| 1174 | return this.data(targetData) ? !this.data(targetData).opts.autoUnmask : !1; |
||
| 1175 | |||
| 1176 | case "isComplete": |
||
| 1177 | return this.data(targetData) ? targetScope({ |
||
| 1178 | action: "isComplete", |
||
| 1179 | buffer: this[0]._valueGet().split(""), |
||
| 1180 | el: this |
||
| 1181 | }) : !0; |
||
| 1182 | |||
| 1183 | case "getmetadata": |
||
| 1184 | return this.data(targetData) ? targetScope({ |
||
| 1185 | action: "getmetadata", |
||
| 1186 | el: this |
||
| 1187 | }) : void 0; |
||
| 1188 | |||
| 1189 | case "_detectScope": |
||
| 1190 | return resolveAlias(opts.alias, options, opts), void 0 == msk || resolveAlias(msk, options, opts) || -1 != $.inArray(msk, [ "mask", "unmaskedvalue", "remove", "getemptymask", "hasMaskedValue", "isComplete", "getmetadata", "_detectScope" ]) || (opts.mask = msk), |
||
| 1191 | $.isFunction(opts.mask) && (opts.mask = opts.mask.call(this, opts)), $.isArray(opts.mask); |
||
| 1192 | |||
| 1193 | default: |
||
| 1194 | return resolveAlias(opts.alias, options, opts), resolveAlias(fn, options, opts) || (opts.mask = fn), |
||
| 1195 | maskset = generateMaskSet(opts, targetScope !== maskScope), void 0 == maskset ? this : this.each(function() { |
||
| 1196 | targetScope({ |
||
| 1197 | action: "mask", |
||
| 1198 | el: this |
||
| 1199 | }, $.extend(!0, {}, maskset), importAttributeOptions(this, opts)); |
||
| 1200 | }); |
||
| 1201 | } else { |
||
| 1202 | if ("object" == typeof fn) return opts = $.extend(!0, {}, $.inputmask.defaults, fn), |
||
| 1203 | resolveAlias(opts.alias, fn, opts), maskset = generateMaskSet(opts, targetScope !== maskScope), |
||
| 1204 | void 0 == maskset ? this : this.each(function() { |
||
| 1205 | targetScope({ |
||
| 1206 | action: "mask", |
||
| 1207 | el: this |
||
| 1208 | }, $.extend(!0, {}, maskset), importAttributeOptions(this, opts)); |
||
| 1209 | }); |
||
| 1210 | if (void 0 == fn) return this.each(function() { |
||
| 1211 | var attrOptions = $(this).attr("data-inputmask"); |
||
| 1212 | if (attrOptions && "" != attrOptions) try { |
||
| 1213 | attrOptions = attrOptions.replace(new RegExp("'", "g"), '"'); |
||
| 1214 | var dataoptions = $.parseJSON("{" + attrOptions + "}"); |
||
| 1215 | $.extend(!0, dataoptions, options), opts = $.extend(!0, {}, $.inputmask.defaults, dataoptions), |
||
| 1216 | opts = importAttributeOptions(this, opts), resolveAlias(opts.alias, dataoptions, opts), |
||
| 1217 | opts.alias = void 0, $(this).inputmask("mask", opts, targetScope); |
||
| 1218 | } catch (ex) {} |
||
| 1219 | if ($(this).attr("data-inputmask-mask") || $(this).attr("data-inputmask-alias")) { |
||
| 1220 | opts = $.extend(!0, {}, $.inputmask.defaults, {}); |
||
| 1221 | var dataOptions = {}; |
||
| 1222 | opts = importAttributeOptions(this, opts, dataOptions), resolveAlias(opts.alias, dataOptions, opts), |
||
| 1223 | opts.alias = void 0, $(this).inputmask("mask", opts, targetScope); |
||
| 1224 | } |
||
| 1225 | }); |
||
| 1226 | } |
||
| 1227 | }; |
||
| 1228 | } |
||
| 1229 | return $.fn.inputmask; |
||
| 1230 | }); |