浏览代码

Each character repeats on Mobile fix #912

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

+ 2 - 0
CHANGELOG.md

@@ -7,9 +7,11 @@ All notable changes to this project will be documented in this file.
 - Add tooltip option
 
 ### Updates
+- Improve handling of compositionevents
 - improve extendAliases, extendDefinitions, extendDefaults
 
 ### Fixed
+- Each character repeats on Mobile #912
 - extra tooltip property #1071
 - Numeric aliases insert '0' in input after clearing if there was fraction part #1067
 - Clear optional tail in getvalue. See #1055 #1065

+ 1 - 1
bower.json

@@ -1,6 +1,6 @@
 {
   "name": "jquery.inputmask",
-  "version": "3.2.3-8",
+  "version": "3.2.3-9",
   "main": [
     "./dist/inputmask/inputmask.dependencyLib.jquery.js",
     "./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.3-8",
+  "version": "3.2.3-9",
   "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-8",
+  "version": "3.2.3-9",
   "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-8
+* Version: 3.2.3-9
 */
 !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-8
+* Version: 3.2.3-9
 */
 !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-8
+* Version: 3.2.3-9
 */
 !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);

+ 14 - 14
dist/inputmask/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-8
+* Version: 3.2.3-9
 */
 !function(factory) {
     "function" == typeof define && define.amd ? define([ "inputmask.dependencyLib" ], factory) : "object" == typeof exports ? module.exports = factory(require("./inputmask.dependencyLib.jquery")) : factory(window.dependencyLib || jQuery);
@@ -767,7 +767,7 @@
         }
         function wrapEventRuler(eventHandler) {
             return function(e) {
-                var inComposition = !1;
+                var inComposition = !1, keydownPressed = !1;
                 if (void 0 === this.inputmask) {
                     var imOpts = $.data(this, "_inputmask_opts");
                     imOpts ? new Inputmask(imOpts).mask(this) : $(this).off(".inputmask");
@@ -776,10 +776,11 @@
                         switch (e.type) {
                           case "input":
                             if (skipInputEvent === !0 || inComposition === !0) return skipInputEvent = !1, e.preventDefault();
+                            keydownPressed = !1;
                             break;
 
                           case "keydown":
-                            skipKeyPressEvent = !1, inComposition = !1;
+                            skipKeyPressEvent = !1, inComposition = !1, keydownPressed = !0;
                             break;
 
                           case "keypress":
@@ -792,11 +793,11 @@
                             break;
 
                           case "compositionupdate":
-                            skipInputEvent = !0;
+                            skipInputEvent = keydownPressed;
                             break;
 
                           case "compositionend":
-                            inComposition = !1;
+                            inComposition = !1, keydownPressed = !1;
                         }
                         return eventHandler.apply(this, arguments);
                     }
@@ -986,18 +987,17 @@
             e.preventDefault();
         }
         function compositionStartEvent(e) {
-            var input = this;
-            undoValue = getBuffer().join(""), ("" === compositionData || 0 !== e.originalEvent.data.indexOf(compositionData)) && (compositionCaretPos = caret(input));
+            undoValue = getBuffer().join(""), "" === compositionData || 0 !== e.originalEvent.data.indexOf(compositionData);
         }
         function compositionUpdateEvent(e) {
-            var input = this, caretPos = caret(input);
-            0 === e.originalEvent.data.indexOf(compositionData) && (resetMaskSet(), caretPos = compositionCaretPos);
-            var newData = e.originalEvent.data;
-            caret(input, caretPos.begin, caretPos.end);
-            for (var i = 0; i < newData.length; i++) {
+            var input = this;
+            caret(input);
+            0 === e.originalEvent.data.indexOf(compositionData) && (resetMaskSet(), getMaskSet().p = seekNext(-1), 
+            skipInputEvent = !0);
+            for (var newData = e.originalEvent.data, i = 0; i < newData.length; i++) {
                 var keypress = $.Event("keypress");
                 keypress.which = newData.charCodeAt(i), skipKeyPressEvent = !1, ignorable = !1, 
-                keypressEvent.call(input, keypress);
+                keypressEvent.call(input, keypress, !0, !1, !1, getMaskSet().p);
             }
             setTimeout(function() {
                 var forwardPosition = getMaskSet().p;
@@ -1112,7 +1112,7 @@
             isComplete(buffer) === !1 && opts.clearIncomplete && resetMaskSet(), opts.clearMaskOnLostFocus && (buffer.join("") === getBufferTemplate().join("") ? buffer = [] : clearOptionalTail(buffer)), 
             writeBuffer(el, buffer), activeElement === el && caret(el, seekNext(getLastValidPosition()));
         }
-        var undoValue, compositionCaretPos, compositionData, el, $el, maxLength, valueBuffer, isRTL = !1, skipKeyPressEvent = !1, skipInputEvent = !1, ignorable = !1, mouseEnter = !0;
+        var undoValue, compositionData, el, $el, maxLength, valueBuffer, isRTL = !1, skipKeyPressEvent = !1, skipInputEvent = !1, ignorable = !1, mouseEnter = !0;
         if (void 0 !== actionObj) switch (actionObj.action) {
           case "isComplete":
             return el = actionObj.el, isComplete(getBuffer());

+ 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-8
+* Version: 3.2.3-9
 */
 !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-8
+* Version: 3.2.3-9
 */
 !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-8
+* Version: 3.2.3-9
 */
 !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-8
+* Version: 3.2.3-9
 */
 !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);

+ 14 - 14
dist/jquery.inputmask.bundle.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-8
+* Version: 3.2.3-9
 */
 !function($) {
     function Inputmask(alias, options) {
@@ -765,7 +765,7 @@
         }
         function wrapEventRuler(eventHandler) {
             return function(e) {
-                var inComposition = !1;
+                var inComposition = !1, keydownPressed = !1;
                 if (void 0 === this.inputmask) {
                     var imOpts = $.data(this, "_inputmask_opts");
                     imOpts ? new Inputmask(imOpts).mask(this) : $(this).off(".inputmask");
@@ -774,10 +774,11 @@
                         switch (e.type) {
                           case "input":
                             if (skipInputEvent === !0 || inComposition === !0) return skipInputEvent = !1, e.preventDefault();
+                            keydownPressed = !1;
                             break;
 
                           case "keydown":
-                            skipKeyPressEvent = !1, inComposition = !1;
+                            skipKeyPressEvent = !1, inComposition = !1, keydownPressed = !0;
                             break;
 
                           case "keypress":
@@ -790,11 +791,11 @@
                             break;
 
                           case "compositionupdate":
-                            skipInputEvent = !0;
+                            skipInputEvent = keydownPressed;
                             break;
 
                           case "compositionend":
-                            inComposition = !1;
+                            inComposition = !1, keydownPressed = !1;
                         }
                         return eventHandler.apply(this, arguments);
                     }
@@ -984,18 +985,17 @@
             e.preventDefault();
         }
         function compositionStartEvent(e) {
-            var input = this;
-            undoValue = getBuffer().join(""), ("" === compositionData || 0 !== e.originalEvent.data.indexOf(compositionData)) && (compositionCaretPos = caret(input));
+            undoValue = getBuffer().join(""), "" === compositionData || 0 !== e.originalEvent.data.indexOf(compositionData);
         }
         function compositionUpdateEvent(e) {
-            var input = this, caretPos = caret(input);
-            0 === e.originalEvent.data.indexOf(compositionData) && (resetMaskSet(), caretPos = compositionCaretPos);
-            var newData = e.originalEvent.data;
-            caret(input, caretPos.begin, caretPos.end);
-            for (var i = 0; i < newData.length; i++) {
+            var input = this;
+            caret(input);
+            0 === e.originalEvent.data.indexOf(compositionData) && (resetMaskSet(), getMaskSet().p = seekNext(-1), 
+            skipInputEvent = !0);
+            for (var newData = e.originalEvent.data, i = 0; i < newData.length; i++) {
                 var keypress = $.Event("keypress");
                 keypress.which = newData.charCodeAt(i), skipKeyPressEvent = !1, ignorable = !1, 
-                keypressEvent.call(input, keypress);
+                keypressEvent.call(input, keypress, !0, !1, !1, getMaskSet().p);
             }
             setTimeout(function() {
                 var forwardPosition = getMaskSet().p;
@@ -1110,7 +1110,7 @@
             isComplete(buffer) === !1 && opts.clearIncomplete && resetMaskSet(), opts.clearMaskOnLostFocus && (buffer.join("") === getBufferTemplate().join("") ? buffer = [] : clearOptionalTail(buffer)), 
             writeBuffer(el, buffer), activeElement === el && caret(el, seekNext(getLastValidPosition()));
         }
-        var undoValue, compositionCaretPos, compositionData, el, $el, maxLength, valueBuffer, isRTL = !1, skipKeyPressEvent = !1, skipInputEvent = !1, ignorable = !1, mouseEnter = !0;
+        var undoValue, compositionData, el, $el, maxLength, valueBuffer, isRTL = !1, skipKeyPressEvent = !1, skipInputEvent = !1, ignorable = !1, mouseEnter = !0;
         if (void 0 !== actionObj) switch (actionObj.action) {
           case "isComplete":
             return el = actionObj.el, isComplete(getBuffer());

文件差异内容过多而无法显示
+ 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-8
+* Version: 3.2.3-9
 */
 !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


+ 12 - 6
js/inputmask.js

@@ -1800,7 +1800,8 @@
 			function wrapEventRuler(eventHandler) {
 				return function(e) {
 					// console.log("triggered " + e.type);
-					var inComposition = false;
+					var inComposition = false,
+						keydownPressed = false;
 					if (this.inputmask === undefined) { //happens when cloning an object with jquery.clone
 						var imOpts = $.data(this, "_inputmask_opts");
 						if (imOpts)(new Inputmask(imOpts)).mask(this);
@@ -1814,11 +1815,13 @@
 									skipInputEvent = false;
 									return e.preventDefault();
 								}
+								keydownPressed = false;
 								break;
 							case "keydown":
 								//Safari 5.1.x - modal dialog fires keypress twice workaround
 								skipKeyPressEvent = false;
 								inComposition = false;
+								keydownPressed = true;
 								break;
 							case "keypress":
 								if (skipKeyPressEvent === true) {
@@ -1831,10 +1834,11 @@
 								inComposition = true;
 								break;
 							case "compositionupdate":
-								skipInputEvent = true;
+								skipInputEvent = keydownPressed;
 								break;
 							case "compositionend":
 								inComposition = false;
+								keydownPressed = false;
 								break;
 						}
 						//console.log("executed " + e.type);
@@ -2254,7 +2258,7 @@
 				var input = this;
 				undoValue = getBuffer().join("");
 				if (compositionData === "" || e.originalEvent.data.indexOf(compositionData) !== 0) {
-					compositionCaretPos = caret(input);
+					// compositionCaretPos = caret(input);
 				}
 			}
 
@@ -2263,16 +2267,18 @@
 					caretPos = caret(input);
 				if (e.originalEvent.data.indexOf(compositionData) === 0) {
 					resetMaskSet();
-					caretPos = compositionCaretPos;
+					getMaskSet().p = seekNext(-1); //needs check
+					skipInputEvent = true;
+					// caretPos = compositionCaretPos;
 				}
 				var newData = e.originalEvent.data;
-				caret(input, caretPos.begin, caretPos.end);
+				// caret(input, caretPos.begin, caretPos.end);
 				for (var i = 0; i < newData.length; i++) {
 					var keypress = $.Event("keypress");
 					keypress.which = newData.charCodeAt(i);
 					skipKeyPressEvent = false;
 					ignorable = false;
-					keypressEvent.call(input, keypress); //needs update
+					keypressEvent.call(input, keypress, true, false, false, getMaskSet().p); //needs check
 				}
 				setTimeout(function() {
 					var forwardPosition = getMaskSet().p;

+ 1 - 1
package.json

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