1/* 2 * Input Mask plugin for jquery 3 * http://github.com/RobinHerbots/jquery.inputmask 4 * Copyright (c) 2010 - Robin Herbots 5 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php) 6 * Version: 0.0.0-dev 7 */ 8 9(function(factory) { 10 if (typeof define === "function" && define.amd) { 11 define(["jquery", "inputmask"], factory); 12 } else if (typeof exports === "object") { 13 module.exports = factory(require("jquery"), require("./inputmask")); 14 } else { 15 factory(jQuery, window.Inputmask); 16 } 17 } 18 (function($, Inputmask) { 19 if ($.fn.inputmask === undefined) { 20 //jquery plugin 21 $.fn.inputmask = function(fn, options) { 22 var nptmask, input; 23 options = options || {}; 24 if (typeof fn === "string") { 25 switch (fn) { 26 case "mask": 27 nptmask = new Inputmask(options); 28 return this.each(function() { 29 nptmask.mask(this); 30 }); 31 case "unmaskedvalue": 32 input = this.jquery && this.length > 0 ? this[0] : this; 33 return input.inputmask ? input.inputmask.unmaskedvalue() : $(input).val(); 34 case "remove": 35 return this.each(function() { 36 if (this.inputmask) this.inputmask.remove(); 37 }); 38 case "getemptymask": 39 input = this.jquery && this.length > 0 ? this[0] : this; 40 return input.inputmask ? input.inputmask.getemptymask() : ""; 41 case "hasMaskedValue": //check wheter the returned value is masked or not; currently only works reliable when using jquery.val fn to retrieve the value 42 input = this.jquery && this.length > 0 ? this[0] : this; 43 return input.inputmask ? input.inputmask.hasMaskedValue() : false; 44 case "isComplete": 45 input = this.jquery && this.length > 0 ? this[0] : this; 46 return input.inputmask ? input.inputmask.isComplete() : true; 47 case "getmetadata": //return mask metadata if exists 48 input = this.jquery && this.length > 0 ? this[0] : this; 49 return input.inputmask ? input.inputmask.getmetadata() : undefined; 50 case "setvalue": 51 input = this.jquery && this.length > 0 ? this[0] : this; 52 $(input).val(options); 53 if (input.inputmask !== undefined) { 54 $(input).triggerHandler("setvalue.inputmask"); 55 } 56 break; 57 case "option": 58 if (typeof options === "string") { 59 input = this.jquery && this.length > 0 ? this[0] : this; 60 if (input.inputmask !== undefined) { 61 return input.inputmask.option(options); 62 } 63 } else { 64 return this.each(function() { 65 if (this.inputmask !== undefined) { 66 return this.inputmask.option(options); 67 } 68 }); 69 } 70 break; 71 default: 72 options.alias = fn; 73 nptmask = new Inputmask(options); 74 return this.each(function() { 75 nptmask.mask(this); 76 }); 77 } 78 } else if (typeof fn == "object") { 79 nptmask = new Inputmask(fn); 80 if (fn.mask === undefined && fn.alias === undefined) { 81 return this.each(function() { 82 if (this.inputmask !== undefined) { 83 return this.inputmask.option(fn); 84 } else nptmask.mask(this); 85 }); 86 } else { 87 return this.each(function() { 88 nptmask.mask(this); 89 }); 90 } 91 } else if (fn === undefined) { 92 //look for data-inputmask atributes 93 return this.each(function() { 94 nptmask = new Inputmask(options); 95 nptmask.mask(this); 96 }); 97 } 98 }; 99 } 100 return $.fn.inputmask; 101 })); 102 103(function (factory) { 104 if (typeof define === "function" && define.amd) { 105 define(["./dependencyLibs/inputmask.dependencyLib", "./inputmask"], factory); 106 } else if (typeof exports === "object") { 107 module.exports = factory(require("./dependencyLibs/inputmask.dependencyLib"), require("./inputmask")); 108 } else { 109 factory(window.dependencyLib || jQuery, window.Inputmask); 110 } 111} 112(function ($, Inputmask) { 113 Inputmask.extendAliases({ // $(selector).inputmask("Regex", { regex: "[0-9]*"} 114 "Regex": { 115 mask: "r", 116 greedy: false, 117 repeat: "*", 118 regex: null, 119 regexTokens: null, 120 //Thx to https://github.com/slevithan/regex-colorizer for the tokenizer regex 121 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, 122 quantifierFilter: /[0-9]+[^,]/, 123 isComplete: function (buffer, opts) { 124 return new RegExp(opts.regex,opts.casing?"i":"").test(buffer.join("")); 125 }, 126 definitions: { 127 "r": { 128 validator: function (chrs, maskset, pos, strict, opts) { 129 var cbuffer = maskset.buffer.slice(), 130 bufferStr, 131 regexPart = "", 132 isValid = false, 133 openGroupCount = 0, 134 groupToken; 135 136 function RegexToken(isGroup, isQuantifier) { 137 this.matches = []; 138 this.isGroup = isGroup || false;
139 this.isQuantifier = isQuantifier || false; 140 this.quantifier = { 141 min: 1, 142 max: 1 143 }; 144 this.repeaterPart = undefined; 145 } 146 147 function analyseRegex() { 148 var currentToken = new RegexToken(), 149 match, m, opengroups = []; 150 151 opts.regexTokens = []; 152 153 // The tokenizer regex does most of the tokenization grunt work 154 while (match = opts.tokenizer.exec(opts.regex)) { 155 m = match[0]; 156 switch (m.charAt(0)) { 157 case "(": // Group opening 158 opengroups.push(new RegexToken(true)); 159 break; 160 case ")": // Group closing 161 groupToken = opengroups.pop(); 162 if (opengroups.length > 0) { 163 opengroups[opengroups.length - 1].matches.push(groupToken); 164 } else { 165 currentToken.matches.push(groupToken); 166 } 167 break; 168 case "{": 169 case "+": 170 case "*": //Quantifier 171 var quantifierToken = new RegexToken(false, true); 172 m = m.replace(/[{}]/g, ""); 173 var mq = m.split(","), 174 mq0 = isNaN(mq[0]) ? mq[0] : parseInt(mq[0]), 175 mq1 = mq.length === 1 ? mq0 : (isNaN(mq[1]) ? mq[1] : parseInt(mq[1])); 176 quantifierToken.quantifier = { 177 min: mq0, 178 max: mq1 179 }; 180 if (opengroups.length > 0) { 181 var matches = opengroups[opengroups.length - 1].matches; 182 match = matches.pop(); 183 if (!match.isGroup) { 184 groupToken = new RegexToken(true); 185 groupToken.matches.push(match); 186 match = groupToken; 187 } 188 matches.push(match); 189 matches.push(quantifierToken); 190 } else { 191 match = currentToken.matches.pop(); 192 if (!match.isGroup) { 193 groupToken = new RegexToken(true); 194 groupToken.matches.push(match); 195 match = groupToken; 196 } 197 currentToken.matches.push(match); 198 currentToken.matches.push(quantifierToken); 199 } 200 break; 201 default: 202 if (opengroups.length > 0) { 203 opengroups[opengroups.length - 1].matches.push(m); 204 } else { 205 currentToken.matches.push(m); 206 } 207 break; 208 } 209 } 210 211 if (currentToken.matches.length > 0) { 212 opts.regexTokens.push(currentToken); 213 } 214 } 215 216 function validateRegexToken(token, fromGroup) { 217 var isvalid = false; 218 if (fromGroup) { 219 regexPart += "("; 220 openGroupCount++; 221 } 222 for (var mndx = 0; mndx < token.matches.length; mndx++) { 223 var matchToken = token.matches[mndx]; 224 if (matchToken.isGroup === true) { 225 isvalid = validateRegexToken(matchToken, true); 226 } else if (matchToken.isQuantifier === true) { 227 var crrntndx = $.inArray(matchToken, token.matches), 228 matchGroup = token.matches[crrntndx - 1]; 229 var regexPartBak = regexPart; 230 if (isNaN(matchToken.quantifier.max)) { 231 while (matchToken.repeaterPart && matchToken.repeaterPart !== regexPart && matchToken.repeaterPart.length > regexPart.length) { 232 isvalid = validateRegexToken(matchGroup, true); 233 if (isvalid) break; 234 } 235 isvalid = isvalid || validateRegexToken(matchGroup, true); 236 if (isvalid) matchToken.repeaterPart = regexPart; 237 regexPart = regexPartBak + matchToken.quantifier.max; 238 } else { 239 for (var i = 0, qm = matchToken.quantifier.max - 1; i < qm; i++) { 240 isvalid = validateRegexToken(matchGroup, true); 241 if (isvalid) break; 242 } 243 regexPart = regexPartBak + "{" + matchToken.quantifier.min + "," + matchToken.quantifier.max + "}"; 244 } 245 } else if (matchToken.matches !== undefined) { 246 for (var k = 0; k < matchToken.length; k++) { 247 isvalid = validateRegexToken(matchToken[k], fromGroup); 248 if (isvalid) break; 249 } 250 } else { 251 var testExp; 252 if (matchToken.charAt(0) == "[") { 253 testExp = regexPart; 254 testExp += matchToken; 255 for (var j = 0; j < openGroupCount; j++) { 256 testExp += ")"; 257 } 258 var exp = new RegExp("^(" + testExp + ")$",opts.casing?"i":""); 259 isvalid = exp.test(bufferStr); 260 } else { 261 for (var l = 0, tl = matchToken.length; l < tl; l++) { 262 if (matchToken.charAt(l) === "\\") continue; 263 testExp = regexPart; 264 testExp += matchToken.substr(0, l + 1); 265 testExp = testExp.replace(/\|$/, ""); 266 for (var j = 0; j < openGroupCount; j++) { 267 testExp += ")"; 268 } 269 var exp = new RegExp("^(" + testExp + ")$",opts.casing?"i":""); 270 isvalid = exp.test(bufferStr); 271 if (isvalid) break; 272 } 273 } 274 regexPart += matchToken; 275 } 276 if (isvalid) break; 277 } 278 279 if (fromGroup) { 280 regexPart += ")"; 281 openGroupCount--; 282 } 283 284 return isvalid; 285 } 286 287 if (opts.regexTokens === null) { 288 analyseRegex(); 289 } 290 291 cbuffer.splice(pos, 0, chrs); 292 bufferStr = cbuffer.join(""); 293 for (var i = 0; i < opts.regexTokens.length; i++) { 294 var regexToken = opts.regexTokens[i]; 295 isValid = validateRegexToken(regexToken, regexToken.isGroup); 296 if (isValid) break; 297 } 298 299 return isValid; 300 }, 301 cardinality: 1 302 } 303 } 304 } 305 }); 306 return Inputmask; 307}));
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.