ソースを参照

update package.json

Robin Herbots 8 年 前
コミット
53881b91e9
5 ファイル変更80 行追加65 行削除
  1. 10 10
      bower.json
  2. 10 10
      component.json
  3. 1 1
      composer.json
  4. 58 43
      js/inputmask.js
  5. 1 1
      package.json

+ 10 - 10
bower.json

@@ -1,16 +1,16 @@
 {
   "name": "jquery.inputmask",
-  "version": "3.3.5-49",
+  "version": "3.3.5-58",
   "main": [
-	  "./dist/inputmask/inputmask",
-	  "./dist/inputmask/inputmask.extensions",
-	  "./dist/inputmask/inputmask.date.extensions",
-	  "./dist/inputmask/inputmask.numeric.extensions",
-	  "./dist/inputmask/inputmask.phone.extensions",
-	  "./dist/inputmask/inputmask.regex.extensions",
-	  "./dist/inputmask/jquery.inputmask",
-	  "./dist/inputmask/global/document",
-	  "./dist/inputmask/global/window",
+	  "./dist/inputmask/inputmask.js",
+	  "./dist/inputmask/inputmask.extensions.js",
+	  "./dist/inputmask/inputmask.date.extensions.js",
+	  "./dist/inputmask/inputmask.numeric.extensions.js",
+	  "./dist/inputmask/inputmask.phone.extensions.js",
+	  "./dist/inputmask/inputmask.regex.extensions.js",
+	  "./dist/inputmask/jquery.inputmask.js",
+	  "./dist/inputmask/global/document.js",
+	  "./dist/inputmask/global/window.js",
 	  "./dist/inputmask/phone-codes/phone.js",
 	  "./dist/inputmask/phone-codes/phone-be.js",
 	  "./dist/inputmask/phone-codes/phone-nl.js",

+ 10 - 10
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.3.5-49",
+	"version": "3.3.5-58",
 	"keywords": [
 		"jquery",
 		"plugins",
@@ -13,15 +13,15 @@
 	],
 	"main": "./dist/jquery.inputmask.bundle.js",
 	"scripts": [
-		"./dist/inputmask/inputmask",
-		"./dist/inputmask/inputmask.extensions",
-		"./dist/inputmask/inputmask.date.extensions",
-		"./dist/inputmask/inputmask.numeric.extensions",
-		"./dist/inputmask/inputmask.phone.extensions",
-		"./dist/inputmask/inputmask.regex.extensions",
-		"./dist/inputmask/jquery.inputmask",
-		"./dist/inputmask/global/document",
-		"./dist/inputmask/global/window",
+		"./dist/inputmask/inputmask.js",
+		"./dist/inputmask/inputmask.extensions.js",
+		"./dist/inputmask/inputmask.date.extensions.js",
+		"./dist/inputmask/inputmask.numeric.extensions.js",
+		"./dist/inputmask/inputmask.phone.extensions.js",
+		"./dist/inputmask/inputmask.regex.extensions.js",
+		"./dist/inputmask/jquery.inputmask.js",
+		"./dist/inputmask/global/document.js",
+		"./dist/inputmask/global/window.js",
 		"./dist/inputmask/phone-codes/phone.js",
 		"./dist/inputmask/phone-codes/phone-be.js",
 		"./dist/inputmask/phone-codes/phone-nl.js",

+ 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.3.5-49",
+  "version": "3.3.5-58",
   "type": "library",
   "keywords": ["jquery", "plugins", "input", "form", "inputmask", "mask"],
   "homepage": "http://robinherbots.github.io/jquery.inputmask",

+ 58 - 43
js/inputmask.js

@@ -11,7 +11,7 @@
 	} else if (typeof exports === "object") {
 		module.exports = factory(require("./dependencyLibs/inputmask.dependencyLib"), require("../global/window"), require("../global/document"));
 	} else {
-		factory(window.dependencyLib || jQuery, window, document);
+		window.Inputmask = factory(window.dependencyLib || jQuery, window, document);
 	}
 }
 (function ($, window, document, undefined) {
@@ -105,8 +105,9 @@
 			//specify keyCodes which should not be considered in the keypress event, otherwise the preventDefault will stop their default behavior especially in FF
 			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, 0, 229],
 			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, currentResult, opts => return true/false
+			canClearPosition: $.noop, //hook to alter the clear behavior in the stripValidPositions args => maskset, position, lastValidPosition, opts => return true|false/command object
+			preValidation: null, //hook to preValidate the input.  Usefull for validating regardless the definition.	args => buffer, pos, char, opts => return true/false/command object
+			postValidation: null, //hook to postValidate the result from isValid.	Usefull for validating the entry as a whole.	args => buffer, currentResult, opts => return true/false/json
 			staticDefinitionSymbol: undefined, //specify a definitionSymbol for static content, used to make matches for alternators
 			jitMasking: false, //just in time masking ~ only mask while typing, can n (number), true or false
 			nullable: true, //return nothing instead of the buffertemplate when the user hasn't entered anything.
@@ -1214,7 +1215,7 @@
 		}
 
 		function refreshFromBuffer(start, end, buffer) {
-			var i;
+			var i, p;
 			if (start === true) {
 				resetMaskSet();
 				start = 0;
@@ -1224,10 +1225,15 @@
 					delete getMaskSet().validPositions[i];
 				}
 			}
+			p = start;
 			for (i = start; i < end; i++) {
 				resetMaskSet(true); //prevents clobber from the buffer
 				if (buffer[i] !== opts.skipOptionalPartCharacter) {
-					isValid(i, buffer[i], true, true);
+					var valResult = isValid(p, buffer[i], true, true);
+					if (valResult !== false) {
+						resetMaskSet(true);
+						p = valResult.caret !== undefined ? valResult.caret : valResult.pos + 1;
+					}
 				}
 			}
 		}
@@ -1306,10 +1312,10 @@
 						//return is false or a json object => { pos: ??, c: ??} or true
 						rslt = test.fn != null ?
 							test.fn.test(chrs, getMaskSet(), position, strict, opts, isSelection(pos)) : (c === test.def || c === opts.skipOptionalPartCharacter) && test.def !== "" ? //non mask
-						{
-							c: getPlaceholder(position, test, true) || test.def,
-							pos: position
-						} : false;
+							{
+								c: getPlaceholder(position, test, true) || test.def,
+								pos: position
+							} : false;
 
 						if (rslt !== false) {
 							var elem = rslt.c !== undefined ? rslt.c : c;
@@ -1599,46 +1605,56 @@
 				}
 			}
 
-			var result = false,
+			var result = true,
 				positionsClone = $.extend(true, {}, getMaskSet().validPositions); //clone the currentPositions
 
-			fillMissingNonMask(maskPos);
-
-			if (isSelection(pos)) {
-				handleRemove(undefined, Inputmask.keyCode.DELETE, pos);
-				maskPos = getMaskSet().p;
+			if ($.isFunction(opts.preValidation) && !strict && fromSetValid !== true) {
+				result = opts.preValidation(getBuffer(), pos.begin, c, opts);
 			}
+			if (result === true) {
+				fillMissingNonMask(maskPos);
 
-			if (maskPos < getMaskSet().maskLength) {
-				result = _isValid(maskPos, c, strict);
-				if ((!strict || fromSetValid === true) && result === false) {
-					var currentPosValid = getMaskSet().validPositions[maskPos];
-					if (currentPosValid && currentPosValid.match.fn === null && (currentPosValid.match.def === c || c === opts.skipOptionalPartCharacter)) {
-						result = {
-							"caret": seekNext(maskPos)
-						};
-					} else if ((opts.insertMode || getMaskSet().validPositions[seekNext(maskPos)] === undefined) && !isMask(maskPos, true)) { //does the input match on a further position?
-						for (var nPos = maskPos + 1, snPos = seekNext(maskPos); nPos <= snPos; nPos++) {
-							result = _isValid(nPos, c, strict);
-							if (result !== false) {
-								trackbackAlternations(maskPos, result.pos !== undefined ? result.pos : nPos);
-								maskPos = nPos;
-								break;
+				if (isSelection(pos)) {
+					handleRemove(undefined, Inputmask.keyCode.DELETE, pos);
+					maskPos = getMaskSet().p;
+				}
+
+				if (maskPos < getMaskSet().maskLength) {
+					result = _isValid(maskPos, c, strict);
+					if ((!strict || fromSetValid === true) && result === false) {
+						var currentPosValid = getMaskSet().validPositions[maskPos];
+						if (currentPosValid && currentPosValid.match.fn === null && (currentPosValid.match.def === c || c === opts.skipOptionalPartCharacter)) {
+							result = {
+								"caret": seekNext(maskPos)
+							};
+						} else if ((opts.insertMode || getMaskSet().validPositions[seekNext(maskPos)] === undefined) && !isMask(maskPos, true)) { //does the input match on a further position?
+							for (var nPos = maskPos + 1, snPos = seekNext(maskPos); nPos <= snPos; nPos++) {
+								result = _isValid(nPos, c, strict);
+								if (result !== false) {
+									trackbackAlternations(maskPos, result.pos !== undefined ? result.pos : nPos);
+									maskPos = nPos;
+									break;
+								}
 							}
 						}
 					}
 				}
-			}
-			if (result === false && opts.keepStatic && !strict && fromAlternate !== true) { //try fuzzy alternator logic
-				result = alternate(maskPos, c, strict);
-			}
-			if (result === true) {
-				result = {
-					"pos": maskPos
-				};
+				if (result === false && opts.keepStatic && !strict && fromAlternate !== true) { //try fuzzy alternator logic
+					result = alternate(maskPos, c, strict);
+				}
+				if (result === true) {
+					result = {
+						"pos": maskPos
+					};
+				}
 			}
 			if ($.isFunction(opts.postValidation) && result !== false && !strict && fromSetValid !== true) {
-				result = opts.postValidation(getBuffer(true), result, opts) ? result : false;
+				var postResult = opts.postValidation(getBuffer(true), result, opts);
+				if (postResult.refreshFromBuffer && postResult.buffer) {
+					var refresh = postResult.refreshFromBuffer;
+					refreshFromBuffer(refresh === true ? refresh : refresh.start, refresh.end, postResult.buffer);
+				}
+				result = postResult === true ? result : postResult;
 			}
 
 			if (result.pos === undefined) {
@@ -1792,7 +1808,7 @@
 
 			$.each(inputValue, function (ndx, charCode) {
 				if (charCode !== undefined) { //inputfallback strips some elements out of the inputarray.  $.each logically presents them as undefined
-					var keypress = new $.Event("keypress");
+					var keypress = new $.Event("_checkval");
 					keypress.which = charCode.charCodeAt(0);
 					charCodes += charCode;
 					var lvp = getLastValidPosition(undefined, true),
@@ -2854,6 +2870,8 @@
 				return isSupported;
 			}
 
+			//unbind all events - to make sure that no other mask will interfere when re-masking
+			EventRuler.off(elem);
 			var isSupported = isElementTypeSupported(elem, opts);
 			if (isSupported !== false) {
 				el = elem;
@@ -2887,8 +2905,6 @@
 					}
 				}
 
-				//unbind all events - to make sure that no other mask will interfere when re-masking
-				EventRuler.off(el);
 				if (isSupported === true) {
 					//bind events
 					EventRuler.on(el, "submit", EventHandlers.submitEvent);
@@ -3049,6 +3065,5 @@
 	}
 
 //make inputmask available
-	window.Inputmask = Inputmask;
 	return Inputmask;
 }));

+ 1 - 1
package.json

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