Robin Herbots 10 年 前
コミット
e1733ad5e5

+ 12 - 0
CHANGELOG.md

@@ -1,6 +1,18 @@
 # Change Log
 All notable changes to this project will be documented in this file.
 
+## [UNRELEASED]
+### Added
+- staticDefinitionSymbol (see readme)
+- include textarea as a valid masking element
+
+### Updates
+- update alternation logic
+
+### Fixed
+- No-strict mask #1084
+- Inputmask not work with textarea #1128
+
 ## [3.2.5] - 2015-11-27
 
 ### Updates

+ 18 - 0
README.md

@@ -927,6 +927,24 @@ Hook to alter the clear behavior in the stripValidPositions<br>Args => maskset,
 ### postValidation
 Hook to postValidate the result from isValid.  Usefull for validating the entry as a whole.  Args => buffer, opts<br>Return => true|false
 
+### staticDefinitionSymbol
+The staticDefinitionSymbol option is used to indicate that the static entries in the mask can match a certain definition.  Especially usefull with alternators so that static element in the mask can match another alternation.  
+
+In the example below we mark the spaces as a possible match for the "i" definition.  By doing so the mask can alternate to the second mask even when we typed already "12 3".
+
+```javaScript
+Inputmask("(99 99 999999)|(i{+})", {
+  definitions: {
+    "i": {
+      validator: ".",
+      cardinality: 1,
+      definitionSymbol: "*"
+    }
+  },
+  staticDefinitionSymbol: "*"
+}).mask(selector);
+```
+
 ## General
 ### set a value and apply mask
 this can be done with the traditional jquery.val function (all browsers) or JavaScript value property for browsers which implement lookupGetter or getOwnPropertyDescriptor

+ 1 - 1
bower.json

@@ -1,6 +1,6 @@
 {
   "name": "jquery.inputmask",
-  "version": "3.2.5",
+  "version": "3.2.6-1",
   "main": [
     "./dist/inputmask/inputmask.js"
   ],

+ 1 - 1
component.json

@@ -2,7 +2,7 @@
   "name": "jquery_inputmask",
   "repository": "robinherbots/jquery.inputmask",
   "description": "jquery.inputmask is a jquery plugin which create an input mask.",
-  "version": "3.2.5",
+  "version": "3.2.6-1",
   "keywords": ["jquery", "plugins", "input", "form", "inputmask", "mask"],
   "main": "./dist/jquery.inputmask.bundle.js",
   "scripts": [

+ 1 - 1
composer.json

@@ -1,7 +1,7 @@
 {
   "name": "robinherbots/jquery.inputmask",
   "description": "jquery.inputmask is a jquery plugin which create an input mask.",
-  "version": "3.2.5",
+  "version": "3.2.6-1",
   "type": "library",
   "keywords": ["jquery", "plugins", "input", "form", "inputmask", "mask"],
   "homepage": "http://robinherbots.github.io/jquery.inputmask",

+ 1 - 1
dist/inputmask/inputmask.date.extensions.js

@@ -3,7 +3,7 @@
 * http://github.com/RobinHerbots/jquery.inputmask
 * Copyright (c) 2010 - 2015 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 3.2.5
+* Version: 3.2.6-1
 */
 !function(factory) {
     "function" == typeof define && define.amd ? define([ "inputmask.dependencyLib", "inputmask" ], factory) : "object" == typeof exports ? module.exports = factory(require("./inputmask.dependencyLib.jquery"), require("./inputmask")) : factory(window.dependencyLib || jQuery, window.Inputmask);

+ 1 - 1
dist/inputmask/inputmask.dependencyLib.jquery.js

@@ -3,7 +3,7 @@
 * http://github.com/RobinHerbots/jquery.inputmask
 * Copyright (c) 2010 - 2015 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 3.2.5
+* Version: 3.2.6-1
 */
 !function(factory) {
     "function" == typeof define && define.amd ? define([ "jquery" ], factory) : "object" == typeof exports ? module.exports = factory(require("jquery")) : factory(jQuery);

+ 8 - 2
dist/inputmask/inputmask.extensions.js

@@ -3,7 +3,7 @@
 * http://github.com/RobinHerbots/jquery.inputmask
 * Copyright (c) 2010 - 2015 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 3.2.5
+* Version: 3.2.6-1
 */
 !function(factory) {
     "function" == typeof define && define.amd ? define([ "inputmask.dependencyLib", "inputmask" ], factory) : "object" == typeof exports ? module.exports = factory(require("./inputmask.dependencyLib.jquery"), require("./inputmask")) : factory(window.dependencyLib || jQuery, window.Inputmask);
@@ -26,7 +26,13 @@
         }
     }), Inputmask.extendAliases({
         url: {
-            mask: "(\\http://)|(\\http\\s://)|(ftp://)|(ftp\\s://)*{+}",
+            definitions: {
+                i: {
+                    validator: ".",
+                    cardinality: 1
+                }
+            },
+            mask: "(\\http://)|(\\http\\s://)|(ftp://)|(ftp\\s://)i{+}",
             insertMode: !1,
             autoUnmask: !1
         },

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


+ 1 - 1
dist/inputmask/inputmask.numeric.extensions.js

@@ -3,7 +3,7 @@
 * http://github.com/RobinHerbots/jquery.inputmask
 * Copyright (c) 2010 - 2015 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 3.2.5
+* Version: 3.2.6-1
 */
 !function(factory) {
     "function" == typeof define && define.amd ? define([ "inputmask.dependencyLib", "inputmask" ], factory) : "object" == typeof exports ? module.exports = factory(require("./inputmask.dependencyLib.jquery"), require("./inputmask")) : factory(window.dependencyLib || jQuery, window.Inputmask);

+ 1 - 1
dist/inputmask/inputmask.phone.extensions.js

@@ -3,7 +3,7 @@
 * http://github.com/RobinHerbots/jquery.inputmask
 * Copyright (c) 2010 - 2015 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 3.2.5
+* Version: 3.2.6-1
 */
 !function(factory) {
     "function" == typeof define && define.amd ? define([ "jquery", "inputmask" ], factory) : "object" == typeof exports ? module.exports = factory(require("jquery"), require("./inputmask")) : factory(window.dependencyLib || jQuery, window.Inputmask);

+ 1 - 1
dist/inputmask/inputmask.regex.extensions.js

@@ -3,7 +3,7 @@
 * http://github.com/RobinHerbots/jquery.inputmask
 * Copyright (c) 2010 - 2015 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 3.2.5
+* Version: 3.2.6-1
 */
 !function(factory) {
     "function" == typeof define && define.amd ? define([ "inputmask.dependencyLib", "inputmask" ], factory) : "object" == typeof exports ? module.exports = factory(require("./inputmask.dependencyLib.jquery"), require("./inputmask")) : factory(window.dependencyLib || jQuery, window.Inputmask);

+ 1 - 1
dist/inputmask/jquery.inputmask.js

@@ -3,7 +3,7 @@
 * http://github.com/RobinHerbots/jquery.inputmask
 * Copyright (c) 2010 - 2015 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 3.2.5
+* Version: 3.2.6-1
 */
 !function(factory) {
     "function" == typeof define && define.amd ? define([ "jquery", "inputmask" ], factory) : "object" == typeof exports ? module.exports = factory(require("jquery"), require("./inputmask")) : factory(jQuery, window.Inputmask);

ファイルの差分が大きいため隠しています
+ 27 - 16
dist/jquery.inputmask.bundle.js


ファイルの差分が大きいため隠しています
+ 1 - 1
dist/min/inputmask/inputmask.date.extensions.min.js


+ 1 - 1
dist/min/inputmask/inputmask.dependencyLib.jquery.min.js

@@ -3,6 +3,6 @@
 * http://github.com/RobinHerbots/jquery.inputmask
 * Copyright (c) 2010 - 2015 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 3.2.5
+* Version: 3.2.6-1
 */
 !function(a){"function"==typeof define&&define.amd?define(["jquery"],a):"object"==typeof exports?module.exports=a(require("jquery")):a(jQuery)}(function(a){return window.dependencyLib=a,a});

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


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


ファイルの差分が大きいため隠しています
+ 1 - 1
dist/min/inputmask/inputmask.numeric.extensions.min.js


ファイルの差分が大きいため隠しています
+ 1 - 1
dist/min/inputmask/inputmask.phone.extensions.min.js


ファイルの差分が大きいため隠しています
+ 1 - 1
dist/min/inputmask/inputmask.regex.extensions.min.js


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


ファイルの差分が大きいため隠しています
+ 4 - 4
dist/min/jquery.inputmask.bundle.min.js


+ 52 - 0
extra/dependencyLibs/inputmask.dependencyLib.jqlite.js

@@ -117,6 +117,58 @@ Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.p
 			// Return the modified object
 			return target;
 		};
+		$.each = function(obj, callback) {
+			var value, i = 0;
+
+			if (isArraylike(obj)) {
+				for (var length = obj.length; i < length; i++) {
+					value = callback.call(obj[i], i, obj[i]);
+					if (value === false) {
+						break;
+					}
+				}
+			} else {
+				for (i in obj) {
+					value = callback.call(obj[i], i, obj[i]);
+					if (value === false) {
+						break;
+					}
+				}
+			}
+
+			return obj;
+		};
+		$.map = function(elems, callback) {
+			var value,
+				i = 0,
+				length = elems.length,
+				isArray = isArraylike(elems),
+				ret = [];
+
+			// Go through the array, translating each of the items to their new values
+			if (isArray) {
+				for (; i < length; i++) {
+					value = callback(elems[i], i);
+
+					if (value != null) {
+						ret.push(value);
+					}
+				}
+
+				// Go through every key on the object,
+			} else {
+				for (i in elems) {
+					value = callback(elems[i], i);
+
+					if (value != null) {
+						ret.push(value);
+					}
+				}
+			}
+
+			// Flatten any nested arrays
+			return [].concat(ret);
+		};
 		$.data = function(elem, name, data) {
 			return $(elem).data(name, data);
 		};

+ 7 - 1
js/inputmask.extensions.js

@@ -37,7 +37,13 @@ Optional extensions on the jquery.inputmask base
 		});
 		Inputmask.extendAliases({
 			"url": {
-				mask: "(\\http://)|(\\http\\s://)|(ftp://)|(ftp\\s://)*{+}",
+				definitions: {
+					"i": {
+						validator: ".",
+						cardinality: 1
+					}
+				},
+				mask: "(\\http://)|(\\http\\s://)|(ftp://)|(ftp\\s://)i{+}",
 				insertMode: false,
 				autoUnmask: false
 			},

+ 31 - 23
js/inputmask.js

@@ -114,7 +114,8 @@
 				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],
 				isComplete: null, //override for isComplete - args => buffer, opts - return true || false
 				canClearPosition: $.noop, //hook to alter the clear behavior in the stripValidPositions args => maskset, position, lastValidPosition, opts => return true|false
-				postValidation: null //hook to postValidate the result from isValid.	Usefull for validating the entry as a whole.	args => buffer, opts => return true/false
+				postValidation: null, //hook to postValidate the result from isValid.	Usefull for validating the entry as a whole.	args => buffer, opts => return true/false
+				staticDefinitionSymbol: undefined //specify a definitionSymbol for static content, used to make matches for alternators
 			},
 			masksCache: {},
 			mask: function(elems) {
@@ -453,8 +454,8 @@
 							optionality: mtoken.isOptional,
 							newBlockMarker: prevMatch === undefined || prevMatch.def !== element,
 							casing: null,
-							def: element,
-							placeholder: undefined,
+							def: opts.staticDefinitionSymbol || element,
+							placeholder: opts.staticDefinitionSymbol !== undefined ? element : undefined,
 							mask: element
 						});
 						escaped = false;
@@ -782,8 +783,8 @@
 			function resetMaskSet(soft) {
 				var maskset = getMaskSet();
 				maskset.buffer = undefined;
-				maskset.tests = {};
 				if (soft !== true) {
+					maskset.tests = {};
 					maskset._buffer = undefined;
 					maskset.validPositions = {};
 					maskset.p = 0;
@@ -958,16 +959,15 @@
 				function resolveTestFromToken(maskToken, ndxInitializer, loopNdx, quantifierRecurse) { //ndxInitializer contains a set of indexes to speedup searches in the mtokens
 					function handleMatch(match, loopNdx, quantifierRecurse) {
 						function resolveNdxInitializer(pos, alternateNdx) {
-							var previousMatch = getMaskSet().validPositions[pos];
-							if (previousMatch === undefined) {
-								if (getMaskSet().tests[pos]) {
-									$.each(getMaskSet().tests[pos], function(ndx, lmnt) {
-										if (lmnt.alternation && lmnt.locator[lmnt.alternation].toString().indexOf(alternateNdx) !== -1) {
-											previousMatch = lmnt;
-											return false;
-										}
-									});
-								}
+							var previousMatch, indexPos;
+							if (getMaskSet().tests[pos] || getMaskSet().validPositions[pos]) {
+								$.each(getMaskSet().tests[pos] || [getMaskSet().validPositions[pos]], function(ndx, lmnt) {
+									var ndxPos = lmnt.alternation ? lmnt.locator[lmnt.alternation].toString().indexOf(alternateNdx) : -1;
+									if (indexPos === undefined || (ndxPos < indexPos && ndxPos !== -1)) {
+										previousMatch = lmnt;
+										indexPos = ndxPos;
+									}
+								});
 							}
 							return previousMatch ? previousMatch.locator.slice(previousMatch.alternation + 1) : [];
 						}
@@ -1190,7 +1190,13 @@
 
 			function getBuffer(noCache) {
 				if (getMaskSet().buffer === undefined || noCache === true) {
-					if (noCache === true) getMaskSet().tests = {};
+					if (noCache === true) {
+						for (var testNdx in getMaskSet().tests) {
+							if (getMaskSet().validPositions[testNdx] === undefined) {
+								delete getMaskSet().tests[testNdx];
+							}
+						}
+					}
 					getMaskSet().buffer = getMaskTemplate(true, getLastValidPosition(), true);
 				}
 				return getMaskSet().buffer;
@@ -1264,13 +1270,13 @@
 						rslt = test.fn != null ?
 							test.fn.test(chrs, getMaskSet(), position, strict, opts) : (c === test.def || c === opts.skipOptionalPartCharacter) && test.def !== "" ? //non mask
 							{
-								c: test.def,
+								c: test.placeholder || test.def,
 								pos: position
 							} : false;
 
 						if (rslt !== false) {
 							var elem = rslt.c !== undefined ? rslt.c : c;
-							elem = (elem === opts.skipOptionalPartCharacter && test.fn === null) ? test.def : elem;
+							elem = (elem === opts.skipOptionalPartCharacter && test.fn === null) ? (test.placeholder || test.def) : elem;
 
 							var validatedPos = position,
 								possibleModifiedBuffer = getBuffer();
@@ -1440,12 +1446,14 @@
 							var tests = getTests(ps),
 								bestMatch = tests[0],
 								equality = -1;
-							$.each(tests, function(ndx, tst) {
+							$.each(tests, function(ndx, tst) { //find best matching
 								for (var i = 0; i < tll; i++) {
-									if (tst.locator[i] && checkAlternationMatch(tst.locator[i].toString().split(","), targetLocator[i].toString().split(",")) && equality < i) {
-										equality = i;
-										bestMatch = tst;
-									}
+									if (tst.locator[i] !== undefined && checkAlternationMatch(tst.locator[i].toString().split(","), targetLocator[i].toString().split(","))) {
+										if (equality < i) {
+											equality = i;
+											bestMatch = tst;
+										}
+									} else break;
 								}
 							});
 							setValidPosition(ps, $.extend({}, bestMatch, {
@@ -2570,7 +2578,7 @@
 				//unbind all events - to make sure that no other mask will interfere when re-masking
 				$el.off(".inputmask");
 				patchValueProperty(el);
-				if ((el.tagName === "INPUT" && isInputTypeSupported(el.getAttribute("type"))) || el.isContentEditable) {
+				if ((el.tagName === "INPUT" && isInputTypeSupported(el.getAttribute("type"))) || el.isContentEditable || el.tagName === "TEXTAREA") {
 					//bind events
 					$(el.form).on("submit.inputmask", submitEvent).on("reset.inputmask", resetEvent);
 

+ 1 - 1
package.json

@@ -1,6 +1,6 @@
 {
   "name": "jquery.inputmask",
-  "version": "3.2.5",
+  "version": "3.2.6-1",
   "description": "jquery.inputmask is a jquery plugin which create an input mask.",
   "main": "./dist/inputmask/jquery.inputmask.js",
   "files": [

+ 55 - 0
qunit/tests_multi.js

@@ -321,5 +321,60 @@ define([
 		assert.equal(testmask.value, "123-12-1234", "Result " + testmask.value);
 
 	});
+	qunit.test("'[9-]AAA-999', '999999' - type 1A - dekdegiv", function(assert) {
+		var $fixture = $("#qunit-fixture");
+		$fixture.append('<input type="text" id="testmask" />');
+		var testmask = document.getElementById("testmask");
+		Inputmask({
+			"mask": ['[9-]AAA-999', '999999'],
+			keepStatic: false
+		}).mask(testmask);
+
+		$("#testmask").Type("1a");
+		assert.equal(testmask.value, "1-A__-___", "Result " + testmask.value);
+
+	});
+
+	qunit.test("(99 99 999999)|(*{+}) - 12abc - dekdegiv", function(assert) {
+		var $fixture = $("#qunit-fixture");
+		$fixture.append('<input type="text" id="testmask" />');
+		var testmask = document.getElementById("testmask");
+		Inputmask("(99 99 999999)|(*{+})").mask(testmask);
+
+		$("#testmask").Type("12abc");
+		assert.equal(testmask.value, "12abc", "Result " + testmask.value);
+	});
 
+	qunit.test("(99 99 999999)|(*{+}) - 12 34 delete ' 34' + 2abc", function(assert) {
+		var $fixture = $("#qunit-fixture");
+		$fixture.append('<input type="text" id="testmask" />');
+		var testmask = document.getElementById("testmask");
+		Inputmask("(99 99 999999)|(*{+})").mask(testmask);
+
+		$("#testmask").Type("12 34");
+		$("#testmask").SendKey(Inputmask.keyCode.BACKSPACE);
+		$("#testmask").SendKey(Inputmask.keyCode.BACKSPACE);
+		$("#testmask").SendKey(Inputmask.keyCode.BACKSPACE);
+		$("#testmask").Type("2abc");
+		assert.equal(testmask.value, "12abc", "Result " + testmask.value);
+	});
+
+	qunit.test("(99 99 999999)|(i{+}) - 12 3abc - dekdegiv", function(assert) {
+		var $fixture = $("#qunit-fixture");
+		$fixture.append('<input type="text" id="testmask" />');
+		var testmask = document.getElementById("testmask");
+		Inputmask("(99 99 999999)|(i{+})", {
+			definitions: {
+				"i": {
+					validator: ".",
+					cardinality: 1,
+					definitionSymbol: "*"
+				}
+			},
+			staticDefinitionSymbol: "*"
+		}).mask(testmask);
+
+		$("#testmask").Type("12 3abc");
+		assert.equal(testmask.value, "12 3abc", "Result " + testmask.value);
+	});
 });