ソースを参照

Fix karma testing - qunit & requirejs #1091

Robin Herbots 8 年 前
コミット
44217b8bdb
4 ファイル変更956 行追加946 行削除
  1. 837 836
      js/inputmask.js
  2. 19 13
      js/inputmask.numeric.extensions.js
  3. 99 96
      js/inputmask.phone.extensions.js
  4. 1 1
      package-lock.json

ファイルの差分が大きいため隠しています
+ 837 - 836
js/inputmask.js


+ 19 - 13
js/inputmask.numeric.extensions.js

@@ -28,8 +28,9 @@
                 opts.quantifiermarker.end === txt.charAt(i) ||
                 opts.groupmarker.start === txt.charAt(i) ||
                 opts.groupmarker.end === txt.charAt(i) ||
-                opts.alternatormarker === txt.charAt(i))
+                opts.alternatormarker === txt.charAt(i)) {
                 escapedTxt += "\\" + txt.charAt(i)
+            }
             else escapedTxt += txt.charAt(i);
         }
         return escapedTxt;
@@ -137,7 +138,7 @@
             unmaskAsNumber: false,
             inputmode: "numeric",
             preValidation: function (buffer, pos, c, isSelection, opts) {
-                if (c === "-" || c == opts.negationSymbol.front) {
+                if (c === "-" || c === opts.negationSymbol.front) {
                     if (opts.allowMinus !== true) return false;
                     opts.isNegative = opts.isNegative === undefined ? true : !opts.isNegative;
                     if (buffer.join("") === "") return true;
@@ -172,9 +173,9 @@
 
                 var suffix = opts.suffix.split(""), prefix = opts.prefix.split("");
 
-                if (currentResult.pos == undefined && currentResult.caret !== undefined && currentResult.dopost !== true) return currentResult;
+                if (currentResult.pos === undefined && currentResult.caret !== undefined && currentResult.dopost !== true) return currentResult;
 
-                var caretPos = currentResult.caret != undefined ? currentResult.caret : currentResult.pos;
+                var caretPos = currentResult.caret !== undefined ? currentResult.caret : currentResult.pos;
                 var maskedValue = buffer.slice();
                 if (opts.numericInput) {
                     caretPos = maskedValue.length - caretPos - 1;
@@ -188,7 +189,7 @@
                 }
 
 
-                if (caretPos == maskedValue.length - opts.suffix.length - 1 && charAtPos === opts.radixPoint) return currentResult;
+                if (caretPos === maskedValue.length - opts.suffix.length - 1 && charAtPos === opts.radixPoint) return currentResult;
 
                 if (charAtPos !== undefined) {
                     if (charAtPos !== opts.radixPoint &&
@@ -219,7 +220,7 @@
 
                 //strip leading zeroes
                 if (processValue.length > 1 && processValue.indexOf(opts.radixPoint) !== 1) {
-                    if (charAtPos == "0") {
+                    if (charAtPos === "0") {
                         processValue = processValue.replace(/^\?/g, "");
                     }
                     processValue = processValue.replace(/^0/g, "");
@@ -281,8 +282,9 @@
                 if (charAtPos !== undefined) {
                     if (charAtPos !== opts.radixPoint && charAtPos !== opts.negationSymbol.front && charAtPos !== opts.negationSymbol.back) {
                         caretPos = $.inArray("?", processValue);
-                        if (caretPos > -1)
+                        if (caretPos > -1) {
                             processValue[caretPos] = charAtPos;
+                        }
                         else caretPos = currentResult.caret || 0;
                     } else if (charAtPos === opts.radixPoint ||
                         charAtPos === opts.negationSymbol.front ||
@@ -397,11 +399,13 @@
                                 processValue = processValue.replace(new RegExp(Inputmask.escapeRegex(opts.negationSymbol.back) + "$"), "");
                                 //filter 0 after radixpoint
                                 var pvRadixSplit = processValue.split(opts.radixPoint);
-                                if (pvRadixSplit.length > 1)
+                                if (pvRadixSplit.length > 1) {
                                     pvRadixSplit[1] = pvRadixSplit[1].replace(/0/g, opts.placeholder.charAt(0));
+                                }
                                 //filter 0 before radixpoint
-                                if (pvRadixSplit[0] === "0")
+                                if (pvRadixSplit[0] === "0") {
                                     pvRadixSplit[0] = pvRadixSplit[0].replace(/0/g, opts.placeholder.charAt(0));
+                                }
                                 processValue = pvRadixSplit[0] + opts.radixPoint + pvRadixSplit[1] || "";
                                 var bufferTemplate = maskset._buffer.join(""); //getBuffer().slice(lvp).join('');
                                 if (processValue === opts.radixPoint) {
@@ -474,8 +478,9 @@
                 var processValue = maskedValue.replace(opts.prefix, "");
                 processValue = processValue.replace(opts.suffix, "");
                 processValue = processValue.replace(new RegExp(Inputmask.escapeRegex(opts.groupSeparator), "g"), "");
-                if (opts.placeholder.charAt(0) !== "")
+                if (opts.placeholder.charAt(0) !== "") {
                     processValue = processValue.replace(new RegExp(opts.placeholder.charAt(0), "g"), "0");
+                }
                 if (opts.unmaskAsNumber) {
                     if (opts.radixPoint !== "" && processValue.indexOf(opts.radixPoint) !== -1) processValue = processValue.replace(Inputmask.escapeRegex.call(this, opts.radixPoint), ".");
                     processValue = processValue.replace(new RegExp("^" + Inputmask.escapeRegex(opts.negationSymbol.front)), "-");
@@ -509,8 +514,9 @@
                 if (opts.radixPoint !== "" && isFinite(initialValue)) {
                     var vs = initialValue.split("."),
                         groupSize = opts.groupSeparator !== "" ? parseInt(opts.groupSize) : 0;
-                    if (vs.length === 2 && (vs[0].length > groupSize || vs[1].length > groupSize || (vs[0].length <= groupSize && vs[1].length < groupSize)))
+                    if (vs.length === 2 && (vs[0].length > groupSize || vs[1].length > groupSize || (vs[0].length <= groupSize && vs[1].length < groupSize))) {
                         initialValue = initialValue.replace(".", opts.radixPoint);
+                    }
                 }
                 var kommaMatches = initialValue.match(/,/g);
                 var dotMatches = initialValue.match(/\./g);
@@ -522,7 +528,7 @@
                         initialValue = initialValue.replace(/,/g, "");
                         initialValue = initialValue.replace(".", opts.radixPoint);
                     } else { //equal
-                        initialValue = initialValue.indexOf(".") < initialValue.indexOf(",") ? initialValue.replace(/\./g, "") : initialValue = initialValue.replace(/,/g, "");
+                        initialValue = initialValue.indexOf(".") < initialValue.indexOf(",") ? initialValue.replace(/\./g, "") : initialValue.replace(/,/g, "");
                     }
                 } else {
                     initialValue = initialValue.replace(new RegExp(Inputmask.escapeRegex(opts.groupSeparator), "g"), "");
@@ -566,7 +572,7 @@
                         vp.input === opts.negationSymbol.front ||
                         vp.input === opts.negationSymbol.back;
 
-                if (canClear && (vp.match.nativeDef == "+" || vp.match.nativeDef == "-")) {
+                if (canClear && (vp.match.nativeDef === "+" || vp.match.nativeDef === "-")) {
                     opts.isNegative = false;
                 }
 

+ 99 - 96
js/inputmask.phone.extensions.js

@@ -9,111 +9,114 @@
 
  */
 (function (factory) {
-	if (typeof define === "function" && define.amd) {
-		define(["./dependencyLibs/inputmask.dependencyLib", "./inputmask"], factory);
-	} else if (typeof exports === "object") {
-		module.exports = factory(require("./dependencyLibs/inputmask.dependencyLib"), require("./inputmask"));
-	} else {
-		factory(window.dependencyLib || jQuery, window.Inputmask);
-	}
+    if (typeof define === "function" && define.amd) {
+        define(["./dependencyLibs/inputmask.dependencyLib", "./inputmask"], factory);
+    } else if (typeof exports === "object") {
+        module.exports = factory(require("./dependencyLibs/inputmask.dependencyLib"), require("./inputmask"));
+    } else {
+        factory(window.dependencyLib || jQuery, window.Inputmask);
+    }
 }
 (function ($, Inputmask) {
-	function maskSort(a, b) {
-		var maska = (a.mask || a).replace(/#/g, "9").replace(/\)/, "9").replace(/[+()#-]/g, ""),
-			maskb = (b.mask || b).replace(/#/g, "9").replace(/\)/, "9").replace(/[+()#-]/g, ""),
-			maskas = (a.mask || a).split("#")[0],
-			maskbs = (b.mask || b).split("#")[0];
+    function maskSort(a, b) {
+        var maska = (a.mask || a).replace(/#/g, "9").replace(/\)/, "9").replace(/[+()#-]/g, ""),
+            maskb = (b.mask || b).replace(/#/g, "9").replace(/\)/, "9").replace(/[+()#-]/g, ""),
+            maskas = (a.mask || a).split("#")[0],
+            maskbs = (b.mask || b).split("#")[0];
 
-		return maskbs.indexOf(maskas) === 0 ? -1 : (maskas.indexOf(maskbs) === 0 ? 1 : maska.localeCompare(maskb));
-	}
+        return maskbs.indexOf(maskas) === 0 ? -1 : (maskas.indexOf(maskbs) === 0 ? 1 : maska.localeCompare(maskb));
+    }
 
-	var analyseMaskBase = Inputmask.prototype.analyseMask;
+    var analyseMaskBase = Inputmask.prototype.analyseMask;
 
-	Inputmask.prototype.analyseMask = function (mask, regexMask, opts) {
-		var maskGroups = {};
+    Inputmask.prototype.analyseMask = function (mask, regexMask, opts) {
+        var maskGroups = {};
 
-		function reduceVariations(masks, previousVariation, previousmaskGroup) {
-			previousVariation = previousVariation || "";
-			previousmaskGroup = previousmaskGroup || maskGroups;
-			if (previousVariation !== "")
-				previousmaskGroup[previousVariation] = {};
-			var variation = "", maskGroup = previousmaskGroup[previousVariation] || previousmaskGroup;
-			for (var i = masks.length - 1; i >= 0; i--) {
-				mask = masks[i].mask || masks[i];
-				variation = mask.substr(0, 1);
-				maskGroup[variation] = maskGroup[variation] || [];
-				maskGroup[variation].unshift(mask.substr(1));
-				masks.splice(i, 1);
-			}
-			for (var ndx in maskGroup) {
-				if (maskGroup[ndx].length > 500) {
-					reduceVariations(maskGroup[ndx].slice(), ndx, maskGroup);
-				}
-			}
-		}
+        function reduceVariations(masks, previousVariation, previousmaskGroup) {
+            previousVariation = previousVariation || "";
+            previousmaskGroup = previousmaskGroup || maskGroups;
+            if (previousVariation !== "") {
+                previousmaskGroup[previousVariation] = {};
+            }
+            var variation = "", maskGroup = previousmaskGroup[previousVariation] || previousmaskGroup;
+            for (var i = masks.length - 1; i >= 0; i--) {
+                mask = masks[i].mask || masks[i];
+                variation = mask.substr(0, 1);
+                maskGroup[variation] = maskGroup[variation] || [];
+                maskGroup[variation].unshift(mask.substr(1));
+                masks.splice(i, 1);
+            }
+            for (var ndx in maskGroup) {
+                if (maskGroup[ndx].length > 500) {
+                    reduceVariations(maskGroup[ndx].slice(), ndx, maskGroup);
+                }
+            }
+        }
 
-		function rebuild(maskGroup) {
-			var mask = "", submasks = [];
-			for (var ndx in maskGroup) {
-				if ($.isArray(maskGroup[ndx])) {
-					if (maskGroup[ndx].length === 1)
-						submasks.push(ndx + maskGroup[ndx]);
-					else
-						submasks.push(ndx + opts.groupmarker.start + maskGroup[ndx].join(opts.groupmarker.end + opts.alternatormarker + opts.groupmarker.start) + opts.groupmarker.end);
-				} else {
-					submasks.push(ndx + rebuild(maskGroup[ndx]));
-				}
-			}
-			if (submasks.length === 1) {
-				mask += submasks[0];
-			} else {
-				mask += opts.groupmarker.start + submasks.join(opts.groupmarker.end + opts.alternatormarker + opts.groupmarker.start) + opts.groupmarker.end;
-			}
+        function rebuild(maskGroup) {
+            var mask = "", submasks = [];
+            for (var ndx in maskGroup) {
+                if ($.isArray(maskGroup[ndx])) {
+                    if (maskGroup[ndx].length === 1) {
+                        submasks.push(ndx + maskGroup[ndx]);
+                    }
+                    else {
+                        submasks.push(ndx + opts.groupmarker.start + maskGroup[ndx].join(opts.groupmarker.end + opts.alternatormarker + opts.groupmarker.start) + opts.groupmarker.end);
+                    }
+                } else {
+                    submasks.push(ndx + rebuild(maskGroup[ndx]));
+                }
+            }
+            if (submasks.length === 1) {
+                mask += submasks[0];
+            } else {
+                mask += opts.groupmarker.start + submasks.join(opts.groupmarker.end + opts.alternatormarker + opts.groupmarker.start) + opts.groupmarker.end;
+            }
 
-			return mask;
-		}
+            return mask;
+        }
 
 
-		if (opts.phoneCodes) {
-			if (opts.phoneCodes && opts.phoneCodes.length > 1000) {
-				mask = mask.substr(1, mask.length - 2);
-				reduceVariations(mask.split(opts.groupmarker.end + opts.alternatormarker + opts.groupmarker.start));
-				mask = rebuild(maskGroups);
-			}
-			//escape 9 definition
-			mask = mask.replace(/9/g, "\\9");
-		}
-		// console.log(mask);
-		var mt = analyseMaskBase.call(this, mask, regexMask,opts);
-		return mt;
-	};
-	Inputmask.extendAliases({
-		"abstractphone": {
-			groupmarker: {
-				start: "<",
-				end: ">"
-			},
-			countrycode: "",
-			phoneCodes: [],
-			mask: function (opts) {
-				opts.definitions = {"#": Inputmask.prototype.definitions["9"]};
-				return opts.phoneCodes.sort(maskSort);
-			},
-			keepStatic: true,
-			onBeforeMask: function (value, opts) {
-				var processedValue = value.replace(/^0{1,2}/, "").replace(/[\s]/g, "");
-				if (processedValue.indexOf(opts.countrycode) > 1 || processedValue.indexOf(opts.countrycode) === -1) {
-					processedValue = "+" + opts.countrycode + processedValue;
-				}
+        if (opts.phoneCodes) {
+            if (opts.phoneCodes && opts.phoneCodes.length > 1000) {
+                mask = mask.substr(1, mask.length - 2);
+                reduceVariations(mask.split(opts.groupmarker.end + opts.alternatormarker + opts.groupmarker.start));
+                mask = rebuild(maskGroups);
+            }
+            //escape 9 definition
+            mask = mask.replace(/9/g, "\\9");
+        }
+        // console.log(mask);
+        var mt = analyseMaskBase.call(this, mask, regexMask, opts);
+        return mt;
+    };
+    Inputmask.extendAliases({
+        "abstractphone": {
+            groupmarker: {
+                start: "<",
+                end: ">"
+            },
+            countrycode: "",
+            phoneCodes: [],
+            mask: function (opts) {
+                opts.definitions = {"#": Inputmask.prototype.definitions["9"]};
+                return opts.phoneCodes.sort(maskSort);
+            },
+            keepStatic: true,
+            onBeforeMask: function (value, opts) {
+                var processedValue = value.replace(/^0{1,2}/, "").replace(/[\s]/g, "");
+                if (processedValue.indexOf(opts.countrycode) > 1 || processedValue.indexOf(opts.countrycode) === -1) {
+                    processedValue = "+" + opts.countrycode + processedValue;
+                }
 
-				return processedValue;
-			},
-			onUnMask: function (maskedValue, unmaskedValue, opts) {
-				var unmasked = maskedValue.replace(/[()#-]/g, "");
-				return unmasked;
-			},
-			inputmode: "tel",
-		}
-	});
-	return Inputmask;
+                return processedValue;
+            },
+            onUnMask: function (maskedValue, unmaskedValue, opts) {
+                var unmasked = maskedValue.replace(/[()#-]/g, "");
+                return unmasked;
+            },
+            inputmode: "tel",
+        }
+    });
+    return Inputmask;
 }));

+ 1 - 1
package-lock.json

@@ -1,6 +1,6 @@
 {
   "name": "inputmask",
-  "version": "4.0.1-21",
+  "version": "4.0.1-25",
   "lockfileVersion": 1,
   "requires": true,
   "dependencies": {