Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 1 | espaco | 1 | /*! |
| 2 | * jquery.inputmask.bundle |
||
| 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($) { |
||
| 9 | function isInputEventSupported(eventName) { |
||
| 10 | var el = document.createElement("input"), evName = "on" + eventName, isSupported = evName in el; |
||
| 11 | return isSupported || (el.setAttribute(evName, "return;"), isSupported = "function" == typeof el[evName]), |
||
| 12 | el = null, isSupported; |
||
| 13 | } |
||
| 14 | function isInputTypeSupported(inputType) { |
||
| 15 | var isSupported = "text" == inputType || "tel" == inputType; |
||
| 16 | if (!isSupported) { |
||
| 17 | var el = document.createElement("input"); |
||
| 18 | el.setAttribute("type", inputType), isSupported = "text" === el.type, el = null; |
||
| 19 | } |
||
| 20 | return isSupported; |
||
| 21 | } |
||
| 22 | function resolveAlias(aliasStr, options, opts) { |
||
| 23 | var aliasDefinition = opts.aliases[aliasStr]; |
||
| 24 | return aliasDefinition ? (aliasDefinition.alias && resolveAlias(aliasDefinition.alias, void 0, opts), |
||
| 25 | $.extend(!0, opts, aliasDefinition), $.extend(!0, opts, options), !0) : !1; |
||
| 26 | } |
||
| 27 | function generateMaskSet(opts, multi) { |
||
| 28 | function analyseMask(mask) { |
||
| 29 | function maskToken(isGroup, isOptional, isQuantifier, isAlternator) { |
||
| 30 | this.matches = [], this.isGroup = isGroup || !1, this.isOptional = isOptional || !1, |
||
| 31 | this.isQuantifier = isQuantifier || !1, this.isAlternator = isAlternator || !1, |
||
| 32 | this.quantifier = { |
||
| 33 | min: 1, |
||
| 34 | max: 1 |
||
| 35 | }; |
||
| 36 | } |
||
| 37 | function insertTestDefinition(mtoken, element, position) { |
||
| 38 | var maskdef = opts.definitions[element], newBlockMarker = 0 == mtoken.matches.length; |
||
| 39 | if (position = void 0 != position ? position : mtoken.matches.length, maskdef && !escaped) { |
||
| 40 | for (var prevalidators = maskdef.prevalidator, prevalidatorsL = prevalidators ? prevalidators.length : 0, i = 1; i < maskdef.cardinality; i++) { |
||
| 41 | var prevalidator = prevalidatorsL >= i ? prevalidators[i - 1] : [], validator = prevalidator.validator, cardinality = prevalidator.cardinality; |
||
| 42 | mtoken.matches.splice(position++, 0, { |
||
| 43 | fn: validator ? "string" == typeof validator ? new RegExp(validator) : new function() { |
||
| 44 | this.test = validator; |
||
| 45 | }() : new RegExp("."), |
||
| 46 | cardinality: cardinality ? cardinality : 1, |
||
| 47 | optionality: mtoken.isOptional, |
||
| 48 | newBlockMarker: newBlockMarker, |
||
| 49 | casing: maskdef.casing, |
||
| 50 | def: maskdef.definitionSymbol || element, |
||
| 51 | placeholder: maskdef.placeholder, |
||
| 52 | mask: element |
||
| 53 | }); |
||
| 54 | } |
||
| 55 | mtoken.matches.splice(position++, 0, { |
||
| 56 | fn: maskdef.validator ? "string" == typeof maskdef.validator ? new RegExp(maskdef.validator) : new function() { |
||
| 57 | this.test = maskdef.validator; |
||
| 58 | }() : new RegExp("."), |
||
| 59 | cardinality: maskdef.cardinality, |
||
| 60 | optionality: mtoken.isOptional, |
||
| 61 | newBlockMarker: newBlockMarker, |
||
| 62 | casing: maskdef.casing, |
||
| 63 | def: maskdef.definitionSymbol || element, |
||
| 64 | placeholder: maskdef.placeholder, |
||
| 65 | mask: element |
||
| 66 | }); |
||
| 67 | } else mtoken.matches.splice(position++, 0, { |
||
| 68 | fn: null, |
||
| 69 | cardinality: 0, |
||
| 70 | optionality: mtoken.isOptional, |
||
| 71 | newBlockMarker: newBlockMarker, |
||
| 72 | casing: null, |
||
| 73 | def: element, |
||
| 74 | placeholder: void 0, |
||
| 75 | mask: element |
||
| 76 | }), escaped = !1; |
||
| 77 | } |
||
| 78 | 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], |
||
| 79 | m.charAt(0)) { |
||
| 80 | case opts.optionalmarker.end: |
||
| 81 | case opts.groupmarker.end: |
||
| 82 | if (openingToken = openenings.pop(), openenings.length > 0) { |
||
| 83 | if (currentOpeningToken = openenings[openenings.length - 1], currentOpeningToken.matches.push(openingToken), |
||
| 84 | currentOpeningToken.isAlternator) { |
||
| 85 | alternator = openenings.pop(); |
||
| 86 | for (var mndx = 0; mndx < alternator.matches.length; mndx++) alternator.matches[mndx].isGroup = !1; |
||
| 87 | openenings.length > 0 ? (currentOpeningToken = openenings[openenings.length - 1], |
||
| 88 | currentOpeningToken.matches.push(alternator)) : currentToken.matches.push(alternator); |
||
| 89 | } |
||
| 90 | } else currentToken.matches.push(openingToken); |
||
| 91 | break; |
||
| 92 | |||
| 93 | case opts.optionalmarker.start: |
||
| 94 | openenings.push(new maskToken(!1, !0)); |
||
| 95 | break; |
||
| 96 | |||
| 97 | case opts.groupmarker.start: |
||
| 98 | openenings.push(new maskToken(!0)); |
||
| 99 | break; |
||
| 100 | |||
| 101 | case opts.quantifiermarker.start: |
||
| 102 | var quantifier = new maskToken(!1, !1, !0); |
||
| 103 | m = m.replace(/[{}]/g, ""); |
||
| 104 | 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]); |
||
| 105 | if (("*" == mq1 || "+" == mq1) && (mq0 = "*" == mq1 ? 0 : 1), quantifier.quantifier = { |
||
| 106 | min: mq0, |
||
| 107 | max: mq1 |
||
| 108 | }, openenings.length > 0) { |
||
| 109 | var matches = openenings[openenings.length - 1].matches; |
||
| 110 | if (match = matches.pop(), !match.isGroup) { |
||
| 111 | var groupToken = new maskToken(!0); |
||
| 112 | groupToken.matches.push(match), match = groupToken; |
||
| 113 | } |
||
| 114 | matches.push(match), matches.push(quantifier); |
||
| 115 | } else { |
||
| 116 | if (match = currentToken.matches.pop(), !match.isGroup) { |
||
| 117 | var groupToken = new maskToken(!0); |
||
| 118 | groupToken.matches.push(match), match = groupToken; |
||
| 119 | } |
||
| 120 | currentToken.matches.push(match), currentToken.matches.push(quantifier); |
||
| 121 | } |
||
| 122 | break; |
||
| 123 | |||
| 124 | case opts.escapeChar: |
||
| 125 | escaped = !0; |
||
| 126 | break; |
||
| 127 | |||
| 128 | case opts.alternatormarker: |
||
| 129 | openenings.length > 0 ? (currentOpeningToken = openenings[openenings.length - 1], |
||
| 130 | lastMatch = currentOpeningToken.matches.pop()) : lastMatch = currentToken.matches.pop(), |
||
| 131 | lastMatch.isAlternator ? openenings.push(lastMatch) : (alternator = new maskToken(!1, !1, !1, !0), |
||
| 132 | alternator.matches.push(lastMatch), openenings.push(alternator)); |
||
| 133 | break; |
||
| 134 | |||
| 135 | default: |
||
| 136 | if (openenings.length > 0) { |
||
| 137 | if (currentOpeningToken = openenings[openenings.length - 1], currentOpeningToken.matches.length > 0 && (lastMatch = currentOpeningToken.matches[currentOpeningToken.matches.length - 1], |
||
| 138 | lastMatch.isGroup && (lastMatch.isGroup = !1, insertTestDefinition(lastMatch, opts.groupmarker.start, 0), |
||
| 139 | insertTestDefinition(lastMatch, opts.groupmarker.end))), insertTestDefinition(currentOpeningToken, m), |
||
| 140 | currentOpeningToken.isAlternator) { |
||
| 141 | alternator = openenings.pop(); |
||
| 142 | for (var mndx = 0; mndx < alternator.matches.length; mndx++) alternator.matches[mndx].isGroup = !1; |
||
| 143 | openenings.length > 0 ? (currentOpeningToken = openenings[openenings.length - 1], |
||
| 144 | currentOpeningToken.matches.push(alternator)) : currentToken.matches.push(alternator); |
||
| 145 | } |
||
| 146 | } else currentToken.matches.length > 0 && (lastMatch = currentToken.matches[currentToken.matches.length - 1], |
||
| 147 | lastMatch.isGroup && (lastMatch.isGroup = !1, insertTestDefinition(lastMatch, opts.groupmarker.start, 0), |
||
| 148 | insertTestDefinition(lastMatch, opts.groupmarker.end))), insertTestDefinition(currentToken, m); |
||
| 149 | } |
||
| 150 | return currentToken.matches.length > 0 && (lastMatch = currentToken.matches[currentToken.matches.length - 1], |
||
| 151 | lastMatch.isGroup && (lastMatch.isGroup = !1, insertTestDefinition(lastMatch, opts.groupmarker.start, 0), |
||
| 152 | insertTestDefinition(lastMatch, opts.groupmarker.end)), maskTokens.push(currentToken)), |
||
| 153 | maskTokens; |
||
| 154 | } |
||
| 155 | function generateMask(mask, metadata) { |
||
| 156 | if (opts.numericInput && opts.multi !== !0) { |
||
| 157 | mask = mask.split("").reverse(); |
||
| 158 | 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); |
||
| 159 | mask = mask.join(""); |
||
| 160 | } |
||
| 161 | if (void 0 == mask || "" == mask) return void 0; |
||
| 162 | if (1 == mask.length && 0 == opts.greedy && 0 != opts.repeat && (opts.placeholder = ""), |
||
| 163 | opts.repeat > 0 || "*" == opts.repeat || "+" == opts.repeat) { |
||
| 164 | var repeatStart = "*" == opts.repeat ? 0 : "+" == opts.repeat ? 1 : opts.repeat; |
||
| 165 | mask = opts.groupmarker.start + mask + opts.groupmarker.end + opts.quantifiermarker.start + repeatStart + "," + opts.repeat + opts.quantifiermarker.end; |
||
| 166 | } |
||
| 167 | return void 0 == $.inputmask.masksCache[mask] && ($.inputmask.masksCache[mask] = { |
||
| 168 | mask: mask, |
||
| 169 | maskToken: analyseMask(mask), |
||
| 170 | validPositions: {}, |
||
| 171 | _buffer: void 0, |
||
| 172 | buffer: void 0, |
||
| 173 | tests: {}, |
||
| 174 | metadata: metadata |
||
| 175 | }), $.extend(!0, {}, $.inputmask.masksCache[mask]); |
||
| 176 | } |
||
| 177 | var ms = void 0; |
||
| 178 | if ($.isFunction(opts.mask) && (opts.mask = opts.mask.call(this, opts)), $.isArray(opts.mask)) if (multi) ms = [], |
||
| 179 | $.each(opts.mask, function(ndx, msk) { |
||
| 180 | ms.push(void 0 == msk.mask || $.isFunction(msk.mask) ? generateMask(msk.toString(), msk) : generateMask(msk.mask.toString(), msk)); |
||
| 181 | }); else { |
||
| 182 | opts.keepStatic = void 0 == opts.keepStatic ? !0 : opts.keepStatic; |
||
| 183 | var altMask = "("; |
||
| 184 | $.each(opts.mask, function(ndx, msk) { |
||
| 185 | altMask.length > 1 && (altMask += ")|("), altMask += void 0 == msk.mask || $.isFunction(msk.mask) ? msk.toString() : msk.mask.toString(); |
||
| 186 | }), altMask += ")", ms = generateMask(altMask, opts.mask); |
||
| 187 | } 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)); |
||
| 188 | return ms; |
||
| 189 | } |
||
| 190 | function maskScope(actionObj, maskset, opts) { |
||
| 191 | function getMaskTemplate(baseOnInput, minimalPos, includeInput) { |
||
| 192 | minimalPos = minimalPos || 0; |
||
| 193 | var ndxIntlzr, test, testPos, maskTemplate = [], pos = 0; |
||
| 194 | do { |
||
| 195 | if (baseOnInput === !0 && getMaskSet().validPositions[pos]) { |
||
| 196 | var validPos = getMaskSet().validPositions[pos]; |
||
| 197 | test = validPos.match, ndxIntlzr = validPos.locator.slice(), maskTemplate.push(includeInput === !0 ? validPos.input : getPlaceholder(pos, test)); |
||
| 198 | } else { |
||
| 199 | if (minimalPos > pos) { |
||
| 200 | var testPositions = getTests(pos, ndxIntlzr, pos - 1); |
||
| 201 | testPos = testPositions[0]; |
||
| 202 | } else testPos = getTestTemplate(pos, ndxIntlzr, pos - 1); |
||
| 203 | test = testPos.match, ndxIntlzr = testPos.locator.slice(), maskTemplate.push(getPlaceholder(pos, test)); |
||
| 204 | } |
||
| 205 | pos++; |
||
| 206 | } while ((void 0 == maxLength || maxLength > pos - 1) && null != test.fn || null == test.fn && "" != test.def || minimalPos >= pos); |
||
| 207 | return maskTemplate.pop(), maskTemplate; |
||
| 208 | } |
||
| 209 | function getMaskSet() { |
||
| 210 | return maskset; |
||
| 211 | } |
||
| 212 | function resetMaskSet(soft) { |
||
| 213 | var maskset = getMaskSet(); |
||
| 214 | maskset.buffer = void 0, maskset.tests = {}, soft !== !0 && (maskset._buffer = void 0, |
||
| 215 | maskset.validPositions = {}, maskset.p = 0); |
||
| 216 | } |
||
| 217 | function getLastValidPosition(closestTo) { |
||
| 218 | var maskset = getMaskSet(), lastValidPosition = -1, valids = maskset.validPositions; |
||
| 219 | void 0 == closestTo && (closestTo = -1); |
||
| 220 | var before = lastValidPosition, after = lastValidPosition; |
||
| 221 | for (var posNdx in valids) { |
||
| 222 | var psNdx = parseInt(posNdx); |
||
| 223 | (-1 == closestTo || null != valids[psNdx].match.fn) && (closestTo >= psNdx && (before = psNdx), |
||
| 224 | psNdx >= closestTo && (after = psNdx)); |
||
| 225 | } |
||
| 226 | return lastValidPosition = closestTo - before > 1 || closestTo > after ? before : after; |
||
| 227 | } |
||
| 228 | function setValidPosition(pos, validTest, fromSetValid) { |
||
| 229 | if (opts.insertMode && void 0 != getMaskSet().validPositions[pos] && void 0 == fromSetValid) { |
||
| 230 | var i, positionsClone = $.extend(!0, {}, getMaskSet().validPositions), lvp = getLastValidPosition(); |
||
| 231 | for (i = pos; lvp >= i; i++) delete getMaskSet().validPositions[i]; |
||
| 232 | getMaskSet().validPositions[pos] = validTest; |
||
| 233 | var j, valid = !0; |
||
| 234 | for (i = pos; lvp >= i; i++) { |
||
| 235 | var t = positionsClone[i]; |
||
| 236 | if (void 0 != t) { |
||
| 237 | var vps = getMaskSet().validPositions; |
||
| 238 | 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), |
||
| 239 | valid = positionCanMatchDefinition(j, t.match.def) ? valid && isValid(j, t.input, !0, !0) !== !1 : null == t.match.fn; |
||
| 240 | } |
||
| 241 | if (!valid) break; |
||
| 242 | } |
||
| 243 | if (!valid) return getMaskSet().validPositions = $.extend(!0, {}, positionsClone), |
||
| 244 | !1; |
||
| 245 | } else getMaskSet().validPositions[pos] = validTest; |
||
| 246 | return !0; |
||
| 247 | } |
||
| 248 | function stripValidPositions(start, end) { |
||
| 249 | var i, startPos = start; |
||
| 250 | for (void 0 != getMaskSet().validPositions[start] && getMaskSet().validPositions[start].input == opts.radixPoint && (end++, |
||
| 251 | startPos++), i = startPos; end > i; i++) void 0 == getMaskSet().validPositions[i] || getMaskSet().validPositions[i].input == opts.radixPoint && i != getLastValidPosition() || delete getMaskSet().validPositions[i]; |
||
| 252 | for (i = end; i <= getLastValidPosition(); ) { |
||
| 253 | var t = getMaskSet().validPositions[i], s = getMaskSet().validPositions[startPos]; |
||
| 254 | void 0 != t && void 0 == s ? (positionCanMatchDefinition(startPos, t.match.def) && isValid(startPos, t.input, !0) !== !1 && (delete getMaskSet().validPositions[i], |
||
| 255 | i++), startPos++) : i++; |
||
| 256 | } |
||
| 257 | var lvp = getLastValidPosition(); |
||
| 258 | lvp >= start && void 0 != getMaskSet().validPositions[lvp] && getMaskSet().validPositions[lvp].input == opts.radixPoint && delete getMaskSet().validPositions[lvp], |
||
| 259 | resetMaskSet(!0); |
||
| 260 | } |
||
| 261 | function getTestTemplate(pos, ndxIntlzr, tstPs) { |
||
| 262 | function checkAlternationMatch(test, altNdx, altArr) { |
||
| 263 | 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)) { |
||
| 264 | isMatch = !0; |
||
| 265 | break; |
||
| 266 | } |
||
| 267 | return isMatch; |
||
| 268 | } |
||
| 269 | 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], |
||
| 270 | !(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++) ; |
||
| 271 | return testPos; |
||
| 272 | } |
||
| 273 | function getTest(pos) { |
||
| 274 | return getMaskSet().validPositions[pos] ? getMaskSet().validPositions[pos].match : getTests(pos)[0].match; |
||
| 275 | } |
||
| 276 | function positionCanMatchDefinition(pos, def) { |
||
| 277 | for (var valid = !1, tests = getTests(pos), tndx = 0; tndx < tests.length; tndx++) if (tests[tndx].match && tests[tndx].match.def == def) { |
||
| 278 | valid = !0; |
||
| 279 | break; |
||
| 280 | } |
||
| 281 | return valid; |
||
| 282 | } |
||
| 283 | function getTests(pos, ndxIntlzr, tstPs) { |
||
| 284 | function ResolveTestFromToken(maskToken, ndxInitializer, loopNdx, quantifierRecurse) { |
||
| 285 | function handleMatch(match, loopNdx, quantifierRecurse) { |
||
| 286 | 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), |
||
| 287 | !0; |
||
| 288 | if (testPos == pos && void 0 == match.matches) return matches.push({ |
||
| 289 | match: match, |
||
| 290 | locator: loopNdx.reverse() |
||
| 291 | }), !0; |
||
| 292 | if (void 0 != match.matches) { |
||
| 293 | if (match.isGroup && quantifierRecurse !== !0) { |
||
| 294 | if (match = handleMatch(maskToken.matches[tndx + 1], loopNdx)) return !0; |
||
| 295 | } else if (match.isOptional) { |
||
| 296 | var optionalToken = match; |
||
| 297 | if (match = ResolveTestFromToken(match, ndxInitializer, loopNdx, quantifierRecurse)) { |
||
| 298 | var latestMatch = matches[matches.length - 1].match, isFirstMatch = 0 == $.inArray(latestMatch, optionalToken.matches); |
||
| 299 | isFirstMatch && (insertStop = !0), testPos = pos; |
||
| 300 | } |
||
| 301 | } else if (match.isAlternator) { |
||
| 302 | var maltMatches, alternateToken = match, malternateMatches = [], currentMatches = matches.slice(), loopNdxCnt = loopNdx.length, altIndex = ndxInitializer.length > 0 ? ndxInitializer.shift() : -1; |
||
| 303 | if (-1 == altIndex || "string" == typeof altIndex) { |
||
| 304 | var altIndexArr, currentPos = testPos, ndxInitializerClone = ndxInitializer.slice(); |
||
| 305 | "string" == typeof altIndex && (altIndexArr = altIndex.split(",")); |
||
| 306 | for (var amndx = 0; amndx < alternateToken.matches.length; amndx++) { |
||
| 307 | matches = [], match = handleMatch(alternateToken.matches[amndx], [ amndx ].concat(loopNdx), quantifierRecurse) || match, |
||
| 308 | maltMatches = matches.slice(), testPos = currentPos, matches = []; |
||
| 309 | for (var i = 0; i < ndxInitializerClone.length; i++) ndxInitializer[i] = ndxInitializerClone[i]; |
||
| 310 | for (var ndx1 = 0; ndx1 < maltMatches.length; ndx1++) for (var altMatch = maltMatches[ndx1], ndx2 = 0; ndx2 < malternateMatches.length; ndx2++) { |
||
| 311 | var altMatch2 = malternateMatches[ndx2]; |
||
| 312 | if (altMatch.match.mask == altMatch2.match.mask && ("string" != typeof altIndex || -1 != $.inArray(altMatch.locator[loopNdxCnt].toString(), altIndexArr))) { |
||
| 313 | maltMatches.splice(ndx1, 1), altMatch2.locator[loopNdxCnt] = altMatch2.locator[loopNdxCnt] + "," + altMatch.locator[loopNdxCnt], |
||
| 314 | altMatch2.alternation = loopNdxCnt; |
||
| 315 | break; |
||
| 316 | } |
||
| 317 | } |
||
| 318 | malternateMatches = malternateMatches.concat(maltMatches); |
||
| 319 | } |
||
| 320 | "string" == typeof altIndex && (malternateMatches = $.map(malternateMatches, function(lmnt, ndx) { |
||
| 321 | if (isFinite(ndx)) { |
||
| 322 | var mamatch, altLocArr = lmnt.locator[loopNdxCnt].toString().split(","); |
||
| 323 | lmnt.locator[loopNdxCnt] = void 0, lmnt.alternation = void 0; |
||
| 324 | for (var alndx = 0; alndx < altLocArr.length; alndx++) mamatch = -1 != $.inArray(altLocArr[alndx], altIndexArr), |
||
| 325 | mamatch && (void 0 != lmnt.locator[loopNdxCnt] ? (lmnt.locator[loopNdxCnt] += ",", |
||
| 326 | lmnt.alternation = loopNdxCnt, lmnt.locator[loopNdxCnt] += altLocArr[alndx]) : lmnt.locator[loopNdxCnt] = parseInt(altLocArr[alndx])); |
||
| 327 | if (void 0 != lmnt.locator[loopNdxCnt]) return lmnt; |
||
| 328 | } |
||
| 329 | })), matches = currentMatches.concat(malternateMatches), insertStop = !0; |
||
| 330 | } else match = handleMatch(alternateToken.matches[altIndex], [ altIndex ].concat(loopNdx), quantifierRecurse); |
||
| 331 | if (match) return !0; |
||
| 332 | } else if (match.isQuantifier && quantifierRecurse !== !0) { |
||
| 333 | var qt = match; |
||
| 334 | opts.greedy = opts.greedy && isFinite(qt.quantifier.max); |
||
| 335 | for (var qndx = ndxInitializer.length > 0 && quantifierRecurse !== !0 ? ndxInitializer.shift() : 0; qndx < (isNaN(qt.quantifier.max) ? qndx + 1 : qt.quantifier.max) && pos >= testPos; qndx++) { |
||
| 336 | var tokenGroup = maskToken.matches[$.inArray(qt, maskToken.matches) - 1]; |
||
| 337 | if (match = handleMatch(tokenGroup, [ qndx ].concat(loopNdx), !0)) { |
||
| 338 | var latestMatch = matches[matches.length - 1].match; |
||
| 339 | latestMatch.optionalQuantifier = qndx > qt.quantifier.min - 1; |
||
| 340 | var isFirstMatch = 0 == $.inArray(latestMatch, tokenGroup.matches); |
||
| 341 | if (isFirstMatch) { |
||
| 342 | if (qndx > qt.quantifier.min - 1) { |
||
| 343 | insertStop = !0, testPos = pos; |
||
| 344 | break; |
||
| 345 | } |
||
| 346 | return !0; |
||
| 347 | } |
||
| 348 | return !0; |
||
| 349 | } |
||
| 350 | } |
||
| 351 | } else if (match = ResolveTestFromToken(match, ndxInitializer, loopNdx, quantifierRecurse)) return !0; |
||
| 352 | } else testPos++; |
||
| 353 | } |
||
| 354 | for (var tndx = ndxInitializer.length > 0 ? ndxInitializer.shift() : 0; tndx < maskToken.matches.length; tndx++) if (maskToken.matches[tndx].isQuantifier !== !0) { |
||
| 355 | var match = handleMatch(maskToken.matches[tndx], [ tndx ].concat(loopNdx), quantifierRecurse); |
||
| 356 | if (match && testPos == pos) return match; |
||
| 357 | if (testPos > pos) break; |
||
| 358 | } |
||
| 359 | } |
||
| 360 | var maskTokens = getMaskSet().maskToken, testPos = ndxIntlzr ? tstPs : 0, ndxInitializer = ndxIntlzr || [ 0 ], matches = [], insertStop = !1; |
||
| 361 | if (void 0 == ndxIntlzr) { |
||
| 362 | for (var test, previousPos = pos - 1; void 0 == (test = getMaskSet().validPositions[previousPos]) && previousPos > -1; ) previousPos--; |
||
| 363 | if (void 0 != test && previousPos > -1) testPos = previousPos, ndxInitializer = test.locator.slice(); else { |
||
| 364 | for (previousPos = pos - 1; void 0 == (test = getMaskSet().tests[previousPos]) && previousPos > -1; ) previousPos--; |
||
| 365 | void 0 != test && previousPos > -1 && (testPos = previousPos, ndxInitializer = test[0].locator.slice()); |
||
| 366 | } |
||
| 367 | } |
||
| 368 | for (var mtndx = ndxInitializer.shift(); mtndx < maskTokens.length; mtndx++) { |
||
| 369 | var match = ResolveTestFromToken(maskTokens[mtndx], ndxInitializer, [ mtndx ]); |
||
| 370 | if (match && testPos == pos || testPos > pos) break; |
||
| 371 | } |
||
| 372 | return (0 == matches.length || insertStop) && matches.push({ |
||
| 373 | match: { |
||
| 374 | fn: null, |
||
| 375 | cardinality: 0, |
||
| 376 | optionality: !0, |
||
| 377 | casing: null, |
||
| 378 | def: "" |
||
| 379 | }, |
||
| 380 | locator: [] |
||
| 381 | }), getMaskSet().tests[pos] = $.extend(!0, [], matches), getMaskSet().tests[pos]; |
||
| 382 | } |
||
| 383 | function getBufferTemplate() { |
||
| 384 | return void 0 == getMaskSet()._buffer && (getMaskSet()._buffer = getMaskTemplate(!1, 1)), |
||
| 385 | getMaskSet()._buffer; |
||
| 386 | } |
||
| 387 | function getBuffer() { |
||
| 388 | return void 0 == getMaskSet().buffer && (getMaskSet().buffer = getMaskTemplate(!0, getLastValidPosition(), !0)), |
||
| 389 | getMaskSet().buffer; |
||
| 390 | } |
||
| 391 | function refreshFromBuffer(start, end) { |
||
| 392 | var buffer = getBuffer().slice(); |
||
| 393 | if (start === !0) resetMaskSet(), start = 0, end = buffer.length; else for (var i = start; end > i; i++) delete getMaskSet().validPositions[i], |
||
| 394 | delete getMaskSet().tests[i]; |
||
| 395 | for (var i = start; end > i; i++) buffer[i] != opts.skipOptionalPartCharacter && isValid(i, buffer[i], !0, !0); |
||
| 396 | } |
||
| 397 | function casing(elem, test) { |
||
| 398 | switch (test.casing) { |
||
| 399 | case "upper": |
||
| 400 | elem = elem.toUpperCase(); |
||
| 401 | break; |
||
| 402 | |||
| 403 | case "lower": |
||
| 404 | elem = elem.toLowerCase(); |
||
| 405 | } |
||
| 406 | return elem; |
||
| 407 | } |
||
| 408 | function isValid(pos, c, strict, fromSetValid) { |
||
| 409 | function _isValid(position, c, strict, fromSetValid) { |
||
| 410 | var rslt = !1; |
||
| 411 | return $.each(getTests(position), function(ndx, tst) { |
||
| 412 | for (var test = tst.match, loopend = c ? 1 : 0, chrs = "", i = (getBuffer(), test.cardinality); i > loopend; i--) chrs += getBufferElement(position - (i - 1)); |
||
| 413 | 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 : { |
||
| 414 | c: test.def, |
||
| 415 | pos: position |
||
| 416 | }, rslt !== !1) { |
||
| 417 | var elem = void 0 != rslt.c ? rslt.c : c; |
||
| 418 | elem = elem == opts.skipOptionalPartCharacter && null === test.fn ? test.def : elem; |
||
| 419 | var validatedPos = position; |
||
| 420 | if (void 0 != rslt.remove && stripValidPositions(rslt.remove, rslt.remove + 1), |
||
| 421 | rslt.refreshFromBuffer) { |
||
| 422 | var refresh = rslt.refreshFromBuffer; |
||
| 423 | if (strict = !0, refreshFromBuffer(refresh === !0 ? refresh : refresh.start, refresh.end), |
||
| 424 | void 0 == rslt.pos && void 0 == rslt.c) return rslt.pos = getLastValidPosition(), |
||
| 425 | !1; |
||
| 426 | if (validatedPos = void 0 != rslt.pos ? rslt.pos : position, validatedPos != position) return rslt = $.extend(rslt, isValid(validatedPos, elem, !0)), |
||
| 427 | !1; |
||
| 428 | } else if (rslt !== !0 && void 0 != rslt.pos && rslt.pos != position && (validatedPos = rslt.pos, |
||
| 429 | refreshFromBuffer(position, validatedPos), validatedPos != position)) return rslt = $.extend(rslt, isValid(validatedPos, elem, !0)), |
||
| 430 | !1; |
||
| 431 | return 1 != rslt && void 0 == rslt.pos && void 0 == rslt.c ? !1 : (ndx > 0 && resetMaskSet(!0), |
||
| 432 | setValidPosition(validatedPos, $.extend({}, tst, { |
||
| 433 | input: casing(elem, test) |
||
| 434 | }), fromSetValid) || (rslt = !1), !1); |
||
| 435 | } |
||
| 436 | }), rslt; |
||
| 437 | } |
||
| 438 | function alternate(pos, c, strict, fromSetValid) { |
||
| 439 | var lastAlt, alternation, validPsClone = $.extend(!0, {}, getMaskSet().validPositions); |
||
| 440 | for (lastAlt = getLastValidPosition(); lastAlt >= 0; lastAlt--) if (getMaskSet().validPositions[lastAlt] && void 0 != getMaskSet().validPositions[lastAlt].alternation) { |
||
| 441 | alternation = getMaskSet().validPositions[lastAlt].alternation; |
||
| 442 | break; |
||
| 443 | } |
||
| 444 | if (void 0 != alternation) for (var decisionPos in getMaskSet().validPositions) if (parseInt(decisionPos) > parseInt(lastAlt) && void 0 === getMaskSet().validPositions[decisionPos].alternation) { |
||
| 445 | 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]) { |
||
| 446 | for (var possibilityPos, possibilities, dp = decisionPos - 1; dp >= 0; dp--) if (possibilityPos = getMaskSet().validPositions[dp], |
||
| 447 | void 0 != possibilityPos) { |
||
| 448 | possibilities = possibilityPos.locator[alternation], possibilityPos.locator[alternation] = altNdxs[mndx]; |
||
| 449 | break; |
||
| 450 | } |
||
| 451 | if (decisionTaker != possibilityPos.locator[alternation]) { |
||
| 452 | for (var buffer = getBuffer().slice(), i = decisionPos; i < getLastValidPosition() + 1; i++) delete getMaskSet().validPositions[i], |
||
| 453 | delete getMaskSet().tests[i]; |
||
| 454 | resetMaskSet(!0), opts.keepStatic = !opts.keepStatic; |
||
| 455 | for (var i = decisionPos; i < buffer.length; i++) buffer[i] != opts.skipOptionalPartCharacter && isValid(getLastValidPosition() + 1, buffer[i], !1, !0); |
||
| 456 | possibilityPos.locator[alternation] = possibilities; |
||
| 457 | var isValidRslt = isValid(pos, c, strict, fromSetValid); |
||
| 458 | if (opts.keepStatic = !opts.keepStatic, isValidRslt) return isValidRslt; |
||
| 459 | resetMaskSet(), getMaskSet().validPositions = $.extend(!0, {}, validPsClone); |
||
| 460 | } |
||
| 461 | } |
||
| 462 | break; |
||
| 463 | } |
||
| 464 | return !1; |
||
| 465 | } |
||
| 466 | function trackbackAlternations(originalPos, newPos) { |
||
| 467 | for (var vp = getMaskSet().validPositions[newPos], targetLocator = vp.locator, tll = targetLocator.length, ps = originalPos; newPos > ps; ps++) if (!isMask(ps)) { |
||
| 468 | var bestMatch, tests = getTests(ps), equality = -1; |
||
| 469 | for (var tndx in tests) for (var activeTest = tests[tndx], i = 0; tll > i; i++) targetLocator[i] == activeTest.locator[i] && i > equality && (equality = i, |
||
| 470 | bestMatch = activeTest); |
||
| 471 | setValidPosition(ps, $.extend({}, bestMatch, { |
||
| 472 | input: bestMatch.match.def |
||
| 473 | }), !0); |
||
| 474 | } |
||
| 475 | } |
||
| 476 | strict = strict === !0; |
||
| 477 | 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); |
||
| 478 | var maskPos = pos, result = !1; |
||
| 479 | if (fromSetValid && maskPos >= getMaskLength() && resetMaskSet(!0), maskPos < getMaskLength() && (result = _isValid(maskPos, c, strict, fromSetValid), |
||
| 480 | !strict && result === !1)) { |
||
| 481 | var currentPosValid = getMaskSet().validPositions[maskPos]; |
||
| 482 | if (!currentPosValid || null != currentPosValid.match.fn || currentPosValid.match.def != c && c != opts.skipOptionalPartCharacter) { |
||
| 483 | 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), |
||
| 484 | result !== !1) { |
||
| 485 | trackbackAlternations(maskPos, nPos), maskPos = nPos; |
||
| 486 | break; |
||
| 487 | } |
||
| 488 | } else result = { |
||
| 489 | caret: seekNext(maskPos) |
||
| 490 | }; |
||
| 491 | } |
||
| 492 | return result === !1 && opts.keepStatic && isComplete(buffer) && (result = alternate(pos, c, strict, fromSetValid)), |
||
| 493 | result === !0 && (result = { |
||
| 494 | pos: maskPos |
||
| 495 | }), result; |
||
| 496 | } |
||
| 497 | function isMask(pos) { |
||
| 498 | var test = getTest(pos); |
||
| 499 | return null != test.fn ? test.fn : !1; |
||
| 500 | } |
||
| 501 | function getMaskLength() { |
||
| 502 | var maskLength; |
||
| 503 | if (maxLength = $el.prop("maxLength"), -1 == maxLength && (maxLength = void 0), |
||
| 504 | |||
| 505 | var pos, lvp = getLastValidPosition(), testPos = getMaskSet().validPositions[lvp], ndxIntlzr = void 0 != testPos ? testPos.locator.slice() : void 0; |
||
| 506 | 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), |
||
| 507 | ndxIntlzr = testPos.locator.slice(); |
||
| 508 | maskLength = pos; |
||
| 509 | } else maskLength = getBuffer().length; |
||
| 510 | return void 0 == maxLength || maxLength > maskLength ? maskLength : maxLength; |
||
| 511 | } |
||
| 512 | function seekNext(pos) { |
||
| 513 | var maskL = getMaskLength(); |
||
| 514 | if (pos >= maskL) return maskL; |
||
| 515 | for (var position = pos; ++position < maskL && !isMask(position) && (opts.nojumps !== !0 || opts.nojumpsThreshold > position); ) ; |
||
| 516 | return position; |
||
| 517 | } |
||
| 518 | function seekPrevious(pos) { |
||
| 519 | var position = pos; |
||
| 520 | if (0 >= position) return 0; |
||
| 521 | for (;--position > 0 && !isMask(position); ) ; |
||
| 522 | return position; |
||
| 523 | } |
||
| 524 | function getBufferElement(position) { |
||
| 525 | return void 0 == getMaskSet().validPositions[position] ? getPlaceholder(position) : getMaskSet().validPositions[position].input; |
||
| 526 | } |
||
| 527 | function writeBuffer(input, buffer, caretPos) { |
||
| 528 | input._valueSet(buffer.join("")), void 0 != caretPos && caret(input, caretPos); |
||
| 529 | } |
||
| 530 | function getPlaceholder(pos, test) { |
||
| 531 | test = test || getTest(pos); |
||
| 532 | var placeholder = $.isFunction(test.placeholder) ? test.placeholder.call(this, opts) : test.placeholder; |
||
| 533 | return void 0 != placeholder ? placeholder : null == test.fn ? test.def : opts.placeholder.charAt(pos % opts.placeholder.length); |
||
| 534 | } |
||
| 535 | function checkVal(input, writeOut, strict, nptvl) { |
||
| 536 | var inputValue = void 0 != nptvl ? nptvl.slice() : input._valueGet().split(""); |
||
| 537 | resetMaskSet(), writeOut && input._valueSet(""); |
||
| 538 | var staticInput = getBufferTemplate().slice(0, seekNext(-1)).join(""), matches = inputValue.join("").match(new RegExp(escapeRegex(staticInput), "g")); |
||
| 539 | if (matches && matches.length > 1 && inputValue.splice(0, staticInput.length), $.each(inputValue, function(ndx, charCode) { |
||
| 540 | var lvp = getLastValidPosition(); |
||
| 541 | -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), |
||
| 542 | strict = strict || ndx > 0 && ndx > getMaskSet().p) : keypressEvent.call(input, void 0, !0, charCode.charCodeAt(0), !1, !0, lvp + 1); |
||
| 543 | }), writeOut) { |
||
| 544 | var keypressResult = opts.onKeyPress.call(this, void 0, getBuffer(), 0, opts); |
||
| 545 | handleOnKeyResult(input, keypressResult), writeBuffer(input, getBuffer(), $(input).is(":focus") ? seekNext(getLastValidPosition(0)) : void 0); |
||
| 546 | } |
||
| 547 | } |
||
| 548 | function escapeRegex(str) { |
||
| 549 | return $.inputmask.escapeRegex.call(this, str); |
||
| 550 | } |
||
| 551 | function unmaskedvalue($input) { |
||
| 552 | if ($input.data("_inputmask") && !$input.hasClass("hasDatepicker")) { |
||
| 553 | var umValue = [], vps = getMaskSet().validPositions; |
||
| 554 | for (var pndx in vps) vps[pndx].match && null != vps[pndx].match.fn && umValue.push(vps[pndx].input); |
||
| 555 | var unmaskedValue = (isRTL ? umValue.reverse() : umValue).join(""), bufferValue = (isRTL ? getBuffer().slice().reverse() : getBuffer()).join(""); |
||
| 556 | return $.isFunction(opts.onUnMask) && (unmaskedValue = opts.onUnMask.call($input, bufferValue, unmaskedValue, opts) || unmaskedValue), |
||
| 557 | unmaskedValue; |
||
| 558 | } |
||
| 559 | return $input[0]._valueGet(); |
||
| 560 | } |
||
| 561 | function TranslatePosition(pos) { |
||
| 562 | if (isRTL && "number" == typeof pos && (!opts.greedy || "" != opts.placeholder)) { |
||
| 563 | var bffrLght = getBuffer().length; |
||
| 564 | pos = bffrLght - pos; |
||
| 565 | } |
||
| 566 | return pos; |
||
| 567 | } |
||
| 568 | function caret(input, begin, end) { |
||
| 569 | var range, npt = input.jquery && input.length > 0 ? input[0] : input; |
||
| 570 | if ("number" != typeof begin) { |
||
| 571 | var data = $(npt).data("_inputmask"); |
||
| 572 | return !$(npt).is(":visible") && data && void 0 != data.caret ? (begin = data.caret.begin, |
||
| 573 | end = data.caret.end) : npt.setSelectionRange ? (begin = npt.selectionStart, end = npt.selectionEnd) : document.selection && document.selection.createRange && (range = document.selection.createRange(), |
||
| 574 | begin = 0 - range.duplicate().moveStart("character", -1e5), end = begin + range.text.length), |
||
| 575 | begin = TranslatePosition(begin), end = TranslatePosition(end), { |
||
| 576 | begin: begin, |
||
| 577 | end: end |
||
| 578 | }; |
||
| 579 | } |
||
| 580 | begin = TranslatePosition(begin), end = TranslatePosition(end), end = "number" == typeof end ? end : begin; |
||
| 581 | var data = $(npt).data("_inputmask") || {}; |
||
| 582 | data.caret = { |
||
| 583 | begin: begin, |
||
| 584 | end: end |
||
| 585 | }, $(npt).data("_inputmask", data), $(npt).is(":visible") && (npt.scrollLeft = npt.scrollWidth, |
||
| 586 | |||
| 587 | npt.selectionEnd = end) : npt.createTextRange && (range = npt.createTextRange(), |
||
| 588 | range.collapse(!0), range.moveEnd("character", end), range.moveStart("character", begin), |
||
| 589 | range.select())); |
||
| 590 | } |
||
| 591 | function determineLastRequiredPosition(returnDefinition) { |
||
| 592 | var pos, testPos, buffer = getBuffer(), bl = buffer.length, lvp = getLastValidPosition(), positions = {}, lvTest = getMaskSet().validPositions[lvp], ndxIntlzr = void 0 != lvTest ? lvTest.locator.slice() : void 0; |
||
| 593 | for (pos = lvp + 1; pos < buffer.length; pos++) testPos = getTestTemplate(pos, ndxIntlzr, pos - 1), |
||
| 594 | ndxIntlzr = testPos.locator.slice(), positions[pos] = $.extend(!0, {}, testPos); |
||
| 595 | var lvTestAltArr = lvTest && void 0 != lvTest.alternation ? lvTest.locator[lvTest.alternation].split(",") : []; |
||
| 596 | 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--; |
||
| 597 | return returnDefinition ? { |
||
| 598 | l: bl, |
||
| 599 | def: positions[bl] ? positions[bl].match : void 0 |
||
| 600 | } : bl; |
||
| 601 | } |
||
| 602 | function clearOptionalTail(input) { |
||
| 603 | var buffer = getBuffer(), tmpBuffer = buffer.slice(); |
||
| 604 | if ($.isFunction(opts.postProcessOnBlur)) opts.postProcessOnBlur.call(input, tmpBuffer, opts); else { |
||
| 605 | for (var rl = determineLastRequiredPosition(), lmib = tmpBuffer.length - 1; lmib > rl && !isMask(lmib); lmib--) ; |
||
| 606 | tmpBuffer.splice(rl, lmib + 1 - rl); |
||
| 607 | } |
||
| 608 | writeBuffer(input, tmpBuffer); |
||
| 609 | } |
||
| 610 | function isComplete(buffer) { |
||
| 611 | if ($.isFunction(opts.isComplete)) return opts.isComplete.call($el, buffer, opts); |
||
| 612 | if ("*" == opts.repeat) return void 0; |
||
| 613 | var complete = !1, lrp = determineLastRequiredPosition(!0), aml = seekPrevious(lrp.l), lvp = getLastValidPosition(); |
||
| 614 | if (lvp == aml && (void 0 == lrp.def || lrp.def.newBlockMarker || lrp.def.optionalQuantifier)) { |
||
| 615 | complete = !0; |
||
| 616 | for (var i = 0; aml >= i; i++) { |
||
| 617 | var mask = isMask(i); |
||
| 618 | if (mask && (void 0 == buffer[i] || buffer[i] == getPlaceholder(i)) || !mask && buffer[i] != getPlaceholder(i)) { |
||
| 619 | complete = !1; |
||
| 620 | break; |
||
| 621 | } |
||
| 622 | } |
||
| 623 | } |
||
| 624 | return complete; |
||
| 625 | } |
||
| 626 | function isSelection(begin, end) { |
||
| 627 | return isRTL ? begin - end > 1 || begin - end == 1 && opts.insertMode : end - begin > 1 || end - begin == 1 && opts.insertMode; |
||
| 628 | } |
||
| 629 | function installEventRuler(npt) { |
||
| 630 | var events = $._data(npt).events; |
||
| 631 | $.each(events, function(eventType, eventHandlers) { |
||
| 632 | $.each(eventHandlers, function(ndx, eventHandler) { |
||
| 633 | if ("inputmask" == eventHandler.namespace && "setvalue" != eventHandler.type) { |
||
| 634 | var handler = eventHandler.handler; |
||
| 635 | eventHandler.handler = function(e) { |
||
| 636 | return this.readOnly || this.disabled ? void e.preventDefault : handler.apply(this, arguments); |
||
| 637 | }; |
||
| 638 | } |
||
| 639 | }); |
||
| 640 | }); |
||
| 641 | } |
||
| 642 | function patchValueProperty(npt) { |
||
| 643 | function PatchValhook(type) { |
||
| 644 | if (void 0 == $.valHooks[type] || 1 != $.valHooks[type].inputmaskpatch) { |
||
| 645 | var valueGet = $.valHooks[type] && $.valHooks[type].get ? $.valHooks[type].get : function(elem) { |
||
| 646 | return elem.value; |
||
| 647 | }, valueSet = $.valHooks[type] && $.valHooks[type].set ? $.valHooks[type].set : function(elem, value) { |
||
| 648 | return elem.value = value, elem; |
||
| 649 | }; |
||
| 650 | $.valHooks[type] = { |
||
| 651 | get: function(elem) { |
||
| 652 | var $elem = $(elem); |
||
| 653 | if ($elem.data("_inputmask")) { |
||
| 654 | if ($elem.data("_inputmask").opts.autoUnmask) return $elem.inputmask("unmaskedvalue"); |
||
| 655 | var result = valueGet(elem), inputData = $elem.data("_inputmask"), maskset = inputData.maskset, bufferTemplate = maskset._buffer; |
||
| 656 | return bufferTemplate = bufferTemplate ? bufferTemplate.join("") : "", result != bufferTemplate ? result : ""; |
||
| 657 | } |
||
| 658 | return valueGet(elem); |
||
| 659 | }, |
||
| 660 | set: function(elem, value) { |
||
| 661 | var result, $elem = $(elem), inputData = $elem.data("_inputmask"); |
||
| 662 | return inputData ? (result = valueSet(elem, $.isFunction(inputData.opts.onBeforeMask) ? inputData.opts.onBeforeMask.call(el, value, inputData.opts) || value : value), |
||
| 663 | $elem.triggerHandler("setvalue.inputmask")) : result = valueSet(elem, value), result; |
||
| 664 | }, |
||
| 665 | inputmaskpatch: !0 |
||
| 666 | }; |
||
| 667 | } |
||
| 668 | } |
||
| 669 | function getter() { |
||
| 670 | var $self = $(this), inputData = $(this).data("_inputmask"); |
||
| 671 | return inputData ? inputData.opts.autoUnmask ? $self.inputmask("unmaskedvalue") : valueGet.call(this) != getBufferTemplate().join("") ? valueGet.call(this) : "" : valueGet.call(this); |
||
| 672 | } |
||
| 673 | function setter(value) { |
||
| 674 | var inputData = $(this).data("_inputmask"); |
||
| 675 | inputData ? (valueSet.call(this, $.isFunction(inputData.opts.onBeforeMask) ? inputData.opts.onBeforeMask.call(el, value, inputData.opts) || value : value), |
||
| 676 | $(this).triggerHandler("setvalue.inputmask")) : valueSet.call(this, value); |
||
| 677 | } |
||
| 678 | function InstallNativeValueSetFallback(npt) { |
||
| 679 | $(npt).bind("mouseenter.inputmask", function() { |
||
| 680 | var $input = $(this), input = this, value = input._valueGet(); |
||
| 681 | "" != value && value != getBuffer().join("") && (valueSet.call(this, $.isFunction(opts.onBeforeMask) ? opts.onBeforeMask.call(el, value, opts) || value : value), |
||
| 682 | $input.trigger("setvalue")); |
||
| 683 | }); |
||
| 684 | //!! the bound handlers are executed in the order they where bound |
||
| 685 | var events = $._data(npt).events, handlers = events.mouseover; |
||
| 686 | if (handlers) { |
||
| 687 | for (var ourHandler = handlers[handlers.length - 1], i = handlers.length - 1; i > 0; i--) handlers[i] = handlers[i - 1]; |
||
| 688 | handlers[0] = ourHandler; |
||
| 689 | } |
||
| 690 | } |
||
| 691 | var valueGet, valueSet; |
||
| 692 | if (!npt._valueGet) { |
||
| 693 | if (Object.getOwnPropertyDescriptor) { |
||
| 694 | Object.getOwnPropertyDescriptor(npt, "value"); |
||
| 695 | } |
||
| 696 | document.__lookupGetter__ && npt.__lookupGetter__("value") ? (valueGet = npt.__lookupGetter__("value"), |
||
| 697 | valueSet = npt.__lookupSetter__("value"), npt.__defineGetter__("value", getter), |
||
| 698 | npt.__defineSetter__("value", setter)) : (valueGet = function() { |
||
| 699 | return npt.value; |
||
| 700 | }, valueSet = function(value) { |
||
| 701 | npt.value = value; |
||
| 702 | }, PatchValhook(npt.type), InstallNativeValueSetFallback(npt)), npt._valueGet = function() { |
||
| 703 | return isRTL ? valueGet.call(this).split("").reverse().join("") : valueGet.call(this); |
||
| 704 | }, npt._valueSet = function(value) { |
||
| 705 | valueSet.call(this, isRTL ? value.split("").reverse().join("") : value); |
||
| 706 | }; |
||
| 707 | } |
||
| 708 | } |
||
| 709 | function handleRemove(input, k, pos) { |
||
| 710 | function generalize() { |
||
| 711 | if (opts.keepStatic) { |
||
| 712 | resetMaskSet(!0); |
||
| 713 | var lastAlt, validInputs = []; |
||
| 714 | for (lastAlt = getLastValidPosition(); lastAlt >= 0; lastAlt--) if (getMaskSet().validPositions[lastAlt]) { |
||
| 715 | if (void 0 != getMaskSet().validPositions[lastAlt].alternation) break; |
||
| 716 | validInputs.push(getMaskSet().validPositions[lastAlt].input), delete getMaskSet().validPositions[lastAlt]; |
||
| 717 | } |
||
| 718 | if (lastAlt > 0) for (;validInputs.length > 0; ) getMaskSet().p = seekNext(getLastValidPosition()), |
||
| 719 | keypressEvent.call(input, void 0, !0, validInputs.pop().charCodeAt(0), !1, !1, getMaskSet().p); |
||
| 720 | } |
||
| 721 | } |
||
| 722 | if ((opts.numericInput || isRTL) && (k == $.inputmask.keyCode.BACKSPACE ? k = $.inputmask.keyCode.DELETE : k == $.inputmask.keyCode.DELETE && (k = $.inputmask.keyCode.BACKSPACE), |
||
| 723 | isRTL)) { |
||
| 724 | var pend = pos.end; |
||
| 725 | pos.end = pos.begin, pos.begin = pend; |
||
| 726 | } |
||
| 727 | k == $.inputmask.keyCode.BACKSPACE && pos.end - pos.begin <= 1 ? pos.begin = seekPrevious(pos.begin) : k == $.inputmask.keyCode.DELETE && pos.begin == pos.end && pos.end++, |
||
| 728 | stripValidPositions(pos.begin, pos.end), generalize(); |
||
| 729 | var firstMaskedPos = getLastValidPosition(pos.begin); |
||
| 730 | firstMaskedPos < pos.begin ? (-1 == firstMaskedPos && resetMaskSet(), getMaskSet().p = seekNext(firstMaskedPos)) : getMaskSet().p = pos.begin; |
||
| 731 | } |
||
| 732 | function handleOnKeyResult(input, keyResult, caretPos) { |
||
| 733 | if (keyResult && keyResult.refreshFromBuffer) { |
||
| 734 | var refresh = keyResult.refreshFromBuffer; |
||
| 735 | refreshFromBuffer(refresh === !0 ? refresh : refresh.start, refresh.end), resetMaskSet(!0), |
||
| 736 | void 0 != caretPos && (writeBuffer(input, getBuffer()), caret(input, keyResult.caret || caretPos.begin, keyResult.caret || caretPos.end)); |
||
| 737 | } |
||
| 738 | } |
||
| 739 | function keydownEvent(e) { |
||
| 740 | skipKeyPressEvent = !1; |
||
| 741 | var input = this, $input = $(input), k = e.keyCode, pos = caret(input); |
||
| 742 | k == $.inputmask.keyCode.BACKSPACE || k == $.inputmask.keyCode.DELETE || iphone && 127 == k || e.ctrlKey && 88 == k && !isInputEventSupported("cut") ? (e.preventDefault(), |
||
| 743 | 88 == k && (valueOnFocus = getBuffer().join("")), handleRemove(input, k, pos), writeBuffer(input, getBuffer(), getMaskSet().p), |
||
| 744 | input._valueGet() == getBufferTemplate().join("") && $input.trigger("cleared"), |
||
| 745 | opts.showTooltip && $input.prop("title", getMaskSet().mask)) : k == $.inputmask.keyCode.END || k == $.inputmask.keyCode.PAGE_DOWN ? setTimeout(function() { |
||
| 746 | var caretPos = seekNext(getLastValidPosition()); |
||
| 747 | opts.insertMode || caretPos != getMaskLength() || e.shiftKey || caretPos--, caret(input, e.shiftKey ? pos.begin : caretPos, caretPos); |
||
| 748 | }, 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("")), |
||
| 749 | $input.click()) : k != $.inputmask.keyCode.INSERT || e.shiftKey || e.ctrlKey ? 0 != opts.insertMode || e.shiftKey || (k == $.inputmask.keyCode.RIGHT ? setTimeout(function() { |
||
| 750 | var caretPos = caret(input); |
||
| 751 | caret(input, caretPos.begin); |
||
| 752 | }, 0) : k == $.inputmask.keyCode.LEFT && setTimeout(function() { |
||
| 753 | var caretPos = caret(input); |
||
| 754 | caret(input, isRTL ? caretPos.begin + 1 : caretPos.begin - 1); |
||
| 755 | }, 0)) : (opts.insertMode = !opts.insertMode, caret(input, opts.insertMode || pos.begin != getMaskLength() ? pos.begin : pos.begin - 1)); |
||
| 756 | var currentCaretPos = caret(input), keydownResult = opts.onKeyDown.call(this, e, getBuffer(), currentCaretPos.begin, opts); |
||
| 757 | handleOnKeyResult(input, keydownResult, currentCaretPos), ignorable = -1 != $.inArray(k, opts.ignorables); |
||
| 758 | } |
||
| 759 | function keypressEvent(e, checkval, k, writeOut, strict, ndx) { |
||
| 760 | if (void 0 == k && skipKeyPressEvent) return !1; |
||
| 761 | skipKeyPressEvent = !0; |
||
| 762 | var input = this, $input = $(input); |
||
| 763 | e = e || window.event; |
||
| 764 | var k = checkval ? k : e.which || e.charCode || e.keyCode; |
||
| 765 | if (!(checkval === !0 || e.ctrlKey && e.altKey) && (e.ctrlKey || e.metaKey || ignorable)) return !0; |
||
| 766 | if (k) { |
||
| 767 | checkval !== !0 && 46 == k && 0 == e.shiftKey && "," == opts.radixPoint && (k = 44); |
||
| 768 | var forwardPosition, pos = checkval ? { |
||
| 769 | begin: ndx, |
||
| 770 | end: ndx |
||
| 771 | } : caret(input), c = String.fromCharCode(k), isSlctn = isSelection(pos.begin, pos.end); |
||
| 772 | isSlctn && (getMaskSet().undoPositions = $.extend(!0, {}, getMaskSet().validPositions), |
||
| 773 | handleRemove(input, $.inputmask.keyCode.DELETE, pos), opts.insertMode || (opts.insertMode = !opts.insertMode, |
||
| 774 | setValidPosition(pos.begin, strict), opts.insertMode = !opts.insertMode), isSlctn = !opts.multi), |
||
| 775 | getMaskSet().writeOutBuffer = !0; |
||
| 776 | var p = isRTL && !isSlctn ? pos.end : pos.begin, valResult = isValid(p, c, strict); |
||
| 777 | if (valResult !== !1) { |
||
| 778 | if (valResult !== !0 && (p = void 0 != valResult.pos ? valResult.pos : p, c = void 0 != valResult.c ? valResult.c : c), |
||
| 779 | resetMaskSet(!0), void 0 != valResult.caret) forwardPosition = valResult.caret; else { |
||
| 780 | var vps = getMaskSet().validPositions; |
||
| 781 | 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); |
||
| 782 | } |
||
| 783 | getMaskSet().p = forwardPosition; |
||
| 784 | } |
||
| 785 | if (writeOut !== !1) { |
||
| 786 | var self = this; |
||
| 787 | if (setTimeout(function() { |
||
| 788 | opts.onKeyValidation.call(self, valResult, opts); |
||
| 789 | }, 0), getMaskSet().writeOutBuffer && valResult !== !1) { |
||
| 790 | var buffer = getBuffer(); |
||
| 791 | writeBuffer(input, buffer, checkval ? void 0 : opts.numericInput ? seekPrevious(forwardPosition) : forwardPosition), |
||
| 792 | checkval !== !0 && setTimeout(function() { |
||
| 793 | isComplete(buffer) === !0 && $input.trigger("complete"), skipInputEvent = !0, $input.trigger("input"); |
||
| 794 | }, 0); |
||
| 795 | } else isSlctn && (getMaskSet().buffer = void 0, getMaskSet().validPositions = getMaskSet().undoPositions); |
||
| 796 | } else isSlctn && (getMaskSet().buffer = void 0, getMaskSet().validPositions = getMaskSet().undoPositions); |
||
| 797 | if (opts.showTooltip && $input.prop("title", getMaskSet().mask), e && 1 != checkval) { |
||
| 798 | e.preventDefault(); |
||
| 799 | var currentCaretPos = caret(input), keypressResult = opts.onKeyPress.call(this, e, getBuffer(), currentCaretPos.begin, opts); |
||
| 800 | handleOnKeyResult(input, keypressResult, currentCaretPos); |
||
| 801 | } |
||
| 802 | } |
||
| 803 | } |
||
| 804 | function keyupEvent(e) { |
||
| 805 | var $input = $(this), input = this, k = e.keyCode, buffer = getBuffer(), currentCaretPos = caret(input), keyupResult = opts.onKeyUp.call(this, e, buffer, currentCaretPos.begin, opts); |
||
| 806 | handleOnKeyResult(input, keyupResult, currentCaretPos), k == $.inputmask.keyCode.TAB && opts.showMaskOnFocus && ($input.is(":focus") && 0 == input._valueGet().length ? (resetMaskSet(), |
||
| 807 | buffer = getBuffer(), writeBuffer(input, buffer), caret(input, 0), valueOnFocus = getBuffer().join("")) : (writeBuffer(input, buffer), |
||
| 808 | caret(input, TranslatePosition(0), TranslatePosition(getMaskLength())))); |
||
| 809 | } |
||
| 810 | function pasteEvent(e) { |
||
| 811 | if (skipInputEvent === !0 && "input" == e.type) return skipInputEvent = !1, !0; |
||
| 812 | var input = this, $input = $(input), inputValue = input._valueGet(), caretPos = caret(input); |
||
| 813 | if ("propertychange" == e.type && input._valueGet().length <= getMaskLength()) return !0; |
||
| 814 | "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))); |
||
| 815 | var pasteValue = $.isFunction(opts.onBeforePaste) ? opts.onBeforePaste.call(input, inputValue, opts) || inputValue : inputValue; |
||
| 816 | return checkVal(input, !0, !1, isRTL ? pasteValue.split("").reverse() : pasteValue.split("")), |
||
| 817 | $input.click(), isComplete(getBuffer()) === !0 && $input.trigger("complete"), !1; |
||
| 818 | } |
||
| 819 | function mobileInputEvent(e) { |
||
| 820 | if (skipInputEvent === !0 && "input" == e.type) return skipInputEvent = !1, !0; |
||
| 821 | var input = this, caretPos = caret(input), currentValue = input._valueGet(); |
||
| 822 | currentValue = currentValue.replace(new RegExp("(" + escapeRegex(getBufferTemplate().join("")) + ")*"), ""), |
||
| 823 | caretPos.begin > currentValue.length && (caret(input, currentValue.length), caretPos = caret(input)), |
||
| 824 | 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, |
||
| 825 | keydownEvent.call(input, e)), e.preventDefault(); |
||
| 826 | } |
||
| 827 | function inputFallBackEvent(e) { |
||
| 828 | if (skipInputEvent === !0 && "input" == e.type) return skipInputEvent = !1, !0; |
||
| 829 | var input = this; |
||
| 830 | checkVal(input, !1, !1); |
||
| 831 | var forwardPosition = getMaskSet().p; |
||
| 832 | writeBuffer(input, getBuffer(), opts.numericInput ? seekPrevious(forwardPosition) : forwardPosition), |
||
| 833 | isComplete(getBuffer()) === !0 && $(input).trigger("complete"), e.preventDefault(); |
||
| 834 | } |
||
| 835 | function compositionupdateEvent(e) { |
||
| 836 | skipInputEvent = !0; |
||
| 837 | var input = this; |
||
| 838 | return setTimeout(function() { |
||
| 839 | caret(input, caret(input).begin - 1); |
||
| 840 | var keypress = $.Event("keypress"); |
||
| 841 | keypress.which = e.originalEvent.data.charCodeAt(0), skipKeyPressEvent = !1, ignorable = !1, |
||
| 842 | keypressEvent.call(input, keypress, void 0, void 0, !1); |
||
| 843 | var forwardPosition = getMaskSet().p; |
||
| 844 | writeBuffer(input, getBuffer(), opts.numericInput ? seekPrevious(forwardPosition) : forwardPosition); |
||
| 845 | }, 0), !1; |
||
| 846 | } |
||
| 847 | function mask(el) { |
||
| 848 | if ($el = $(el), $el.is(":input") && isInputTypeSupported($el.attr("type"))) { |
||
| 849 | if ($el.data("_inputmask", { |
||
| 850 | maskset: maskset, |
||
| 851 | opts: opts, |
||
| 852 | isRTL: !1 |
||
| 853 | }), opts.showTooltip && $el.prop("title", getMaskSet().mask), ("rtl" == el.dir || opts.rightAlign) && $el.css("text-align", "right"), |
||
| 854 | "rtl" == el.dir || opts.numericInput) { |
||
| 855 | el.dir = "ltr", $el.removeAttr("dir"); |
||
| 856 | var inputData = $el.data("_inputmask"); |
||
| 857 | inputData.isRTL = !0, $el.data("_inputmask", inputData), isRTL = !0; |
||
| 858 | } |
||
| 859 | $el.unbind(".inputmask"), $el.closest("form").bind("submit", function() { |
||
| 860 | valueOnFocus != getBuffer().join("") && $el.change(), $el[0]._valueGet && $el[0]._valueGet() == getBufferTemplate().join("") && $el[0]._valueSet(""), |
||
| 861 | opts.removeMaskOnSubmit && $el.inputmask("remove"); |
||
| 862 | }).bind("reset", function() { |
||
| 863 | setTimeout(function() { |
||
| 864 | $el.trigger("setvalue"); |
||
| 865 | }, 0); |
||
| 866 | }), $el.bind("mouseenter.inputmask", function() { |
||
| 867 | var $input = $(this), input = this; |
||
| 868 | !$input.is(":focus") && opts.showMaskOnHover && input._valueGet() != getBuffer().join("") && writeBuffer(input, getBuffer()); |
||
| 869 | }).bind("blur.inputmask", function() { |
||
| 870 | var $input = $(this), input = this; |
||
| 871 | if ($input.data("_inputmask")) { |
||
| 872 | var nptValue = input._valueGet(), buffer = getBuffer(); |
||
| 873 | firstClick = !0, valueOnFocus != getBuffer().join("") && ($input.change(), valueOnFocus = getBuffer().join("")), |
||
| 874 | opts.clearMaskOnLostFocus && "" != nptValue && (nptValue == getBufferTemplate().join("") ? input._valueSet("") : clearOptionalTail(input)), |
||
| 875 | isComplete(buffer) === !1 && ($input.trigger("incomplete"), opts.clearIncomplete && (resetMaskSet(), |
||
| 876 | opts.clearMaskOnLostFocus ? input._valueSet("") : (buffer = getBufferTemplate().slice(), |
||
| 877 | writeBuffer(input, buffer)))); |
||
| 878 | } |
||
| 879 | }).bind("focus.inputmask", function() { |
||
| 880 | var $input = $(this), input = this, nptValue = input._valueGet(); |
||
| 881 | opts.showMaskOnFocus && !$input.is(":focus") && (!opts.showMaskOnHover || opts.showMaskOnHover && "" == nptValue) && input._valueGet() != getBuffer().join("") && writeBuffer(input, getBuffer(), seekNext(getLastValidPosition())), |
||
| 882 | valueOnFocus = getBuffer().join(""); |
||
| 883 | }).bind("mouseleave.inputmask", function() { |
||
| 884 | var $input = $(this), input = this; |
||
| 885 | opts.clearMaskOnLostFocus && ($input.is(":focus") || input._valueGet() == $input.attr("placeholder") || (input._valueGet() == getBufferTemplate().join("") || "" == input._valueGet() ? input._valueSet("") : clearOptionalTail(input))); |
||
| 886 | }).bind("click.inputmask", function() { |
||
| 887 | var $input = $(this), input = this; |
||
| 888 | if ($input.is(":focus")) { |
||
| 889 | var selectedCaret = caret(input); |
||
| 890 | 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())), |
||
| 891 | firstClick = !1; else { |
||
| 892 | var clickPosition = isRTL ? TranslatePosition(selectedCaret.begin) : selectedCaret.begin, lastPosition = seekNext(getLastValidPosition(clickPosition)); |
||
| 893 | lastPosition > clickPosition ? caret(input, isMask(clickPosition) ? clickPosition : seekNext(clickPosition)) : caret(input, lastPosition); |
||
| 894 | } |
||
| 895 | } |
||
| 896 | }).bind("dblclick.inputmask", function() { |
||
| 897 | var input = this; |
||
| 898 | setTimeout(function() { |
||
| 899 | caret(input, 0, seekNext(getLastValidPosition())); |
||
| 900 | }, 0); |
||
| 901 | }).bind(PasteEventType + ".inputmask dragdrop.inputmask drop.inputmask", pasteEvent).bind("setvalue.inputmask", function() { |
||
| 902 | var input = this; |
||
| 903 | checkVal(input, !0, !1), valueOnFocus = getBuffer().join(""), (opts.clearMaskOnLostFocus || opts.clearIncomplete) && input._valueGet() == getBufferTemplate().join("") && input._valueSet(""); |
||
| 904 | }).bind("cut.inputmask", function(e) { |
||
| 905 | skipInputEvent = !0; |
||
| 906 | var input = this, $input = $(input), pos = caret(input); |
||
| 907 | handleRemove(input, $.inputmask.keyCode.DELETE, pos); |
||
| 908 | var keypressResult = opts.onKeyPress.call(this, e, getBuffer(), getMaskSet().p, opts); |
||
| 909 | handleOnKeyResult(input, keypressResult, { |
||
| 910 | begin: getMaskSet().p, |
||
| 911 | end: getMaskSet().p |
||
| 912 | }), input._valueGet() == getBufferTemplate().join("") && $input.trigger("cleared"), |
||
| 913 | opts.showTooltip && $input.prop("title", getMaskSet().mask); |
||
| 914 | }).bind("complete.inputmask", opts.oncomplete).bind("incomplete.inputmask", opts.onincomplete).bind("cleared.inputmask", opts.oncleared), |
||
| 915 | $el.bind("keydown.inputmask", keydownEvent).bind("keypress.inputmask", keypressEvent).bind("keyup.inputmask", keyupEvent).bind("compositionupdate.inputmask", compositionupdateEvent), |
||
| 916 | "paste" === PasteEventType && $el.bind("input.inputmask", inputFallBackEvent), (android || androidfirefox || androidchrome || kindle) && ($el.unbind("input.inputmask"), |
||
| 917 | $el.bind("input.inputmask", mobileInputEvent)), patchValueProperty(el); |
||
| 918 | var initialValue = $.isFunction(opts.onBeforeMask) ? opts.onBeforeMask.call(el, el._valueGet(), opts) || el._valueGet() : el._valueGet(); |
||
| 919 | checkVal(el, !0, !1, initialValue.split("")), valueOnFocus = getBuffer().join(""); |
||
| 920 | var activeElement; |
||
| 921 | try { |
||
| 922 | activeElement = document.activeElement; |
||
| 923 | } catch (e) {} |
||
| 924 | isComplete(getBuffer()) === !1 && opts.clearIncomplete && resetMaskSet(), opts.clearMaskOnLostFocus ? getBuffer().join("") == getBufferTemplate().join("") ? el._valueSet("") : clearOptionalTail(el) : writeBuffer(el, getBuffer()), |
||
| 925 | activeElement === el && caret(el, seekNext(getLastValidPosition())), installEventRuler(el); |
||
| 926 | } |
||
| 927 | } |
||
| 928 | var valueOnFocus, $el, maxLength, isRTL = !1, skipKeyPressEvent = !1, skipInputEvent = !1, ignorable = !1, firstClick = !0; |
||
| 929 | if (void 0 != actionObj) switch (actionObj.action) { |
||
| 930 | case "isComplete": |
||
| 931 | return $el = $(actionObj.el), maskset = $el.data("_inputmask").maskset, opts = $el.data("_inputmask").opts, |
||
| 932 | isComplete(actionObj.buffer); |
||
| 933 | |||
| 934 | case "unmaskedvalue": |
||
| 935 | return $el = actionObj.$input, maskset = $el.data("_inputmask").maskset, opts = $el.data("_inputmask").opts, |
||
| 936 | isRTL = actionObj.$input.data("_inputmask").isRTL, unmaskedvalue(actionObj.$input); |
||
| 937 | |||
| 938 | case "mask": |
||
| 939 | valueOnFocus = getBuffer().join(""), mask(actionObj.el); |
||
| 940 | break; |
||
| 941 | |||
| 942 | case "format": |
||
| 943 | $el = $({}), $el.data("_inputmask", { |
||
| 944 | maskset: maskset, |
||
| 945 | opts: opts, |
||
| 946 | isRTL: opts.numericInput |
||
| 947 | }), opts.numericInput && (isRTL = !0); |
||
| 948 | var valueBuffer = ($.isFunction(opts.onBeforeMask) ? opts.onBeforeMask.call($el, actionObj.value, opts) || actionObj.value : actionObj.value).split(""); |
||
| 949 | return checkVal($el, !1, !1, isRTL ? valueBuffer.reverse() : valueBuffer), opts.onKeyPress.call(this, void 0, getBuffer(), 0, opts), |
||
| 950 | actionObj.metadata ? { |
||
| 951 | value: isRTL ? getBuffer().slice().reverse().join("") : getBuffer().join(""), |
||
| 952 | metadata: $el.inputmask("getmetadata") |
||
| 953 | } : isRTL ? getBuffer().slice().reverse().join("") : getBuffer().join(""); |
||
| 954 | |||
| 955 | case "isValid": |
||
| 956 | $el = $({}), $el.data("_inputmask", { |
||
| 957 | maskset: maskset, |
||
| 958 | opts: opts, |
||
| 959 | isRTL: opts.numericInput |
||
| 960 | }), opts.numericInput && (isRTL = !0); |
||
| 961 | var valueBuffer = actionObj.value.split(""); |
||
| 962 | checkVal($el, !1, !0, isRTL ? valueBuffer.reverse() : valueBuffer); |
||
| 963 | for (var buffer = getBuffer(), rl = determineLastRequiredPosition(), lmib = buffer.length - 1; lmib > rl && !isMask(lmib); lmib--) ; |
||
| 964 | return buffer.splice(rl, lmib + 1 - rl), isComplete(buffer) && actionObj.value == buffer.join(""); |
||
| 965 | |||
| 966 | case "getemptymask": |
||
| 967 | return $el = $(actionObj.el), maskset = $el.data("_inputmask").maskset, opts = $el.data("_inputmask").opts, |
||
| 968 | getBufferTemplate(); |
||
| 969 | |||
| 970 | case "remove": |
||
| 971 | var el = actionObj.el; |
||
| 972 | $el = $(el), maskset = $el.data("_inputmask").maskset, opts = $el.data("_inputmask").opts, |
||
| 973 | el._valueSet(unmaskedvalue($el)), $el.unbind(".inputmask"), $el.removeData("_inputmask"); |
||
| 974 | var valueProperty; |
||
| 975 | Object.getOwnPropertyDescriptor && (valueProperty = Object.getOwnPropertyDescriptor(el, "value")), |
||
| 976 | valueProperty && valueProperty.get ? el._valueGet && Object.defineProperty(el, "value", { |
||
| 977 | get: el._valueGet, |
||
| 978 | set: el._valueSet |
||
| 979 | }) : document.__lookupGetter__ && el.__lookupGetter__("value") && el._valueGet && (el.__defineGetter__("value", el._valueGet), |
||
| 980 | el.__defineSetter__("value", el._valueSet)); |
||
| 981 | try { |
||
| 982 | delete el._valueGet, delete el._valueSet; |
||
| 983 | } catch (e) { |
||
| 984 | el._valueGet = void 0, el._valueSet = void 0; |
||
| 985 | } |
||
| 986 | break; |
||
| 987 | |||
| 988 | case "getmetadata": |
||
| 989 | if ($el = $(actionObj.el), maskset = $el.data("_inputmask").maskset, opts = $el.data("_inputmask").opts, |
||
| 990 | $.isArray(maskset.metadata)) { |
||
| 991 | for (var alternation, lvp = getLastValidPosition(), firstAlt = lvp; firstAlt >= 0; firstAlt--) if (getMaskSet().validPositions[firstAlt] && void 0 != getMaskSet().validPositions[firstAlt].alternation) { |
||
| 992 | alternation = getMaskSet().validPositions[firstAlt].alternation; |
||
| 993 | break; |
||
| 994 | } |
||
| 995 | return void 0 != alternation ? maskset.metadata[getMaskSet().validPositions[lvp].locator[alternation]] : maskset.metadata[0]; |
||
| 996 | } |
||
| 997 | return maskset.metadata; |
||
| 998 | } |
||
| 999 | } |
||
| 1000 | if (void 0 === $.fn.inputmask) { |
||
| 1001 | var ua = ("function" == typeof ScriptEngineMajorVersion ? ScriptEngineMajorVersion() >= 10 : /*@cc_on (@_jscript_version >= 10) ||@*/ !1, |
||
| 1002 | 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"; |
||
| 1003 | $.inputmask = { |
||
| 1004 | defaults: { |
||
| 1005 | placeholder: "_", |
||
| 1006 | optionalmarker: { |
||
| 1007 | start: "[", |
||
| 1008 | end: "]" |
||
| 1009 | }, |
||
| 1010 | quantifiermarker: { |
||
| 1011 | start: "{", |
||
| 1012 | end: "}" |
||
| 1013 | }, |
||
| 1014 | groupmarker: { |
||
| 1015 | start: "(", |
||
| 1016 | end: ")" |
||
| 1017 | }, |
||
| 1018 | alternatormarker: "|", |
||
| 1019 | escapeChar: "\\", |
||
| 1020 | mask: null, |
||
| 1021 | oncomplete: $.noop, |
||
| 1022 | onincomplete: $.noop, |
||
| 1023 | oncleared: $.noop, |
||
| 1024 | repeat: 0, |
||
| 1025 | greedy: !0, |
||
| 1026 | autoUnmask: !1, |
||
| 1027 | removeMaskOnSubmit: !0, |
||
| 1028 | clearMaskOnLostFocus: !0, |
||
| 1029 | insertMode: !0, |
||
| 1030 | clearIncomplete: !1, |
||
| 1031 | aliases: {}, |
||
| 1032 | alias: null, |
||
| 1033 | onKeyUp: $.noop, |
||
| 1034 | onKeyPress: $.noop, |
||
| 1035 | onKeyDown: $.noop, |
||
| 1036 | onBeforeMask: void 0, |
||
| 1037 | onBeforePaste: void 0, |
||
| 1038 | onUnMask: void 0, |
||
| 1039 | showMaskOnFocus: !0, |
||
| 1040 | showMaskOnHover: !0, |
||
| 1041 | onKeyValidation: $.noop, |
||
| 1042 | skipOptionalPartCharacter: " ", |
||
| 1043 | showTooltip: !1, |
||
| 1044 | numericInput: !1, |
||
| 1045 | rightAlign: !1, |
||
| 1046 | radixPoint: "", |
||
| 1047 | radixFocus: !1, |
||
| 1048 | nojumps: !1, |
||
| 1049 | nojumpsThreshold: 0, |
||
| 1050 | keepStatic: void 0, |
||
| 1051 | definitions: { |
||
| 1052 | "9": { |
||
| 1053 | validator: "[0-9]", |
||
| 1054 | cardinality: 1, |
||
| 1055 | definitionSymbol: "*" |
||
| 1056 | }, |
||
| 1057 | a: { |
||
| 1058 | validator: "[A-Za-zА-яЁёÀ-ÿµ]", |
||
| 1059 | cardinality: 1, |
||
| 1060 | definitionSymbol: "*" |
||
| 1061 | }, |
||
| 1062 | "*": { |
||
| 1063 | validator: "[0-9A-Za-zА-яЁёÀ-ÿµ]", |
||
| 1064 | cardinality: 1 |
||
| 1065 | } |
||
| 1066 | }, |
||
| 1067 | 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 ], |
||
| 1068 | isComplete: void 0, |
||
| 1069 | postProcessOnBlur: void 0 |
||
| 1070 | }, |
||
| 1071 | keyCode: { |
||
| 1072 | ALT: 18, |
||
| 1073 | BACKSPACE: 8, |
||
| 1074 | CAPS_LOCK: 20, |
||
| 1075 | COMMA: 188, |
||
| 1076 | COMMAND: 91, |
||
| 1077 | COMMAND_LEFT: 91, |
||
| 1078 | COMMAND_RIGHT: 93, |
||
| 1079 | CONTROL: 17, |
||
| 1080 | DELETE: 46, |
||
| 1081 | DOWN: 40, |
||
| 1082 | END: 35, |
||
| 1083 | ENTER: 13, |
||
| 1084 | ESCAPE: 27, |
||
| 1085 | HOME: 36, |
||
| 1086 | INSERT: 45, |
||
| 1087 | LEFT: 37, |
||
| 1088 | MENU: 93, |
||
| 1089 | NUMPAD_ADD: 107, |
||
| 1090 | NUMPAD_DECIMAL: 110, |
||
| 1091 | NUMPAD_DIVIDE: 111, |
||
| 1092 | NUMPAD_ENTER: 108, |
||
| 1093 | NUMPAD_MULTIPLY: 106, |
||
| 1094 | NUMPAD_SUBTRACT: 109, |
||
| 1095 | PAGE_DOWN: 34, |
||
| 1096 | PAGE_UP: 33, |
||
| 1097 | PERIOD: 190, |
||
| 1098 | RIGHT: 39, |
||
| 1099 | SHIFT: 16, |
||
| 1100 | SPACE: 32, |
||
| 1101 | TAB: 9, |
||
| 1102 | UP: 38, |
||
| 1103 | WINDOWS: 91 |
||
| 1104 | }, |
||
| 1105 | masksCache: {}, |
||
| 1106 | escapeRegex: function(str) { |
||
| 1107 | var specials = [ "/", ".", "*", "+", "?", "|", "(", ")", "[", "]", "{", "}", "\\" ]; |
||
| 1108 | return str.replace(new RegExp("(\\" + specials.join("|\\") + ")", "gim"), "\\$1"); |
||
| 1109 | }, |
||
| 1110 | format: function(value, options, metadata) { |
||
| 1111 | var opts = $.extend(!0, {}, $.inputmask.defaults, options); |
||
| 1112 | return resolveAlias(opts.alias, options, opts), maskScope({ |
||
| 1113 | action: "format", |
||
| 1114 | value: value, |
||
| 1115 | metadata: metadata |
||
| 1116 | }, generateMaskSet(opts), opts); |
||
| 1117 | }, |
||
| 1118 | isValid: function(value, options) { |
||
| 1119 | var opts = $.extend(!0, {}, $.inputmask.defaults, options); |
||
| 1120 | return resolveAlias(opts.alias, options, opts), maskScope({ |
||
| 1121 | action: "isValid", |
||
| 1122 | value: value |
||
| 1123 | }, generateMaskSet(opts), opts); |
||
| 1124 | } |
||
| 1125 | }, $.fn.inputmask = function(fn, options, targetScope, targetData, msk) { |
||
| 1126 | function importAttributeOptions(npt, opts, importedOptionsContainer) { |
||
| 1127 | var $npt = $(npt); |
||
| 1128 | $npt.data("inputmask-alias") && resolveAlias($npt.data("inputmask-alias"), {}, opts); |
||
| 1129 | for (var option in opts) { |
||
| 1130 | var optionData = $npt.data("inputmask-" + option.toLowerCase()); |
||
| 1131 | void 0 != optionData && ("mask" == option && 0 == optionData.indexOf("[") ? (opts[option] = optionData.replace(/[\s[\]]/g, "").split("','"), |
||
| 1132 | 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(), |
||
| 1133 | importedOptionsContainer && (importedOptionsContainer[option] = opts[option])); |
||
| 1134 | } |
||
| 1135 | return opts; |
||
| 1136 | } |
||
| 1137 | targetScope = targetScope || maskScope, targetData = targetData || "_inputmask"; |
||
| 1138 | var maskset, opts = $.extend(!0, {}, $.inputmask.defaults, options); |
||
| 1139 | if ("string" == typeof fn) switch (fn) { |
||
| 1140 | case "mask": |
||
| 1141 | return resolveAlias(opts.alias, options, opts), maskset = generateMaskSet(opts, targetScope !== maskScope), |
||
| 1142 | void 0 == maskset ? this : this.each(function() { |
||
| 1143 | targetScope({ |
||
| 1144 | action: "mask", |
||
| 1145 | el: this |
||
| 1146 | }, $.extend(!0, {}, maskset), importAttributeOptions(this, opts)); |
||
| 1147 | }); |
||
| 1148 | |||
| 1149 | case "unmaskedvalue": |
||
| 1150 | var $input = $(this); |
||
| 1151 | return $input.data(targetData) ? targetScope({ |
||
| 1152 | action: "unmaskedvalue", |
||
| 1153 | $input: $input |
||
| 1154 | }) : $input.val(); |
||
| 1155 | |||
| 1156 | case "remove": |
||
| 1157 | return this.each(function() { |
||
| 1158 | var $input = $(this); |
||
| 1159 | $input.data(targetData) && targetScope({ |
||
| 1160 | action: "remove", |
||
| 1161 | el: this |
||
| 1162 | }); |
||
| 1163 | }); |
||
| 1164 | |||
| 1165 | case "getemptymask": |
||
| 1166 | return this.data(targetData) ? targetScope({ |
||
| 1167 | action: "getemptymask", |
||
| 1168 | el: this |
||
| 1169 | }) : ""; |
||
| 1170 | |||
| 1171 | case "hasMaskedValue": |
||
| 1172 | return this.data(targetData) ? !this.data(targetData).opts.autoUnmask : !1; |
||
| 1173 | |||
| 1174 | case "isComplete": |
||
| 1175 | return this.data(targetData) ? targetScope({ |
||
| 1176 | action: "isComplete", |
||
| 1177 | buffer: this[0]._valueGet().split(""), |
||
| 1178 | el: this |
||
| 1179 | }) : !0; |
||
| 1180 | |||
| 1181 | case "getmetadata": |
||
| 1182 | return this.data(targetData) ? targetScope({ |
||
| 1183 | action: "getmetadata", |
||
| 1184 | el: this |
||
| 1185 | }) : void 0; |
||
| 1186 | |||
| 1187 | case "_detectScope": |
||
| 1188 | 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), |
||
| 1189 | $.isFunction(opts.mask) && (opts.mask = opts.mask.call(this, opts)), $.isArray(opts.mask); |
||
| 1190 | |||
| 1191 | default: |
||
| 1192 | return resolveAlias(opts.alias, options, opts), resolveAlias(fn, options, opts) || (opts.mask = fn), |
||
| 1193 | maskset = generateMaskSet(opts, targetScope !== maskScope), void 0 == maskset ? this : this.each(function() { |
||
| 1194 | targetScope({ |
||
| 1195 | action: "mask", |
||
| 1196 | el: this |
||
| 1197 | }, $.extend(!0, {}, maskset), importAttributeOptions(this, opts)); |
||
| 1198 | }); |
||
| 1199 | } else { |
||
| 1200 | if ("object" == typeof fn) return opts = $.extend(!0, {}, $.inputmask.defaults, fn), |
||
| 1201 | resolveAlias(opts.alias, fn, opts), maskset = generateMaskSet(opts, targetScope !== maskScope), |
||
| 1202 | void 0 == maskset ? this : this.each(function() { |
||
| 1203 | targetScope({ |
||
| 1204 | action: "mask", |
||
| 1205 | el: this |
||
| 1206 | }, $.extend(!0, {}, maskset), importAttributeOptions(this, opts)); |
||
| 1207 | }); |
||
| 1208 | if (void 0 == fn) return this.each(function() { |
||
| 1209 | var attrOptions = $(this).attr("data-inputmask"); |
||
| 1210 | if (attrOptions && "" != attrOptions) try { |
||
| 1211 | attrOptions = attrOptions.replace(new RegExp("'", "g"), '"'); |
||
| 1212 | var dataoptions = $.parseJSON("{" + attrOptions + "}"); |
||
| 1213 | $.extend(!0, dataoptions, options), opts = $.extend(!0, {}, $.inputmask.defaults, dataoptions), |
||
| 1214 | opts = importAttributeOptions(this, opts), resolveAlias(opts.alias, dataoptions, opts), |
||
| 1215 | opts.alias = void 0, $(this).inputmask("mask", opts, targetScope); |
||
| 1216 | } catch (ex) {} |
||
| 1217 | if ($(this).attr("data-inputmask-mask") || $(this).attr("data-inputmask-alias")) { |
||
| 1218 | opts = $.extend(!0, {}, $.inputmask.defaults, {}); |
||
| 1219 | var dataOptions = {}; |
||
| 1220 | opts = importAttributeOptions(this, opts, dataOptions), resolveAlias(opts.alias, dataOptions, opts), |
||
| 1221 | opts.alias = void 0, $(this).inputmask("mask", opts, targetScope); |
||
| 1222 | } |
||
| 1223 | }); |
||
| 1224 | } |
||
| 1225 | }; |
||
| 1226 | } |
||
| 1227 | return $.fn.inputmask; |
||
| 1228 | }(jQuery), function($) { |
||
| 1229 | return $.extend($.inputmask.defaults.definitions, { |
||
| 1230 | h: { |
||
| 1231 | validator: "[01][0-9]|2[0-3]", |
||
| 1232 | cardinality: 2, |
||
| 1233 | prevalidator: [ { |
||
| 1234 | validator: "[0-2]", |
||
| 1235 | cardinality: 1 |
||
| 1236 | } ] |
||
| 1237 | }, |
||
| 1238 | s: { |
||
| 1239 | validator: "[0-5][0-9]", |
||
| 1240 | cardinality: 2, |
||
| 1241 | prevalidator: [ { |
||
| 1242 | validator: "[0-5]", |
||
| 1243 | cardinality: 1 |
||
| 1244 | } ] |
||
| 1245 | }, |
||
| 1246 | d: { |
||
| 1247 | validator: "0[1-9]|[12][0-9]|3[01]", |
||
| 1248 | cardinality: 2, |
||
| 1249 | prevalidator: [ { |
||
| 1250 | validator: "[0-3]", |
||
| 1251 | cardinality: 1 |
||
| 1252 | } ] |
||
| 1253 | }, |
||
| 1254 | m: { |
||
| 1255 | validator: "0[1-9]|1[012]", |
||
| 1256 | cardinality: 2, |
||
| 1257 | prevalidator: [ { |
||
| 1258 | validator: "[01]", |
||
| 1259 | cardinality: 1 |
||
| 1260 | } ] |
||
| 1261 | }, |
||
| 1262 | y: { |
||
| 1263 | validator: "(19|20)\\d{2}", |
||
| 1264 | cardinality: 4, |
||
| 1265 | prevalidator: [ { |
||
| 1266 | validator: "[12]", |
||
| 1267 | cardinality: 1 |
||
| 1268 | }, { |
||
| 1269 | validator: "(19|20)", |
||
| 1270 | cardinality: 2 |
||
| 1271 | }, { |
||
| 1272 | validator: "(19|20)\\d", |
||
| 1273 | cardinality: 3 |
||
| 1274 | } ] |
||
| 1275 | } |
||
| 1276 | }), $.extend($.inputmask.defaults.aliases, { |
||
| 1277 | "dd/mm/yyyy": { |
||
| 1278 | mask: "1/2/y", |
||
| 1279 | placeholder: "dd/mm/yyyy", |
||
| 1280 | regex: { |
||
| 1281 | val1pre: new RegExp("[0-3]"), |
||
| 1282 | val1: new RegExp("0[1-9]|[12][0-9]|3[01]"), |
||
| 1283 | val2pre: function(separator) { |
||
| 1284 | var escapedSeparator = $.inputmask.escapeRegex.call(this, separator); |
||
| 1285 | return new RegExp("((0[1-9]|[12][0-9]|3[01])" + escapedSeparator + "[01])"); |
||
| 1286 | }, |
||
| 1287 | val2: function(separator) { |
||
| 1288 | var escapedSeparator = $.inputmask.escapeRegex.call(this, separator); |
||
| 1289 | return new RegExp("((0[1-9]|[12][0-9])" + escapedSeparator + "(0[1-9]|1[012]))|(30" + escapedSeparator + "(0[13-9]|1[012]))|(31" + escapedSeparator + "(0[13578]|1[02]))"); |
||
| 1290 | } |
||
| 1291 | }, |
||
| 1292 | leapday: "29/02/", |
||
| 1293 | separator: "/", |
||
| 1294 | yearrange: { |
||
| 1295 | minyear: 1900, |
||
| 1296 | maxyear: 2099 |
||
| 1297 | }, |
||
| 1298 | isInYearRange: function(chrs, minyear, maxyear) { |
||
| 1299 | if (isNaN(chrs)) return !1; |
||
| 1300 | var enteredyear = parseInt(chrs.concat(minyear.toString().slice(chrs.length))), enteredyear2 = parseInt(chrs.concat(maxyear.toString().slice(chrs.length))); |
||
| 1301 | return (isNaN(enteredyear) ? !1 : enteredyear >= minyear && maxyear >= enteredyear) || (isNaN(enteredyear2) ? !1 : enteredyear2 >= minyear && maxyear >= enteredyear2); |
||
| 1302 | }, |
||
| 1303 | determinebaseyear: function(minyear, maxyear, hint) { |
||
| 1304 | var currentyear = new Date().getFullYear(); |
||
| 1305 | if (minyear > currentyear) return minyear; |
||
| 1306 | if (currentyear > maxyear) { |
||
| 1307 | for (var maxYearPrefix = maxyear.toString().slice(0, 2), maxYearPostfix = maxyear.toString().slice(2, 4); maxYearPrefix + hint > maxyear; ) maxYearPrefix--; |
||
| 1308 | var maxxYear = maxYearPrefix + maxYearPostfix; |
||
| 1309 | return minyear > maxxYear ? minyear : maxxYear; |
||
| 1310 | } |
||
| 1311 | return currentyear; |
||
| 1312 | }, |
||
| 1313 | onKeyUp: function(e) { |
||
| 1314 | var $input = $(this); |
||
| 1315 | if (e.ctrlKey && e.keyCode == $.inputmask.keyCode.RIGHT) { |
||
| 1316 | var today = new Date(); |
||
| 1317 | $input.val(today.getDate().toString() + (today.getMonth() + 1).toString() + today.getFullYear().toString()); |
||
| 1318 | } |
||
| 1319 | }, |
||
| 1320 | definitions: { |
||
| 1321 | "1": { |
||
| 1322 | validator: function(chrs, maskset, pos, strict, opts) { |
||
| 1323 | var isValid = opts.regex.val1.test(chrs); |
||
| 1324 | return strict || isValid || chrs.charAt(1) != opts.separator && -1 == "-./".indexOf(chrs.charAt(1)) || !(isValid = opts.regex.val1.test("0" + chrs.charAt(0))) ? isValid : (maskset.buffer[pos - 1] = "0", |
||
| 1325 | { |
||
| 1326 | refreshFromBuffer: { |
||
| 1327 | start: pos - 1, |
||
| 1328 | end: pos |
||
| 1329 | }, |
||
| 1330 | pos: pos, |
||
| 1331 | c: chrs.charAt(0) |
||
| 1332 | }); |
||
| 1333 | }, |
||
| 1334 | cardinality: 2, |
||
| 1335 | prevalidator: [ { |
||
| 1336 | validator: function(chrs, maskset, pos, strict, opts) { |
||
| 1337 | isNaN(maskset.buffer[pos + 1]) || (chrs += maskset.buffer[pos + 1]); |
||
| 1338 | var isValid = 1 == chrs.length ? opts.regex.val1pre.test(chrs) : opts.regex.val1.test(chrs); |
||
| 1339 | return strict || isValid || !(isValid = opts.regex.val1.test("0" + chrs)) ? isValid : (maskset.buffer[pos] = "0", |
||
| 1340 | pos++, { |
||
| 1341 | pos: pos |
||
| 1342 | }); |
||
| 1343 | }, |
||
| 1344 | cardinality: 1 |
||
| 1345 | } ] |
||
| 1346 | }, |
||
| 1347 | "2": { |
||
| 1348 | validator: function(chrs, maskset, pos, strict, opts) { |
||
| 1349 | var frontValue = opts.mask.indexOf("2") == opts.mask.length - 1 ? maskset.buffer.join("").substr(5, 3) : maskset.buffer.join("").substr(0, 3); |
||
| 1350 | -1 != frontValue.indexOf(opts.placeholder[0]) && (frontValue = "01" + opts.separator); |
||
| 1351 | var isValid = opts.regex.val2(opts.separator).test(frontValue + chrs); |
||
| 1352 | if (!strict && !isValid && (chrs.charAt(1) == opts.separator || -1 != "-./".indexOf(chrs.charAt(1))) && (isValid = opts.regex.val2(opts.separator).test(frontValue + "0" + chrs.charAt(0)))) return maskset.buffer[pos - 1] = "0", |
||
| 1353 | { |
||
| 1354 | refreshFromBuffer: { |
||
| 1355 | start: pos - 1, |
||
| 1356 | end: pos |
||
| 1357 | }, |
||
| 1358 | pos: pos, |
||
| 1359 | c: chrs.charAt(0) |
||
| 1360 | }; |
||
| 1361 | if (opts.mask.indexOf("2") == opts.mask.length - 1 && isValid) { |
||
| 1362 | var dayMonthValue = maskset.buffer.join("").substr(4, 4) + chrs; |
||
| 1363 | if (dayMonthValue != opts.leapday) return !0; |
||
| 1364 | var year = parseInt(maskset.buffer.join("").substr(0, 4), 10); |
||
| 1365 | return year % 4 === 0 ? year % 100 === 0 ? year % 400 === 0 ? !0 : !1 : !0 : !1; |
||
| 1366 | } |
||
| 1367 | return isValid; |
||
| 1368 | }, |
||
| 1369 | cardinality: 2, |
||
| 1370 | prevalidator: [ { |
||
| 1371 | validator: function(chrs, maskset, pos, strict, opts) { |
||
| 1372 | isNaN(maskset.buffer[pos + 1]) || (chrs += maskset.buffer[pos + 1]); |
||
| 1373 | var frontValue = opts.mask.indexOf("2") == opts.mask.length - 1 ? maskset.buffer.join("").substr(5, 3) : maskset.buffer.join("").substr(0, 3); |
||
| 1374 | -1 != frontValue.indexOf(opts.placeholder[0]) && (frontValue = "01" + opts.separator); |
||
| 1375 | var isValid = 1 == chrs.length ? opts.regex.val2pre(opts.separator).test(frontValue + chrs) : opts.regex.val2(opts.separator).test(frontValue + chrs); |
||
| 1376 | return strict || isValid || !(isValid = opts.regex.val2(opts.separator).test(frontValue + "0" + chrs)) ? isValid : (maskset.buffer[pos] = "0", |
||
| 1377 | pos++, { |
||
| 1378 | pos: pos |
||
| 1379 | }); |
||
| 1380 | }, |
||
| 1381 | cardinality: 1 |
||
| 1382 | } ] |
||
| 1383 | }, |
||
| 1384 | y: { |
||
| 1385 | validator: function(chrs, maskset, pos, strict, opts) { |
||
| 1386 | if (opts.isInYearRange(chrs, opts.yearrange.minyear, opts.yearrange.maxyear)) { |
||
| 1387 | var dayMonthValue = maskset.buffer.join("").substr(0, 6); |
||
| 1388 | if (dayMonthValue != opts.leapday) return !0; |
||
| 1389 | var year = parseInt(chrs, 10); |
||
| 1390 | return year % 4 === 0 ? year % 100 === 0 ? year % 400 === 0 ? !0 : !1 : !0 : !1; |
||
| 1391 | } |
||
| 1392 | return !1; |
||
| 1393 | }, |
||
| 1394 | cardinality: 4, |
||
| 1395 | prevalidator: [ { |
||
| 1396 | validator: function(chrs, maskset, pos, strict, opts) { |
||
| 1397 | var isValid = opts.isInYearRange(chrs, opts.yearrange.minyear, opts.yearrange.maxyear); |
||
| 1398 | if (!strict && !isValid) { |
||
| 1399 | var yearPrefix = opts.determinebaseyear(opts.yearrange.minyear, opts.yearrange.maxyear, chrs + "0").toString().slice(0, 1); |
||
| 1400 | if (isValid = opts.isInYearRange(yearPrefix + chrs, opts.yearrange.minyear, opts.yearrange.maxyear)) return maskset.buffer[pos++] = yearPrefix.charAt(0), |
||
| 1401 | { |
||
| 1402 | pos: pos |
||
| 1403 | }; |
||
| 1404 | if (yearPrefix = opts.determinebaseyear(opts.yearrange.minyear, opts.yearrange.maxyear, chrs + "0").toString().slice(0, 2), |
||
| 1405 | isValid = opts.isInYearRange(yearPrefix + chrs, opts.yearrange.minyear, opts.yearrange.maxyear)) return maskset.buffer[pos++] = yearPrefix.charAt(0), |
||
| 1406 | maskset.buffer[pos++] = yearPrefix.charAt(1), { |
||
| 1407 | pos: pos |
||
| 1408 | }; |
||
| 1409 | } |
||
| 1410 | return isValid; |
||
| 1411 | }, |
||
| 1412 | cardinality: 1 |
||
| 1413 | }, { |
||
| 1414 | validator: function(chrs, maskset, pos, strict, opts) { |
||
| 1415 | var isValid = opts.isInYearRange(chrs, opts.yearrange.minyear, opts.yearrange.maxyear); |
||
| 1416 | if (!strict && !isValid) { |
||
| 1417 | var yearPrefix = opts.determinebaseyear(opts.yearrange.minyear, opts.yearrange.maxyear, chrs).toString().slice(0, 2); |
||
| 1418 | if (isValid = opts.isInYearRange(chrs[0] + yearPrefix[1] + chrs[1], opts.yearrange.minyear, opts.yearrange.maxyear)) return maskset.buffer[pos++] = yearPrefix.charAt(1), |
||
| 1419 | { |
||
| 1420 | pos: pos |
||
| 1421 | }; |
||
| 1422 | if (yearPrefix = opts.determinebaseyear(opts.yearrange.minyear, opts.yearrange.maxyear, chrs).toString().slice(0, 2), |
||
| 1423 | opts.isInYearRange(yearPrefix + chrs, opts.yearrange.minyear, opts.yearrange.maxyear)) { |
||
| 1424 | var dayMonthValue = maskset.buffer.join("").substr(0, 6); |
||
| 1425 | if (dayMonthValue != opts.leapday) isValid = !0; else { |
||
| 1426 | var year = parseInt(chrs, 10); |
||
| 1427 | isValid = year % 4 === 0 ? year % 100 === 0 ? year % 400 === 0 ? !0 : !1 : !0 : !1; |
||
| 1428 | } |
||
| 1429 | } else isValid = !1; |
||
| 1430 | if (isValid) return maskset.buffer[pos - 1] = yearPrefix.charAt(0), maskset.buffer[pos++] = yearPrefix.charAt(1), |
||
| 1431 | maskset.buffer[pos++] = chrs.charAt(0), { |
||
| 1432 | refreshFromBuffer: { |
||
| 1433 | start: pos - 3, |
||
| 1434 | end: pos |
||
| 1435 | }, |
||
| 1436 | pos: pos |
||
| 1437 | }; |
||
| 1438 | } |
||
| 1439 | return isValid; |
||
| 1440 | }, |
||
| 1441 | cardinality: 2 |
||
| 1442 | }, { |
||
| 1443 | validator: function(chrs, maskset, pos, strict, opts) { |
||
| 1444 | return opts.isInYearRange(chrs, opts.yearrange.minyear, opts.yearrange.maxyear); |
||
| 1445 | }, |
||
| 1446 | cardinality: 3 |
||
| 1447 | } ] |
||
| 1448 | } |
||
| 1449 | }, |
||
| 1450 | insertMode: !1, |
||
| 1451 | autoUnmask: !1 |
||
| 1452 | }, |
||
| 1453 | "mm/dd/yyyy": { |
||
| 1454 | placeholder: "mm/dd/yyyy", |
||
| 1455 | alias: "dd/mm/yyyy", |
||
| 1456 | regex: { |
||
| 1457 | val2pre: function(separator) { |
||
| 1458 | var escapedSeparator = $.inputmask.escapeRegex.call(this, separator); |
||
| 1459 | return new RegExp("((0[13-9]|1[012])" + escapedSeparator + "[0-3])|(02" + escapedSeparator + "[0-2])"); |
||
| 1460 | }, |
||
| 1461 | val2: function(separator) { |
||
| 1462 | var escapedSeparator = $.inputmask.escapeRegex.call(this, separator); |
||
| 1463 | return new RegExp("((0[1-9]|1[012])" + escapedSeparator + "(0[1-9]|[12][0-9]))|((0[13-9]|1[012])" + escapedSeparator + "30)|((0[13578]|1[02])" + escapedSeparator + "31)"); |
||
| 1464 | }, |
||
| 1465 | val1pre: new RegExp("[01]"), |
||
| 1466 | val1: new RegExp("0[1-9]|1[012]") |
||
| 1467 | }, |
||
| 1468 | leapday: "02/29/", |
||
| 1469 | onKeyUp: function(e) { |
||
| 1470 | var $input = $(this); |
||
| 1471 | if (e.ctrlKey && e.keyCode == $.inputmask.keyCode.RIGHT) { |
||
| 1472 | var today = new Date(); |
||
| 1473 | $input.val((today.getMonth() + 1).toString() + today.getDate().toString() + today.getFullYear().toString()); |
||
| 1474 | } |
||
| 1475 | } |
||
| 1476 | }, |
||
| 1477 | "yyyy/mm/dd": { |
||
| 1478 | mask: "y/1/2", |
||
| 1479 | placeholder: "yyyy/mm/dd", |
||
| 1480 | alias: "mm/dd/yyyy", |
||
| 1481 | leapday: "/02/29", |
||
| 1482 | onKeyUp: function(e) { |
||
| 1483 | var $input = $(this); |
||
| 1484 | if (e.ctrlKey && e.keyCode == $.inputmask.keyCode.RIGHT) { |
||
| 1485 | var today = new Date(); |
||
| 1486 | $input.val(today.getFullYear().toString() + (today.getMonth() + 1).toString() + today.getDate().toString()); |
||
| 1487 | } |
||
| 1488 | } |
||
| 1489 | }, |
||
| 1490 | "dd.mm.yyyy": { |
||
| 1491 | mask: "1.2.y", |
||
| 1492 | placeholder: "dd.mm.yyyy", |
||
| 1493 | leapday: "29.02.", |
||
| 1494 | separator: ".", |
||
| 1495 | alias: "dd/mm/yyyy" |
||
| 1496 | }, |
||
| 1497 | "dd-mm-yyyy": { |
||
| 1498 | mask: "1-2-y", |
||
| 1499 | placeholder: "dd-mm-yyyy", |
||
| 1500 | leapday: "29-02-", |
||
| 1501 | separator: "-", |
||
| 1502 | alias: "dd/mm/yyyy" |
||
| 1503 | }, |
||
| 1504 | "mm.dd.yyyy": { |
||
| 1505 | mask: "1.2.y", |
||
| 1506 | placeholder: "mm.dd.yyyy", |
||
| 1507 | leapday: "02.29.", |
||
| 1508 | separator: ".", |
||
| 1509 | alias: "mm/dd/yyyy" |
||
| 1510 | }, |
||
| 1511 | "mm-dd-yyyy": { |
||
| 1512 | mask: "1-2-y", |
||
| 1513 | placeholder: "mm-dd-yyyy", |
||
| 1514 | leapday: "02-29-", |
||
| 1515 | separator: "-", |
||
| 1516 | alias: "mm/dd/yyyy" |
||
| 1517 | }, |
||
| 1518 | "yyyy.mm.dd": { |
||
| 1519 | mask: "y.1.2", |
||
| 1520 | placeholder: "yyyy.mm.dd", |
||
| 1521 | leapday: ".02.29", |
||
| 1522 | separator: ".", |
||
| 1523 | alias: "yyyy/mm/dd" |
||
| 1524 | }, |
||
| 1525 | "yyyy-mm-dd": { |
||
| 1526 | mask: "y-1-2", |
||
| 1527 | placeholder: "yyyy-mm-dd", |
||
| 1528 | leapday: "-02-29", |
||
| 1529 | separator: "-", |
||
| 1530 | alias: "yyyy/mm/dd" |
||
| 1531 | }, |
||
| 1532 | datetime: { |
||
| 1533 | mask: "1/2/y h:s", |
||
| 1534 | placeholder: "dd/mm/yyyy hh:mm", |
||
| 1535 | alias: "dd/mm/yyyy", |
||
| 1536 | regex: { |
||
| 1537 | hrspre: new RegExp("[012]"), |
||
| 1538 | hrs24: new RegExp("2[0-4]|1[3-9]"), |
||
| 1539 | hrs: new RegExp("[01][0-9]|2[0-4]"), |
||
| 1540 | ampm: new RegExp("^[a|p|A|P][m|M]"), |
||
| 1541 | mspre: new RegExp("[0-5]"), |
||
| 1542 | ms: new RegExp("[0-5][0-9]") |
||
| 1543 | }, |
||
| 1544 | timeseparator: ":", |
||
| 1545 | hourFormat: "24", |
||
| 1546 | definitions: { |
||
| 1547 | h: { |
||
| 1548 | validator: function(chrs, maskset, pos, strict, opts) { |
||
| 1549 | if ("24" == opts.hourFormat && 24 == parseInt(chrs, 10)) return maskset.buffer[pos - 1] = "0", |
||
| 1550 | maskset.buffer[pos] = "0", { |
||
| 1551 | refreshFromBuffer: { |
||
| 1552 | start: pos - 1, |
||
| 1553 | end: pos |
||
| 1554 | }, |
||
| 1555 | c: "0" |
||
| 1556 | }; |
||
| 1557 | var isValid = opts.regex.hrs.test(chrs); |
||
| 1558 | if (!strict && !isValid && (chrs.charAt(1) == opts.timeseparator || -1 != "-.:".indexOf(chrs.charAt(1))) && (isValid = opts.regex.hrs.test("0" + chrs.charAt(0)))) return maskset.buffer[pos - 1] = "0", |
||
| 1559 | maskset.buffer[pos] = chrs.charAt(0), pos++, { |
||
| 1560 | refreshFromBuffer: { |
||
| 1561 | start: pos - 2, |
||
| 1562 | end: pos |
||
| 1563 | }, |
||
| 1564 | pos: pos, |
||
| 1565 | c: opts.timeseparator |
||
| 1566 | }; |
||
| 1567 | if (isValid && "24" !== opts.hourFormat && opts.regex.hrs24.test(chrs)) { |
||
| 1568 | var tmp = parseInt(chrs, 10); |
||
| 1569 | return 24 == tmp ? (maskset.buffer[pos + 5] = "a", maskset.buffer[pos + 6] = "m") : (maskset.buffer[pos + 5] = "p", |
||
| 1570 | maskset.buffer[pos + 6] = "m"), tmp -= 12, 10 > tmp ? (maskset.buffer[pos] = tmp.toString(), |
||
| 1571 | maskset.buffer[pos - 1] = "0") : (maskset.buffer[pos] = tmp.toString().charAt(1), |
||
| 1572 | maskset.buffer[pos - 1] = tmp.toString().charAt(0)), { |
||
| 1573 | refreshFromBuffer: { |
||
| 1574 | start: pos - 1, |
||
| 1575 | end: pos + 6 |
||
| 1576 | }, |
||
| 1577 | c: maskset.buffer[pos] |
||
| 1578 | }; |
||
| 1579 | } |
||
| 1580 | return isValid; |
||
| 1581 | }, |
||
| 1582 | cardinality: 2, |
||
| 1583 | prevalidator: [ { |
||
| 1584 | validator: function(chrs, maskset, pos, strict, opts) { |
||
| 1585 | var isValid = opts.regex.hrspre.test(chrs); |
||
| 1586 | return strict || isValid || !(isValid = opts.regex.hrs.test("0" + chrs)) ? isValid : (maskset.buffer[pos] = "0", |
||
| 1587 | pos++, { |
||
| 1588 | pos: pos |
||
| 1589 | }); |
||
| 1590 | }, |
||
| 1591 | cardinality: 1 |
||
| 1592 | } ] |
||
| 1593 | }, |
||
| 1594 | s: { |
||
| 1595 | validator: "[0-5][0-9]", |
||
| 1596 | cardinality: 2, |
||
| 1597 | prevalidator: [ { |
||
| 1598 | validator: function(chrs, maskset, pos, strict, opts) { |
||
| 1599 | var isValid = opts.regex.mspre.test(chrs); |
||
| 1600 | return strict || isValid || !(isValid = opts.regex.ms.test("0" + chrs)) ? isValid : (maskset.buffer[pos] = "0", |
||
| 1601 | pos++, { |
||
| 1602 | pos: pos |
||
| 1603 | }); |
||
| 1604 | }, |
||
| 1605 | cardinality: 1 |
||
| 1606 | } ] |
||
| 1607 | }, |
||
| 1608 | t: { |
||
| 1609 | validator: function(chrs, maskset, pos, strict, opts) { |
||
| 1610 | return opts.regex.ampm.test(chrs + "m"); |
||
| 1611 | }, |
||
| 1612 | casing: "lower", |
||
| 1613 | cardinality: 1 |
||
| 1614 | } |
||
| 1615 | }, |
||
| 1616 | insertMode: !1, |
||
| 1617 | autoUnmask: !1 |
||
| 1618 | }, |
||
| 1619 | datetime12: { |
||
| 1620 | mask: "1/2/y h:s t\\m", |
||
| 1621 | placeholder: "dd/mm/yyyy hh:mm xm", |
||
| 1622 | alias: "datetime", |
||
| 1623 | hourFormat: "12" |
||
| 1624 | }, |
||
| 1625 | "hh:mm t": { |
||
| 1626 | mask: "h:s t\\m", |
||
| 1627 | placeholder: "hh:mm xm", |
||
| 1628 | alias: "datetime", |
||
| 1629 | hourFormat: "12" |
||
| 1630 | }, |
||
| 1631 | "h:s t": { |
||
| 1632 | mask: "h:s t\\m", |
||
| 1633 | placeholder: "hh:mm xm", |
||
| 1634 | alias: "datetime", |
||
| 1635 | hourFormat: "12" |
||
| 1636 | }, |
||
| 1637 | "hh:mm:ss": { |
||
| 1638 | mask: "h:s:s", |
||
| 1639 | placeholder: "hh:mm:ss", |
||
| 1640 | alias: "datetime", |
||
| 1641 | autoUnmask: !1 |
||
| 1642 | }, |
||
| 1643 | "hh:mm": { |
||
| 1644 | mask: "h:s", |
||
| 1645 | placeholder: "hh:mm", |
||
| 1646 | alias: "datetime", |
||
| 1647 | autoUnmask: !1 |
||
| 1648 | }, |
||
| 1649 | date: { |
||
| 1650 | alias: "dd/mm/yyyy" |
||
| 1651 | }, |
||
| 1652 | "mm/yyyy": { |
||
| 1653 | mask: "1/y", |
||
| 1654 | placeholder: "mm/yyyy", |
||
| 1655 | leapday: "donotuse", |
||
| 1656 | separator: "/", |
||
| 1657 | alias: "mm/dd/yyyy" |
||
| 1658 | } |
||
| 1659 | }), $.fn.inputmask; |
||
| 1660 | }(jQuery), function($) { |
||
| 1661 | return $.extend($.inputmask.defaults.definitions, { |
||
| 1662 | A: { |
||
| 1663 | validator: "[A-Za-zА-яЁёÀ-ÿµ]", |
||
| 1664 | cardinality: 1, |
||
| 1665 | casing: "upper" |
||
| 1666 | }, |
||
| 1667 | "#": { |
||
| 1668 | validator: "[0-9A-Za-zА-яЁёÀ-ÿµ]", |
||
| 1669 | cardinality: 1, |
||
| 1670 | casing: "upper" |
||
| 1671 | } |
||
| 1672 | }), $.extend($.inputmask.defaults.aliases, { |
||
| 1673 | url: { |
||
| 1674 | mask: "ir", |
||
| 1675 | placeholder: "", |
||
| 1676 | separator: "", |
||
| 1677 | defaultPrefix: "http://", |
||
| 1678 | regex: { |
||
| 1679 | urlpre1: new RegExp("[fh]"), |
||
| 1680 | urlpre2: new RegExp("(ft|ht)"), |
||
| 1681 | urlpre3: new RegExp("(ftp|htt)"), |
||
| 1682 | urlpre4: new RegExp("(ftp:|http|ftps)"), |
||
| 1683 | urlpre5: new RegExp("(ftp:/|ftps:|http:|https)"), |
||
| 1684 | urlpre6: new RegExp("(ftp://|ftps:/|http:/|https:)"), |
||
| 1685 | urlpre7: new RegExp("(ftp://|ftps://|http://|https:/)"), |
||
| 1686 | urlpre8: new RegExp("(ftp://|ftps://|http://|https://)") |
||
| 1687 | }, |
||
| 1688 | definitions: { |
||
| 1689 | i: { |
||
| 1690 | validator: function() { |
||
| 1691 | return !0; |
||
| 1692 | }, |
||
| 1693 | cardinality: 8, |
||
| 1694 | prevalidator: function() { |
||
| 1695 | for (var result = [], prefixLimit = 8, i = 0; prefixLimit > i; i++) result[i] = function() { |
||
| 1696 | var j = i; |
||
| 1697 | return { |
||
| 1698 | validator: function(chrs, maskset, pos, strict, opts) { |
||
| 1699 | if (opts.regex["urlpre" + (j + 1)]) { |
||
| 1700 | var k, tmp = chrs; |
||
| 1701 | j + 1 - chrs.length > 0 && (tmp = maskset.buffer.join("").substring(0, j + 1 - chrs.length) + "" + tmp); |
||
| 1702 | var isValid = opts.regex["urlpre" + (j + 1)].test(tmp); |
||
| 1703 | if (!strict && !isValid) { |
||
| 1704 | for (pos -= j, k = 0; k < opts.defaultPrefix.length; k++) maskset.buffer[pos] = opts.defaultPrefix[k], |
||
| 1705 | pos++; |
||
| 1706 | for (k = 0; k < tmp.length - 1; k++) maskset.buffer[pos] = tmp[k], pos++; |
||
| 1707 | return { |
||
| 1708 | pos: pos |
||
| 1709 | }; |
||
| 1710 | } |
||
| 1711 | return isValid; |
||
| 1712 | } |
||
| 1713 | return !1; |
||
| 1714 | }, |
||
| 1715 | cardinality: j |
||
| 1716 | }; |
||
| 1717 | }(); |
||
| 1718 | return result; |
||
| 1719 | }() |
||
| 1720 | }, |
||
| 1721 | r: { |
||
| 1722 | validator: ".", |
||
| 1723 | cardinality: 50 |
||
| 1724 | } |
||
| 1725 | }, |
||
| 1726 | insertMode: !1, |
||
| 1727 | autoUnmask: !1 |
||
| 1728 | }, |
||
| 1729 | ip: { |
||
| 1730 | mask: "i[i[i]].i[i[i]].i[i[i]].i[i[i]]", |
||
| 1731 | definitions: { |
||
| 1732 | i: { |
||
| 1733 | validator: function(chrs, maskset, pos) { |
||
| 1734 | return pos - 1 > -1 && "." != maskset.buffer[pos - 1] ? (chrs = maskset.buffer[pos - 1] + chrs, |
||
| 1735 | chrs = pos - 2 > -1 && "." != maskset.buffer[pos - 2] ? maskset.buffer[pos - 2] + chrs : "0" + chrs) : chrs = "00" + chrs, |
||
| 1736 | new RegExp("25[0-5]|2[0-4][0-9]|[01][0-9][0-9]").test(chrs); |
||
| 1737 | }, |
||
| 1738 | cardinality: 1 |
||
| 1739 | } |
||
| 1740 | } |
||
| 1741 | }, |
||
| 1742 | email: { |
||
| 1743 | mask: "*{1,64}[.*{1,64}][.*{1,64}][.*{1,64}]@*{1,64}[.*{2,64}][.*{2,6}][.*{1,2}]", |
||
| 1744 | greedy: !1, |
||
| 1745 | onBeforePaste: function(pastedValue) { |
||
| 1746 | return pastedValue = pastedValue.toLowerCase(), pastedValue.replace("mailto:", ""); |
||
| 1747 | }, |
||
| 1748 | definitions: { |
||
| 1749 | "*": { |
||
| 1750 | validator: "[0-9A-Za-z!#$%&'*+/=?^_`{|}~-]", |
||
| 1751 | cardinality: 1, |
||
| 1752 | casing: "lower" |
||
| 1753 | } |
||
| 1754 | } |
||
| 1755 | } |
||
| 1756 | }), $.fn.inputmask; |
||
| 1757 | }(jQuery), function($) { |
||
| 1758 | return $.extend($.inputmask.defaults.aliases, { |
||
| 1759 | numeric: { |
||
| 1760 | mask: function(opts) { |
||
| 1761 | if (0 !== opts.repeat && isNaN(opts.integerDigits) && (opts.integerDigits = opts.repeat), |
||
| 1762 | opts.repeat = 0, opts.groupSeparator == opts.radixPoint && (opts.groupSeparator = "." == opts.radixPoint ? "," : "," == opts.radixPoint ? "." : ""), |
||
| 1763 | " " === opts.groupSeparator && (opts.skipOptionalPartCharacter = void 0), opts.autoGroup = opts.autoGroup && "" != opts.groupSeparator, |
||
| 1764 | opts.autoGroup && isFinite(opts.integerDigits)) { |
||
| 1765 | var seps = Math.floor(opts.integerDigits / opts.groupSize), mod = opts.integerDigits % opts.groupSize; |
||
| 1766 | opts.integerDigits += 0 == mod ? seps - 1 : seps; |
||
| 1767 | } |
||
| 1768 | opts.definitions[";"] = opts.definitions["~"]; |
||
| 1769 | var mask = opts.prefix; |
||
| 1770 | return mask += "[+]", mask += "~{1," + opts.integerDigits + "}", void 0 != opts.digits && (isNaN(opts.digits) || parseInt(opts.digits) > 0) && (mask += opts.digitsOptional ? "[" + (opts.decimalProtect ? ":" : opts.radixPoint) + ";{" + opts.digits + "}]" : (opts.decimalProtect ? ":" : opts.radixPoint) + ";{" + opts.digits + "}"), |
||
| 1771 | mask += opts.suffix; |
||
| 1772 | }, |
||
| 1773 | placeholder: "", |
||
| 1774 | greedy: !1, |
||
| 1775 | digits: "*", |
||
| 1776 | digitsOptional: !0, |
||
| 1777 | groupSeparator: "", |
||
| 1778 | radixPoint: ".", |
||
| 1779 | radixFocus: !0, |
||
| 1780 | groupSize: 3, |
||
| 1781 | autoGroup: !1, |
||
| 1782 | allowPlus: !0, |
||
| 1783 | allowMinus: !0, |
||
| 1784 | integerDigits: "+", |
||
| 1785 | prefix: "", |
||
| 1786 | suffix: "", |
||
| 1787 | rightAlign: !0, |
||
| 1788 | decimalProtect: !0, |
||
| 1789 | postFormat: function(buffer, pos, reformatOnly, opts) { |
||
| 1790 | var needsRefresh = !1, charAtPos = buffer[pos]; |
||
| 1791 | if ("" == opts.groupSeparator || -1 != $.inArray(opts.radixPoint, buffer) && pos >= $.inArray(opts.radixPoint, buffer) || new RegExp("[-+]").test(charAtPos)) return { |
||
| 1792 | pos: pos |
||
| 1793 | }; |
||
| 1794 | var cbuf = buffer.slice(); |
||
| 1795 | charAtPos == opts.groupSeparator && (cbuf.splice(pos--, 1), charAtPos = cbuf[pos]), |
||
| 1796 | reformatOnly ? cbuf[pos] = "?" : cbuf.splice(pos, 0, "?"); |
||
| 1797 | var bufVal = cbuf.join(""); |
||
| 1798 | if (bufVal.length > 0 && opts.autoGroup || reformatOnly && -1 != bufVal.indexOf(opts.groupSeparator)) { |
||
| 1799 | var escapedGroupSeparator = $.inputmask.escapeRegex.call(this, opts.groupSeparator); |
||
| 1800 | needsRefresh = 0 == bufVal.indexOf(opts.groupSeparator), bufVal = bufVal.replace(new RegExp(escapedGroupSeparator, "g"), ""); |
||
| 1801 | var radixSplit = bufVal.split(opts.radixPoint); |
||
| 1802 | if (bufVal = "" == opts.radixPoint ? bufVal : radixSplit[0], bufVal != opts.prefix + "?0" && bufVal.length >= opts.groupSize + opts.prefix.length) { |
||
| 1803 | needsRefresh = !0; |
||
| 1804 | for (var reg = new RegExp("([-+]?[\\d?]+)([\\d?]{" + opts.groupSize + "})"); reg.test(bufVal); ) bufVal = bufVal.replace(reg, "$1" + opts.groupSeparator + "$2"), |
||
| 1805 | bufVal = bufVal.replace(opts.groupSeparator + opts.groupSeparator, opts.groupSeparator); |
||
| 1806 | } |
||
| 1807 | "" != opts.radixPoint && radixSplit.length > 1 && (bufVal += opts.radixPoint + radixSplit[1]); |
||
| 1808 | } |
||
| 1809 | buffer.length = bufVal.length; |
||
| 1810 | for (var i = 0, l = bufVal.length; l > i; i++) buffer[i] = bufVal.charAt(i); |
||
| 1811 | var newPos = $.inArray("?", buffer); |
||
| 1812 | return reformatOnly ? buffer[newPos] = charAtPos : buffer.splice(newPos, 1), { |
||
| 1813 | pos: newPos, |
||
| 1814 | refreshFromBuffer: needsRefresh |
||
| 1815 | }; |
||
| 1816 | }, |
||
| 1817 | onKeyDown: function(e, buffer, caretPos, opts) { |
||
| 1818 | if (e.keyCode == $.inputmask.keyCode.TAB && "0" != opts.placeholder.charAt(0)) { |
||
| 1819 | var radixPosition = $.inArray(opts.radixPoint, buffer); |
||
| 1820 | if (-1 != radixPosition && isFinite(opts.digits)) { |
||
| 1821 | for (var i = 1; i <= opts.digits; i++) (void 0 == buffer[radixPosition + i] || buffer[radixPosition + i] == opts.placeholder.charAt(0)) && (buffer[radixPosition + i] = "0"); |
||
| 1822 | return { |
||
| 1823 | refreshFromBuffer: { |
||
| 1824 | start: ++radixPosition, |
||
| 1825 | end: radixPosition + opts.digits |
||
| 1826 | } |
||
| 1827 | }; |
||
| 1828 | } |
||
| 1829 | } else if (opts.autoGroup && (e.keyCode == $.inputmask.keyCode.DELETE || e.keyCode == $.inputmask.keyCode.BACKSPACE)) { |
||
| 1830 | var rslt = opts.postFormat(buffer, caretPos - 1, !0, opts); |
||
| 1831 | return rslt.caret = rslt.pos + 1, rslt; |
||
| 1832 | } |
||
| 1833 | }, |
||
| 1834 | onKeyPress: function(e, buffer, caretPos, opts) { |
||
| 1835 | if (opts.autoGroup) { |
||
| 1836 | var rslt = opts.postFormat(buffer, caretPos - 1, !0, opts); |
||
| 1837 | return rslt.caret = rslt.pos + 1, rslt; |
||
| 1838 | } |
||
| 1839 | }, |
||
| 1840 | postProcessOnBlur: function(tmpBuffer, opts) { |
||
| 1841 | var tmpBufSplit = "" != opts.radixPoint ? tmpBuffer.join("").split(opts.radixPoint) : [ tmpBuffer.join("") ], matchRslt = tmpBufSplit[0].match(opts.regex.integerPart(opts)), matchRsltDigits = 2 == tmpBufSplit.length ? tmpBufSplit[1].match(opts.regex.integerNPart(opts)) : void 0; |
||
| 1842 | matchRslt && "-0" == matchRslt[matchRslt.index] && (void 0 == matchRsltDigits || matchRsltDigits[matchRsltDigits.index].match(/^0+$/)) && tmpBuffer.splice(0, 1); |
||
| 1843 | }, |
||
| 1844 | regex: { |
||
| 1845 | integerPart: function() { |
||
| 1846 | return new RegExp("[-+]?\\d+"); |
||
| 1847 | }, |
||
| 1848 | integerNPart: function() { |
||
| 1849 | return new RegExp("\\d+"); |
||
| 1850 | } |
||
| 1851 | }, |
||
| 1852 | signHandler: function(chrs, maskset, pos, strict, opts) { |
||
| 1853 | if (!strict && (opts.allowMinus && "-" === chrs || opts.allowPlus && "+" === chrs)) { |
||
| 1854 | var matchRslt = maskset.buffer.join("").match(opts.regex.integerPart(opts)); |
||
| 1855 | if (matchRslt && matchRslt[matchRslt.index].length > 0 && ("0" !== matchRslt[matchRslt.index] || maskset.buffer && maskset._buffer && maskset.buffer.join("") != maskset._buffer.join(""))) return maskset.buffer[matchRslt.index] == ("-" === chrs ? "+" : "-") ? { |
||
| 1856 | pos: matchRslt.index, |
||
| 1857 | c: chrs, |
||
| 1858 | remove: matchRslt.index, |
||
| 1859 | caret: pos |
||
| 1860 | } : maskset.buffer[matchRslt.index] == ("-" === chrs ? "-" : "+") ? { |
||
| 1861 | remove: matchRslt.index, |
||
| 1862 | caret: pos - 1 |
||
| 1863 | } : { |
||
| 1864 | pos: matchRslt.index, |
||
| 1865 | c: chrs, |
||
| 1866 | caret: pos + 1 |
||
| 1867 | }; |
||
| 1868 | } |
||
| 1869 | return !1; |
||
| 1870 | }, |
||
| 1871 | radixHandler: function(chrs, maskset, pos, strict, opts) { |
||
| 1872 | if (!strict && chrs === opts.radixPoint && opts.digits > 0) { |
||
| 1873 | var radixPos = $.inArray(opts.radixPoint, maskset.buffer), integerValue = maskset.buffer.join("").match(opts.regex.integerPart(opts)); |
||
| 1874 | if (-1 != radixPos && maskset.validPositions[radixPos]) return maskset.validPositions[radixPos - 1] ? { |
||
| 1875 | caret: radixPos + 1 |
||
| 1876 | } : { |
||
| 1877 | pos: integerValue.index, |
||
| 1878 | c: integerValue[0], |
||
| 1879 | caret: radixPos + 1 |
||
| 1880 | }; |
||
| 1881 | if (!integerValue || "0" == integerValue[0]) return maskset.buffer[integerValue ? integerValue.index : pos] = "0", |
||
| 1882 | { |
||
| 1883 | pos: (integerValue ? integerValue.index : pos) + 1 |
||
| 1884 | }; |
||
| 1885 | } |
||
| 1886 | return !1; |
||
| 1887 | }, |
||
| 1888 | leadingZeroHandler: function(chrs, maskset, pos, strict, opts) { |
||
| 1889 | var matchRslt = maskset.buffer.join("").match(opts.regex.integerNPart(opts)), radixPosition = $.inArray(opts.radixPoint, maskset.buffer); |
||
| 1890 | if (matchRslt && !strict && (-1 == radixPosition || matchRslt.index < radixPosition)) if ("0" == matchRslt[0] && pos >= opts.prefix.length) { |
||
| 1891 | if (-1 == radixPosition || radixPosition >= pos && void 0 == maskset.validPositions[radixPosition]) return maskset.buffer.splice(matchRslt.index, 1), |
||
| 1892 | pos = pos > matchRslt.index ? pos - 1 : matchRslt.index, { |
||
| 1893 | pos: pos, |
||
| 1894 | remove: matchRslt.index |
||
| 1895 | }; |
||
| 1896 | if (pos > matchRslt.index && radixPosition >= pos) return maskset.buffer.splice(matchRslt.index, 1), |
||
| 1897 | pos = pos > matchRslt.index ? pos - 1 : matchRslt.index, { |
||
| 1898 | pos: pos, |
||
| 1899 | remove: matchRslt.index |
||
| 1900 | }; |
||
| 1901 | if (void 0 == maskset.validPositions[radixPosition]) return maskset.buffer[pos] = chrs, |
||
| 1902 | { |
||
| 1903 | refreshFromBuffer: !0 |
||
| 1904 | }; |
||
| 1905 | } else if ("0" == chrs && pos <= matchRslt.index) return !1; |
||
| 1906 | return !0; |
||
| 1907 | }, |
||
| 1908 | definitions: { |
||
| 1909 | "~": { |
||
| 1910 | validator: function(chrs, maskset, pos, strict, opts) { |
||
| 1911 | var isValid = opts.signHandler(chrs, maskset, pos, strict, opts); |
||
| 1912 | if (!isValid && (isValid = opts.radixHandler(chrs, maskset, pos, strict, opts), |
||
| 1913 | !isValid && (isValid = strict ? new RegExp("[0-9" + $.inputmask.escapeRegex.call(this, opts.groupSeparator) + "]").test(chrs) : new RegExp("[0-9]").test(chrs), |
||
| 1914 | isValid === !0 && (isValid = opts.leadingZeroHandler(chrs, maskset, pos, strict, opts), |
||
| 1915 | isValid === !0)))) { |
||
| 1916 | var radixPosition = $.inArray(opts.radixPoint, maskset.buffer); |
||
| 1917 | isValid = opts.digitsOptional === !1 && pos > radixPosition && !strict ? { |
||
| 1918 | pos: pos, |
||
| 1919 | remove: pos |
||
| 1920 | } : { |
||
| 1921 | pos: pos |
||
| 1922 | }; |
||
| 1923 | } |
||
| 1924 | return isValid; |
||
| 1925 | }, |
||
| 1926 | cardinality: 1, |
||
| 1927 | prevalidator: null |
||
| 1928 | }, |
||
| 1929 | "+": { |
||
| 1930 | validator: function(chrs, maskset, pos, strict, opts) { |
||
| 1931 | var isValid = opts.signHandler(chrs, maskset, pos, strict, opts); |
||
| 1932 | return isValid || (isValid = opts.allowMinus && "-" == chrs || opts.allowPlus && "+" == chrs), |
||
| 1933 | isValid; |
||
| 1934 | }, |
||
| 1935 | cardinality: 1, |
||
| 1936 | prevalidator: null, |
||
| 1937 | placeholder: "" |
||
| 1938 | }, |
||
| 1939 | ":": { |
||
| 1940 | validator: function(chrs, maskset, pos, strict, opts) { |
||
| 1941 | var isValid = opts.signHandler(chrs, maskset, pos, strict, opts); |
||
| 1942 | if (!isValid) { |
||
| 1943 | var radix = "[" + $.inputmask.escapeRegex.call(this, opts.radixPoint) + "]"; |
||
| 1944 | isValid = new RegExp(radix).test(chrs), isValid && maskset.validPositions[pos] && maskset.validPositions[pos].match.placeholder == opts.radixPoint && (isValid = { |
||
| 1945 | pos: pos, |
||
| 1946 | remove: pos |
||
| 1947 | }); |
||
| 1948 | } |
||
| 1949 | return isValid; |
||
| 1950 | }, |
||
| 1951 | cardinality: 1, |
||
| 1952 | prevalidator: null, |
||
| 1953 | placeholder: function(opts) { |
||
| 1954 | return opts.radixPoint; |
||
| 1955 | } |
||
| 1956 | } |
||
| 1957 | }, |
||
| 1958 | insertMode: !0, |
||
| 1959 | autoUnmask: !1, |
||
| 1960 | onUnMask: function(maskedValue, unmaskedValue, opts) { |
||
| 1961 | var processValue = maskedValue.replace(opts.prefix, ""); |
||
| 1962 | return processValue = processValue.replace(opts.suffix, ""), processValue = processValue.replace(new RegExp($.inputmask.escapeRegex.call(this, opts.groupSeparator), "g"), ""); |
||
| 1963 | }, |
||
| 1964 | isComplete: function(buffer, opts) { |
||
| 1965 | var maskedValue = buffer.join(""), bufClone = buffer.slice(); |
||
| 1966 | if (opts.postFormat(bufClone, 0, !0, opts), bufClone.join("") != maskedValue) return !1; |
||
| 1967 | var processValue = maskedValue.replace(opts.prefix, ""); |
||
| 1968 | return processValue = processValue.replace(opts.suffix, ""), processValue = processValue.replace(new RegExp($.inputmask.escapeRegex.call(this, opts.groupSeparator), "g"), ""), |
||
| 1969 | processValue = processValue.replace($.inputmask.escapeRegex.call(this, opts.radixPoint), "."), |
||
| 1970 | isFinite(processValue); |
||
| 1971 | }, |
||
| 1972 | onBeforeMask: function(initialValue, opts) { |
||
| 1973 | if ("" != opts.radixPoint && isFinite(initialValue)) initialValue = initialValue.toString().replace(".", opts.radixPoint); else { |
||
| 1974 | var kommaMatches = initialValue.match(/,/g), dotMatches = initialValue.match(/\./g); |
||
| 1975 | dotMatches && kommaMatches ? dotMatches.length > kommaMatches.length ? (initialValue = initialValue.replace(/\./g, ""), |
||
| 1976 | initialValue = initialValue.replace(",", opts.radixPoint)) : kommaMatches.length > dotMatches.length ? (initialValue = initialValue.replace(/,/g, ""), |
||
| 1977 | initialValue = initialValue.replace(".", opts.radixPoint)) : initialValue = initialValue.indexOf(".") < initialValue.indexOf(",") ? initialValue.replace(/\./g, "") : initialValue = initialValue.replace(/,/g, "") : initialValue = initialValue.replace(new RegExp($.inputmask.escapeRegex.call(this, opts.groupSeparator), "g"), ""); |
||
| 1978 | } |
||
| 1979 | return 0 == opts.digits && (-1 != initialValue.indexOf(".") ? initialValue = initialValue.substring(0, initialValue.indexOf(".")) : -1 != initialValue.indexOf(",") && (initialValue = initialValue.substring(0, initialValue.indexOf(",")))), |
||
| 1980 | initialValue; |
||
| 1981 | } |
||
| 1982 | }, |
||
| 1983 | currency: { |
||
| 1984 | prefix: "$ ", |
||
| 1985 | groupSeparator: ",", |
||
| 1986 | alias: "numeric", |
||
| 1987 | placeholder: "0", |
||
| 1988 | autoGroup: !0, |
||
| 1989 | digits: 2, |
||
| 1990 | digitsOptional: !1, |
||
| 1991 | clearMaskOnLostFocus: !1 |
||
| 1992 | }, |
||
| 1993 | decimal: { |
||
| 1994 | alias: "numeric" |
||
| 1995 | }, |
||
| 1996 | integer: { |
||
| 1997 | alias: "numeric", |
||
| 1998 | digits: "0", |
||
| 1999 | radixPoint: "" |
||
| 2000 | } |
||
| 2001 | }), $.fn.inputmask; |
||
| 2002 | }(jQuery), function($) { |
||
| 2003 | return $.extend($.inputmask.defaults.aliases, { |
||
| 2004 | phone: { |
||
| 2005 | url: "phone-codes/phone-codes.js", |
||
| 2006 | maskInit: "+pp(pp)pppppppp", |
||
| 2007 | countrycode: "", |
||
| 2008 | mask: function(opts) { |
||
| 2009 | opts.definitions = { |
||
| 2010 | p: { |
||
| 2011 | validator: function() { |
||
| 2012 | return !1; |
||
| 2013 | }, |
||
| 2014 | cardinality: 1 |
||
| 2015 | }, |
||
| 2016 | "#": { |
||
| 2017 | validator: "[0-9]", |
||
| 2018 | cardinality: 1 |
||
| 2019 | } |
||
| 2020 | }; |
||
| 2021 | var maskList = []; |
||
| 2022 | return $.ajax({ |
||
| 2023 | url: opts.url, |
||
| 2024 | async: !1, |
||
| 2025 | dataType: "json", |
||
| 2026 | success: function(response) { |
||
| 2027 | maskList = response; |
||
| 2028 | }, |
||
| 2029 | error: function(xhr, ajaxOptions, thrownError) { |
||
| 2030 | alert(thrownError + " - " + opts.url); |
||
| 2031 | } |
||
| 2032 | }), maskList = maskList.sort(function(a, b) { |
||
| 2033 | return (a.mask || a) < (b.mask || b) ? -1 : 1; |
||
| 2034 | }), "" != opts.countrycode && (opts.maskInit = "+" + opts.countrycode + opts.maskInit.substring(3)), |
||
| 2035 | maskList.splice(0, 0, opts.maskInit), maskList; |
||
| 2036 | }, |
||
| 2037 | nojumps: !0, |
||
| 2038 | nojumpsThreshold: 1, |
||
| 2039 | onBeforeMask: function(value, opts) { |
||
| 2040 | var processedValue = value.replace(/^0/g, ""); |
||
| 2041 | return (processedValue.indexOf(opts.countrycode) > 1 || -1 == processedValue.indexOf(opts.countrycode)) && (processedValue = opts.countrycode + processedValue), |
||
| 2042 | processedValue; |
||
| 2043 | } |
||
| 2044 | }, |
||
| 2045 | phonebe: { |
||
| 2046 | alias: "phone", |
||
| 2047 | url: "phone-codes/phone-be.js", |
||
| 2048 | countrycode: "32", |
||
| 2049 | nojumpsThreshold: 4 |
||
| 2050 | } |
||
| 2051 | }), $.fn.inputmask; |
||
| 2052 | }(jQuery), function($) { |
||
| 2053 | return $.extend($.inputmask.defaults.aliases, { |
||
| 2054 | Regex: { |
||
| 2055 | mask: "r", |
||
| 2056 | greedy: !1, |
||
| 2057 | repeat: "*", |
||
| 2058 | regex: null, |
||
| 2059 | regexTokens: null, |
||
| 2060 | tokenizer: /\[\^?]?(?:[^\\\]]+|\\[\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, |
||
| 2061 | quantifierFilter: /[0-9]+[^,]/, |
||
| 2062 | isComplete: function(buffer, opts) { |
||
| 2063 | return new RegExp(opts.regex).test(buffer.join("")); |
||
| 2064 | }, |
||
| 2065 | definitions: { |
||
| 2066 | r: { |
||
| 2067 | validator: function(chrs, maskset, pos, strict, opts) { |
||
| 2068 | function regexToken(isGroup, isQuantifier) { |
||
| 2069 | this.matches = [], this.isGroup = isGroup || !1, this.isQuantifier = isQuantifier || !1, |
||
| 2070 | this.quantifier = { |
||
| 2071 | min: 1, |
||
| 2072 | max: 1 |
||
| 2073 | }, this.repeaterPart = void 0; |
||
| 2074 | } |
||
| 2075 | function analyseRegex() { |
||
| 2076 | var match, m, currentToken = new regexToken(), opengroups = []; |
||
| 2077 | for (opts.regexTokens = []; match = opts.tokenizer.exec(opts.regex); ) switch (m = match[0], |
||
| 2078 | m.charAt(0)) { |
||
| 2079 | case "(": |
||
| 2080 | opengroups.push(new regexToken(!0)); |
||
| 2081 | break; |
||
| 2082 | |||
| 2083 | case ")": |
||
| 2084 | var groupToken = opengroups.pop(); |
||
| 2085 | opengroups.length > 0 ? opengroups[opengroups.length - 1].matches.push(groupToken) : currentToken.matches.push(groupToken); |
||
| 2086 | break; |
||
| 2087 | |||
| 2088 | case "{": |
||
| 2089 | case "+": |
||
| 2090 | case "*": |
||
| 2091 | var quantifierToken = new regexToken(!1, !0); |
||
| 2092 | m = m.replace(/[{}]/g, ""); |
||
| 2093 | 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]); |
||
| 2094 | if (quantifierToken.quantifier = { |
||
| 2095 | min: mq0, |
||
| 2096 | max: mq1 |
||
| 2097 | }, opengroups.length > 0) { |
||
| 2098 | var matches = opengroups[opengroups.length - 1].matches; |
||
| 2099 | if (match = matches.pop(), !match.isGroup) { |
||
| 2100 | var groupToken = new regexToken(!0); |
||
| 2101 | groupToken.matches.push(match), match = groupToken; |
||
| 2102 | } |
||
| 2103 | matches.push(match), matches.push(quantifierToken); |
||
| 2104 | } else { |
||
| 2105 | if (match = currentToken.matches.pop(), !match.isGroup) { |
||
| 2106 | var groupToken = new regexToken(!0); |
||
| 2107 | groupToken.matches.push(match), match = groupToken; |
||
| 2108 | } |
||
| 2109 | currentToken.matches.push(match), currentToken.matches.push(quantifierToken); |
||
| 2110 | } |
||
| 2111 | break; |
||
| 2112 | |||
| 2113 | default: |
||
| 2114 | opengroups.length > 0 ? opengroups[opengroups.length - 1].matches.push(m) : currentToken.matches.push(m); |
||
| 2115 | } |
||
| 2116 | currentToken.matches.length > 0 && opts.regexTokens.push(currentToken); |
||
| 2117 | } |
||
| 2118 | function validateRegexToken(token, fromGroup) { |
||
| 2119 | var isvalid = !1; |
||
| 2120 | fromGroup && (regexPart += "(", openGroupCount++); |
||
| 2121 | for (var mndx = 0; mndx < token.matches.length; mndx++) { |
||
| 2122 | var matchToken = token.matches[mndx]; |
||
| 2123 | if (1 == matchToken.isGroup) isvalid = validateRegexToken(matchToken, !0); else if (1 == matchToken.isQuantifier) { |
||
| 2124 | var crrntndx = $.inArray(matchToken, token.matches), matchGroup = token.matches[crrntndx - 1], regexPartBak = regexPart; |
||
| 2125 | if (isNaN(matchToken.quantifier.max)) { |
||
| 2126 | for (;matchToken.repeaterPart && matchToken.repeaterPart != regexPart && matchToken.repeaterPart.length > regexPart.length && !(isvalid = validateRegexToken(matchGroup, !0)); ) ; |
||
| 2127 | isvalid = isvalid || validateRegexToken(matchGroup, !0), isvalid && (matchToken.repeaterPart = regexPart), |
||
| 2128 | regexPart = regexPartBak + matchToken.quantifier.max; |
||
| 2129 | } else { |
||
| 2130 | for (var i = 0, qm = matchToken.quantifier.max - 1; qm > i && !(isvalid = validateRegexToken(matchGroup, !0)); i++) ; |
||
| 2131 | regexPart = regexPartBak + "{" + matchToken.quantifier.min + "," + matchToken.quantifier.max + "}"; |
||
| 2132 | } |
||
| 2133 | } else if (void 0 != matchToken.matches) for (var k = 0; k < matchToken.length && !(isvalid = validateRegexToken(matchToken[k], fromGroup)); k++) ; else { |
||
| 2134 | var testExp; |
||
| 2135 | if ("[" == matchToken.charAt(0)) { |
||
| 2136 | testExp = regexPart, testExp += matchToken; |
||
| 2137 | for (var j = 0; openGroupCount > j; j++) testExp += ")"; |
||
| 2138 | var exp = new RegExp("^(" + testExp + ")$"); |
||
| 2139 | isvalid = exp.test(bufferStr); |
||
| 2140 | } else for (var l = 0, tl = matchToken.length; tl > l; l++) if ("\\" != matchToken.charAt(l)) { |
||
| 2141 | testExp = regexPart, testExp += matchToken.substr(0, l + 1), testExp = testExp.replace(/\|$/, ""); |
||
| 2142 | for (var j = 0; openGroupCount > j; j++) testExp += ")"; |
||
| 2143 | var exp = new RegExp("^(" + testExp + ")$"); |
||
| 2144 | if (isvalid = exp.test(bufferStr)) break; |
||
| 2145 | } |
||
| 2146 | regexPart += matchToken; |
||
| 2147 | } |
||
| 2148 | if (isvalid) break; |
||
| 2149 | } |
||
| 2150 | return fromGroup && (regexPart += ")", openGroupCount--), isvalid; |
||
| 2151 | } |
||
| 2152 | null == opts.regexTokens && analyseRegex(); |
||
| 2153 | var cbuffer = maskset.buffer.slice(), regexPart = "", isValid = !1, openGroupCount = 0; |
||
| 2154 | cbuffer.splice(pos, 0, chrs); |
||
| 2155 | for (var bufferStr = cbuffer.join(""), i = 0; i < opts.regexTokens.length; i++) { |
||
| 2156 | var regexToken = opts.regexTokens[i]; |
||
| 2157 | if (isValid = validateRegexToken(regexToken, regexToken.isGroup)) break; |
||
| 2158 | } |
||
| 2159 | return isValid; |
||
| 2160 | }, |
||
| 2161 | cardinality: 1 |
||
| 2162 | } |
||
| 2163 | } |
||
| 2164 | } |
||
| 2165 | }), $.fn.inputmask; |
||
| 2166 | }(jQuery); |