Browse Source

correct paste with rtl

Robin Herbots 11 years ago
parent
commit
b33db329d7

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

@@ -751,8 +751,8 @@
                     return npt.value;
                 }, valueSet = function(value) {
                     npt.value = value;
-                }, PatchValhook(npt.type), InstallNativeValueSetFallback(npt)), npt._valueGet = function() {
-                    return isRTL ? valueGet.call(this).split("").reverse().join("") : valueGet.call(this);
+                }, PatchValhook(npt.type), InstallNativeValueSetFallback(npt)), npt._valueGet = function(overruleRTL) {
+                    return isRTL && overruleRTL !== !0 ? valueGet.call(this).split("").reverse().join("") : valueGet.call(this);
                 }, npt._valueSet = function(value) {
                     valueSet.call(this, isRTL ? value.split("").reverse().join("") : value);
                 };
@@ -860,7 +860,7 @@
             handleOnKeyResult(input, keyupResult, currentCaretPos);
         }
         function pasteEvent(e) {
-            var input = this, $input = $(input), inputValue = input._valueGet(), caretPos = caret(input);
+            var input = this, $input = $(input), inputValue = input._valueGet(!0), caretPos = caret(input);
             if ("propertychange" == e.type && input._valueGet().length <= getMaskLength()) return !0;
             "paste" == e.type && (window.clipboardData && window.clipboardData.getData ? inputValue = inputValue.substr(0, caretPos.begin) + window.clipboardData.getData("Text") + inputValue.substr(caretPos.end, inputValue.length) : e.originalEvent && e.originalEvent.clipboardData && e.originalEvent.clipboardData.getData && (inputValue = inputValue.substr(0, caretPos.begin) + e.originalEvent.clipboardData.getData("text/plain") + inputValue.substr(caretPos.end, inputValue.length)));
             var pasteValue = $.isFunction(opts.onBeforePaste) ? opts.onBeforePaste.call(input, inputValue, opts) || inputValue : inputValue;

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

@@ -749,8 +749,8 @@
                     return npt.value;
                 }, valueSet = function(value) {
                     npt.value = value;
-                }, PatchValhook(npt.type), InstallNativeValueSetFallback(npt)), npt._valueGet = function() {
-                    return isRTL ? valueGet.call(this).split("").reverse().join("") : valueGet.call(this);
+                }, PatchValhook(npt.type), InstallNativeValueSetFallback(npt)), npt._valueGet = function(overruleRTL) {
+                    return isRTL && overruleRTL !== !0 ? valueGet.call(this).split("").reverse().join("") : valueGet.call(this);
                 }, npt._valueSet = function(value) {
                     valueSet.call(this, isRTL ? value.split("").reverse().join("") : value);
                 };
@@ -858,7 +858,7 @@
             handleOnKeyResult(input, keyupResult, currentCaretPos);
         }
         function pasteEvent(e) {
-            var input = this, $input = $(input), inputValue = input._valueGet(), caretPos = caret(input);
+            var input = this, $input = $(input), inputValue = input._valueGet(!0), caretPos = caret(input);
             if ("propertychange" == e.type && input._valueGet().length <= getMaskLength()) return !0;
             "paste" == e.type && (window.clipboardData && window.clipboardData.getData ? inputValue = inputValue.substr(0, caretPos.begin) + window.clipboardData.getData("Text") + inputValue.substr(caretPos.end, inputValue.length) : e.originalEvent && e.originalEvent.clipboardData && e.originalEvent.clipboardData.getData && (inputValue = inputValue.substr(0, caretPos.begin) + e.originalEvent.clipboardData.getData("text/plain") + inputValue.substr(caretPos.end, inputValue.length)));
             var pasteValue = $.isFunction(opts.onBeforePaste) ? opts.onBeforePaste.call(input, inputValue, opts) || inputValue : inputValue;

File diff suppressed because it is too large
+ 1 - 1
dist/jquery.inputmask.bundle.min.js


+ 3 - 3
js/jquery.inputmask.js

@@ -1308,8 +1308,8 @@
                         PatchValhook(npt.type);
                         InstallNativeValueSetFallback(npt);
                     }
-                    npt._valueGet = function () {
-                        return isRTL ? valueGet.call(this).split('').reverse().join('') : valueGet.call(this);
+                    npt._valueGet = function (overruleRTL) {
+                        return isRTL && overruleRTL !== true ? valueGet.call(this).split('').reverse().join('') : valueGet.call(this);
                     };
                     npt._valueSet = function (value) {
                         valueSet.call(this, isRTL ? value.split('').reverse().join('') : value);
@@ -1530,7 +1530,7 @@
                 handleOnKeyResult(input, keyupResult, currentCaretPos);
             }
             function pasteEvent(e) {
-                var input = this, $input = $(input), inputValue = input._valueGet(), caretPos = caret(input);
+                var input = this, $input = $(input), inputValue = input._valueGet(true), caretPos = caret(input);
                 //paste event for IE8 and lower I guess ;-)
                 if (e.type == "propertychange" && input._valueGet().length <= getMaskLength()) {
                     return true;

+ 2 - 2
qunit/simulator.js

@@ -87,8 +87,8 @@
         });
     }
     $.fn.paste = function (inputStr) {
-        var $input = $(this);
-        window.clipboardData ? window.clipboardData.setData("Text", inputStr) : $input[0]._valueSet(inputStr);
+        var $input = $(this), isRTL = $input.data("_inputmask").isRTL;
+        window.clipboardData ? window.clipboardData.setData("Text", inputStr) : $input[0]._valueSet(isRTL ? inputStr.split('').reverse().join('') : inputStr);
         $input.trigger('paste');
     }
 })(jQuery);

+ 17 - 0
qunit/tests_paste.js

@@ -118,4 +118,21 @@ asyncTest("inputmask(\"+31 9999999999\") ~ paste \"+3112345678\" - jason16v", fu
         start();
         $("#testmask").remove();
     }, 0);
+});
+
+asyncTest("99.999.999/9999-99 numericInput ~ paste __-____/..__79100085302751__-____/..__ - imbelo", function () {
+    var $fixture = $("#qunit-fixture");
+    $fixture.append('<input type="text" id="testmask" />');
+    $("#testmask").inputmask({
+        "mask": "99.999.999/9999-99",
+        "numericInput": true
+    });
+    $("#testmask")[0].focus();
+    $("#testmask").paste("__-____/..__79100085302751__-____/..__");
+
+    setTimeout(function () {
+        equal($("#testmask").val(), "79.100.085/3027-51", "Result " + $("#testmask").val());
+        start();
+        $("#testmask").remove();
+    }, 0);
 });