浏览代码

add backspace detection in inputevent fix #1090

Robin Herbots 10 年之前
父节点
当前提交
fc5a7ebaf2

+ 1 - 0
CHANGELOG.md

@@ -13,6 +13,7 @@ All notable changes to this project will be documented in this file.
 - improve extendAliases, extendDefinitions, extendDefaults
 
 ### Fixed
+- Cannot erase input value throw mask symbols (Android 4.4, Android 4.2) #1090
 - CTRL-x / Cut issue #948
 - Double "Change" action when pressing Enter in Firefox #1070
 - upper/lower case handling in data-inputmask-* #1079

+ 5 - 27
bower.json

@@ -1,38 +1,16 @@
 {
   "name": "jquery.inputmask",
-  "version": "3.2.3-20",
+  "version": "3.2.3-21",
   "main": [
-    "./dist/inputmask/inputmask.dependencyLib.jquery.js",
-    "./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/jquery.inputmask.bundle.js",
-    "./extra/dependencyLibs/inputmask.dependencyLib.jqlite.js",
-    "./extra/dependencyLibs/inputmask.dependencyLib.js",
-    "./extra/phone-codes/phone-be.js",
-    "./extra/phone-codes/phone-codes.js",
-    "./extra/phone-codes/phone-nl.js",
-    "./extra/phone-codes/phone-ru.js",
-    "./extra/phone-codes/phone-uk.js"
+    "./dist/inputmask/inputmask.js"
   ],
   "keywords": ["jquery", "plugins", "input", "form", "inputmask", "mask"],
   "description": "jquery.inputmask is a jquery plugin which create an input mask.",
   "license": "http://opensource.org/licenses/mit-license.php",
   "ignore": [
-    "**/.*",
-    "qunit/",
-    "nuspecs/",
-    "tools/",
-    "js/",
-    "*.md",
-    "package.json",
-    "component.json",
-    "composer.json",
-    "*.js"
+    "*",
+    "!dist/*",
+    "!extra/*"
   ],
   "dependencies": {
     "jquery": ">=1.7"

+ 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.3-20",
+  "version": "3.2.3-21",
   "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.3-20",
+  "version": "3.2.3-21",
   "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.3-20
+* Version: 3.2.3-21
 */
 !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(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.3-20
+* Version: 3.2.3-21
 */
 !function(factory) {
     "function" == typeof define && define.amd ? define([ "jquery" ], factory) : "object" == typeof exports ? module.exports = factory(require("jquery")) : factory(jQuery);

+ 1 - 1
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.3-20
+* Version: 3.2.3-21
 */
 !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(jQuery, window.Inputmask);

文件差异内容过多而无法显示
+ 12 - 4
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.3-20
+* Version: 3.2.3-21
 */
 !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(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.3-20
+* Version: 3.2.3-21
 */
 !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);

+ 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.3-20
+* Version: 3.2.3-21
 */
 !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(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.3-20
+* Version: 3.2.3-21
 */
 !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);

文件差异内容过多而无法显示
+ 12 - 4
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.3-20
+* Version: 3.2.3-21
 */
 !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});

文件差异内容过多而无法显示
+ 1 - 1
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


+ 29 - 7
js/inputmask.js

@@ -714,10 +714,10 @@
 
 		var ua = navigator.userAgent,
 			iphone = ua.match(new RegExp("iphone", "i")) !== null,
-			// android = ua.match(new RegExp("android.*safari.*", "i")) !== null,
+			android = ua.match(new RegExp("android.*safari.*", "i")) !== null,
 			androidchrome = ua.match(new RegExp("android.*chrome.*", "i")) !== null,
 			androidfirefox = ua.match(new RegExp("android.*firefox.*", "i")) !== null,
-			// 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),
+			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";
 
 		//if (androidchrome) {
@@ -2270,6 +2270,28 @@
 				e.preventDefault();
 			}
 
+			function mobileInputEvent(e) {
+				var input = this;
+
+				//backspace in chrome32 only fires input event - detect & treat
+				var caretPos = caret(input),
+					currentValue = input._valueGet();
+
+				currentValue = currentValue.replace(new RegExp("(" + escapeRegex(getBufferTemplate().join("")) + ")*"), "");
+				//correct caretposition for chrome
+				if (caretPos.begin > currentValue.length) {
+					caret(input, currentValue.length);
+					caretPos = caret(input);
+				}
+				if ((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 = opts.keyCode.BACKSPACE;
+					keydownEvent.call(input, e);
+				} else {
+					inputFallBackEvent.call(this, e);
+				}
+				e.preventDefault();
+			}
+
 			function compositionStartEvent(e) {
 				var ev = e.originalEvent || e;
 				undoValue = getBuffer().join("");
@@ -2407,7 +2429,7 @@
 				var clipboardData = window.clipboardData || ev.clipboardData,
 					clipData = isRTL ? getBuffer().slice(pos.end, pos.begin) : getBuffer().slice(pos.begin, pos.end);
 				clipboardData.setData("text", isRTL ? clipData.reverse().join("") : clipData.join(""));
-				if(document.execCommand) document.execCommand("copy"); // copy selected content to system clipbaord
+				if (document.execCommand) document.execCommand("copy"); // copy selected content to system clipbaord
 
 				handleRemove(input, Inputmask.keyCode.DELETE, pos);
 				writeBuffer(input, getBuffer(), getMaskSet().p, e, undoValue !== getBuffer().join(""));
@@ -2538,10 +2560,10 @@
 					if (PasteEventType === "paste") {
 						$el.on("input.inputmask", wrapEventRuler(inputFallBackEvent));
 					}
-					//if (android || androidfirefox || androidchrome || kindle) {
-					//		$el.off("input.inputmask");
-					//		$el.on("input.inputmask", mobileInputEvent);
-					//}
+					if (android || androidfirefox || androidchrome || kindle) {
+						$el.off("input.inputmask");
+						$el.on("input.inputmask", wrapEventRuler(mobileInputEvent));
+					}
 				}
 				$el.on("setvalue.inputmask", wrapEventRuler(setValueEvent));
 

+ 1 - 1
package.json

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