ソースを参照

experimental commit for composition events in android #747 #653 #745

Robin Herbots 11 年 前
コミット
be0fb7bfc8

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

@@ -551,9 +551,7 @@
                 } else keypressEvent.call(input, keypress, !0, !1, !0, lvp + 1);
             }), writeOut) {
                 var keypressResult = opts.onKeyPress.call(this, void 0, getBuffer(), 0, opts);
-                handleOnKeyResult(input, keypressResult);
-                var forwardPosition = getMaskSet().p;
-                writeBuffer(input, getBuffer(), $(input).is(":focus") ? opts.numericInput ? seekPrevious(forwardPosition) : forwardPosition : void 0);
+                handleOnKeyResult(input, keypressResult), writeBuffer(input, getBuffer(), $(input).is(":focus") ? seekNext(getLastValidPosition(0)) : void 0);
             }
         }
         function escapeRegex(str) {
@@ -658,6 +656,7 @@
                                     break;
 
                                   case "compositionupdate":
+                                  case "compositionend":
                                     skipInputEvent = !0;
                                 }
                                 return handler.apply(this, arguments);
@@ -850,15 +849,16 @@
             checkVal(input, !0, !1), isComplete(getBuffer()) === !0 && $(input).trigger("complete"), 
             e.preventDefault();
         }
-        function compositionupdateEvent(e) {
-            var input = this;
+        function compositionEndEvent(e) {
+            var input = this, caretPos = caret(input);
             return setTimeout(function() {
-                caret(input, caret(input).begin - 1);
-                var keypress = $.Event("keypress");
-                keypress.which = e.originalEvent.data.charCodeAt(0), skipKeyPressEvent = !1, ignorable = !1, 
-                keypressEvent.call(input, keypress, void 0, void 0, !1);
-                var forwardPosition = getMaskSet().p;
-                writeBuffer(input, getBuffer(), opts.numericInput ? seekPrevious(forwardPosition) : forwardPosition);
+                var newData = e.originalEvent.data;
+                caret(input, caretPos.begin - 1, caretPos.end);
+                for (var i = 0; i < newData.length; i++) {
+                    var keypress = $.Event("keypress");
+                    keypress.which = newData.charCodeAt(i), skipKeyPressEvent = !1, ignorable = !1, 
+                    keypressEvent.call(input, keypress);
+                }
             }, 0), !1;
         }
         function mask(el) {
@@ -939,8 +939,8 @@
                     opts.showTooltip && $input.prop("title", getMaskSet().mask);
                 }).bind("complete.inputmask", opts.oncomplete).bind("incomplete.inputmask", opts.onincomplete).bind("cleared.inputmask", opts.oncleared), 
                 $el.bind("keydown.inputmask", keydownEvent).bind("keypress.inputmask", keypressEvent).bind("keyup.inputmask", keyupEvent).bind("compositionstart.inputmask", function() {
-                    undoValue = getBuffer().join(""), compositionUpdateData = "";
-                }).bind("compositionupdate.inputmask", compositionupdateEvent).bind("compositionend.inputmask", function() {}), 
+                    undoValue = getBuffer().join("");
+                }).bind("compositionupdate.inputmask", function() {}).bind("compositionend.inputmask", compositionEndEvent), 
                 "paste" === PasteEventType && $el.bind("input.inputmask", inputFallBackEvent), patchValueProperty(el);
                 var initialValue = $.isFunction(opts.onBeforeMask) ? opts.onBeforeMask.call(el, el._valueGet(), opts) || el._valueGet() : el._valueGet();
                 checkVal(el, !0, !1, initialValue.split(""));
@@ -955,7 +955,7 @@
                 installEventRuler(el);
             }
         }
-        var undoValue, compositionUpdateData, $el, maxLength, isRTL = !1, skipKeyPressEvent = !1, skipInputEvent = !1, ignorable = !1, firstClick = !0;
+        var undoValue, $el, maxLength, isRTL = !1, skipKeyPressEvent = !1, skipInputEvent = !1, ignorable = !1, firstClick = !0;
         if (void 0 != actionObj) switch (actionObj.action) {
           case "isComplete":
             return $el = $(actionObj.el), maskset = $el.data("_inputmask").maskset, opts = $el.data("_inputmask").opts, 

+ 14 - 14
dist/jquery.inputmask.bundle.js

@@ -549,9 +549,7 @@
                 } else keypressEvent.call(input, keypress, !0, !1, !0, lvp + 1);
             }), writeOut) {
                 var keypressResult = opts.onKeyPress.call(this, void 0, getBuffer(), 0, opts);
-                handleOnKeyResult(input, keypressResult);
-                var forwardPosition = getMaskSet().p;
-                writeBuffer(input, getBuffer(), $(input).is(":focus") ? opts.numericInput ? seekPrevious(forwardPosition) : forwardPosition : void 0);
+                handleOnKeyResult(input, keypressResult), writeBuffer(input, getBuffer(), $(input).is(":focus") ? seekNext(getLastValidPosition(0)) : void 0);
             }
         }
         function escapeRegex(str) {
@@ -656,6 +654,7 @@
                                     break;
 
                                   case "compositionupdate":
+                                  case "compositionend":
                                     skipInputEvent = !0;
                                 }
                                 return handler.apply(this, arguments);
@@ -848,15 +847,16 @@
             checkVal(input, !0, !1), isComplete(getBuffer()) === !0 && $(input).trigger("complete"), 
             e.preventDefault();
         }
-        function compositionupdateEvent(e) {
-            var input = this;
+        function compositionEndEvent(e) {
+            var input = this, caretPos = caret(input);
             return setTimeout(function() {
-                caret(input, caret(input).begin - 1);
-                var keypress = $.Event("keypress");
-                keypress.which = e.originalEvent.data.charCodeAt(0), skipKeyPressEvent = !1, ignorable = !1, 
-                keypressEvent.call(input, keypress, void 0, void 0, !1);
-                var forwardPosition = getMaskSet().p;
-                writeBuffer(input, getBuffer(), opts.numericInput ? seekPrevious(forwardPosition) : forwardPosition);
+                var newData = e.originalEvent.data;
+                caret(input, caretPos.begin - 1, caretPos.end);
+                for (var i = 0; i < newData.length; i++) {
+                    var keypress = $.Event("keypress");
+                    keypress.which = newData.charCodeAt(i), skipKeyPressEvent = !1, ignorable = !1, 
+                    keypressEvent.call(input, keypress);
+                }
             }, 0), !1;
         }
         function mask(el) {
@@ -937,8 +937,8 @@
                     opts.showTooltip && $input.prop("title", getMaskSet().mask);
                 }).bind("complete.inputmask", opts.oncomplete).bind("incomplete.inputmask", opts.onincomplete).bind("cleared.inputmask", opts.oncleared), 
                 $el.bind("keydown.inputmask", keydownEvent).bind("keypress.inputmask", keypressEvent).bind("keyup.inputmask", keyupEvent).bind("compositionstart.inputmask", function() {
-                    undoValue = getBuffer().join(""), compositionUpdateData = "";
-                }).bind("compositionupdate.inputmask", compositionupdateEvent).bind("compositionend.inputmask", function() {}), 
+                    undoValue = getBuffer().join("");
+                }).bind("compositionupdate.inputmask", function() {}).bind("compositionend.inputmask", compositionEndEvent), 
                 "paste" === PasteEventType && $el.bind("input.inputmask", inputFallBackEvent), patchValueProperty(el);
                 var initialValue = $.isFunction(opts.onBeforeMask) ? opts.onBeforeMask.call(el, el._valueGet(), opts) || el._valueGet() : el._valueGet();
                 checkVal(el, !0, !1, initialValue.split(""));
@@ -953,7 +953,7 @@
                 installEventRuler(el);
             }
         }
-        var undoValue, compositionUpdateData, $el, maxLength, isRTL = !1, skipKeyPressEvent = !1, skipInputEvent = !1, ignorable = !1, firstClick = !0;
+        var undoValue, $el, maxLength, isRTL = !1, skipKeyPressEvent = !1, skipInputEvent = !1, ignorable = !1, firstClick = !0;
         if (void 0 != actionObj) switch (actionObj.action) {
           case "isComplete":
             return $el = $(actionObj.el), maskset = $el.data("_inputmask").maskset, opts = $el.data("_inputmask").opts, 

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


+ 37 - 43
js/jquery.inputmask.js

@@ -331,7 +331,6 @@
         function maskScope(actionObj, maskset, opts) {
             var isRTL = false,
                 undoValue,
-                compositionUpdateData,
                 $el,
                 skipKeyPressEvent = false, //Safari 5.1.x - modal dialog fires keypress twice workaround
                 skipInputEvent = false, //skip when triggered from within inputmask
@@ -984,9 +983,7 @@
                 if (writeOut) {
                     var keypressResult = opts.onKeyPress.call(this, undefined, getBuffer(), 0, opts);
                     handleOnKeyResult(input, keypressResult);
-                    //writeBuffer(input, getBuffer(), $(input).is(":focus") ? seekNext(getLastValidPosition(0)) : undefined);
-                    var forwardPosition = getMaskSet()["p"];
-                    writeBuffer(input, getBuffer(), $(input).is(":focus") ? (opts.numericInput ? seekPrevious(forwardPosition) : forwardPosition) : undefined);
+                    writeBuffer(input, getBuffer(), $(input).is(":focus") ? seekNext(getLastValidPosition(0)) : undefined);
                 }
             }
             function escapeRegex(str) {
@@ -1146,7 +1143,7 @@
                                                     return e.preventDefault;
                                                 skipKeyPressEvent = true;
                                                 break;
-                                            case "compositionupdate":
+                                            case "compositionupdate": case "compositionend":
                                                 skipInputEvent = true; //stop inutFallback
                                                 break;
                                         }
@@ -1508,27 +1505,27 @@
 
                 return false;
             }
-            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 = $.inputmask.keyCode.BACKSPACE;
-                    keydownEvent.call(input, e);
-                }
-                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 = $.inputmask.keyCode.BACKSPACE;
+            //        keydownEvent.call(input, e);
+            //    }
+            //    e.preventDefault();
+            //}
             function inputFallBackEvent(e) { //fallback when keypress & compositionevents fail
                 var input = this;
                 checkVal(input, true, false);
@@ -1540,18 +1537,18 @@
 
                 e.preventDefault();
             }
-            function compositionupdateEvent(e) { //fix for special latin-charset FF/Linux
-                //console.log(e.originalEvent.data + " vs " + compositionUpdateData);
-                var input = this;
+            function compositionEndEvent(e) {
+                var input = this, caretPos = caret(input);
                 setTimeout(function () {
-                    caret(input, caret(input).begin - 1);
-                    var keypress = $.Event("keypress");
-                    keypress.which = e.originalEvent.data.charCodeAt(0);
-                    skipKeyPressEvent = false;
-                    ignorable = false;
-                    keypressEvent.call(input, keypress, undefined, undefined, false);
-                    var forwardPosition = getMaskSet()["p"];
-                    writeBuffer(input, getBuffer(), opts.numericInput ? seekPrevious(forwardPosition) : forwardPosition);
+                    var newData = e.originalEvent.data;
+                    caret(input, caretPos.begin - 1, 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);
+                    }
                 }, 0);
                 return false;
             }
@@ -1721,12 +1718,9 @@
                     ).bind("keyup.inputmask", keyupEvent
                     ).bind("compositionstart.inputmask", function (e) {
                         undoValue = getBuffer().join('');
-                        //init compositionUpdateData
-                        compositionUpdateData = "";
-                    }).bind("compositionupdate.inputmask", compositionupdateEvent
-                    ).bind("compositionend.inputmask", function (e) {
-
-                    });
+                    }).bind("compositionupdate.inputmask", function (e) {
+                        
+                    }).bind("compositionend.inputmask", compositionEndEvent);
 
                     if (PasteEventType === "paste") {
                         $el.bind("input.inputmask", inputFallBackEvent);