Browse Source

update placeholder stuff && fix paste/input

Robin Herbots 10 years ago
parent
commit
411498346c

+ 4 - 0
CHANGELOG.md

@@ -2,6 +2,10 @@
 All notable changes to this project will be documented in this file.
 
 ## [Unreleased]
+
+### Updates
+- Update placeholder handling
+
 ### Fixed
 - never trigger 'input' event when paste after invoke inputmask #776
 - Script looping start when add '.' between decimal values #870 ('.' part)

+ 1 - 1
bower.json

@@ -1,6 +1,6 @@
 {
   "name": "jquery.inputmask",
-  "version": "3.1.64-1",
+  "version": "3.1.64-8",
   "main": [
     "./dist/inputmask/jquery.inputmask.js",
     "./dist/inputmask/jquery.inputmask.extensions.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.1.64-1",
+    "version": "3.1.64-8",
     "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.1.64-1",
+	"version": "3.1.64-8",
     "type": "library",
     "keywords": ["jquery", "plugins", "input", "form", "inputmask", "mask"],
     "homepage": "http://robinherbots.github.io/jquery.inputmask",

+ 1 - 1
dist/inputmask/jquery.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.1.64-1
+* Version: 3.1.64-8
 */
 !function(factory) {
     "function" == typeof define && define.amd ? define([ "jquery", "./jquery.inputmask" ], factory) : "object" == typeof exports ? module.exports = factory(require("jquery"), require("./jquery.inputmask")) : factory(jQuery);

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


+ 1 - 1
dist/inputmask/jquery.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.1.64-1
+* Version: 3.1.64-8
 */
 !function(factory) {
     "function" == typeof define && define.amd ? define([ "jquery", "./jquery.inputmask" ], factory) : "object" == typeof exports ? module.exports = factory(require("jquery"), require("./jquery.inputmask")) : factory(jQuery);

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


+ 10 - 7
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.1.64-1
+* Version: 3.1.64-8
 */
 !function(factory) {
     "function" == typeof define && define.amd ? define([ "jquery" ], factory) : "object" == typeof exports ? module.exports = factory(require("jquery")) : factory(jQuery);
@@ -596,11 +596,14 @@
             if (test = test || getTest(pos), void 0 != test.placeholder) return test.placeholder;
             if (null == test.fn) {
                 if (!opts.keepStatic && void 0 == getMaskSet().validPositions[pos]) {
-                    for (var tests = getTests(pos), staticAlternations = !0, i = 0; i < tests.length; i++) if ("" != tests[i].match.def && (null !== tests[i].match.fn || void 0 == tests[i].alternation || tests[i].locator[tests[i].alternation].length > 1)) {
-                        staticAlternations = !1;
-                        break;
+                    for (var prevTest, tests = getTests(pos), hasAlternations = !1, i = 0; i < tests.length; i++) {
+                        if (prevTest && "" != tests[i].match.def && tests[i].match.def != prevTest.match.def && (void 0 == tests[i].alternation || tests[i].alternation == prevTest.alternation)) {
+                            hasAlternations = !0;
+                            break;
+                        }
+                        1 != tests[i].match.optionality && 1 != tests[i].match.optionalQuantifier && (prevTest = tests[i]);
                     }
-                    if (staticAlternations) return opts.placeholder.charAt(pos % opts.placeholder.length);
+                    if (hasAlternations) return opts.placeholder.charAt(pos % opts.placeholder.length);
                 }
                 return test.def;
             }
@@ -943,8 +946,8 @@
                 !1;
                 pasteValue || (pasteValue = inputValue);
             }
-            return checkVal(input, !0, !1, isRTL ? pasteValue.split("").reverse() : pasteValue.split("")), 
-            $input.click(), $input.trigger("input"), isComplete(getBuffer()) === !0 && $input.trigger("complete"), 
+            return checkVal(input, !1, !1, isRTL ? pasteValue.split("").reverse() : pasteValue.split("")), 
+            writeBuffer(input, getBuffer(), void 0, e, !0), $input.click(), isComplete(getBuffer()) === !0 && $input.trigger("complete"), 
             !1;
         }
         function inputFallBackEvent(e) {

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


+ 1 - 1
dist/inputmask/jquery.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.1.64-1
+* Version: 3.1.64-8
 */
 !function(factory) {
     "function" == typeof define && define.amd ? define([ "jquery", "./jquery.inputmask" ], factory) : "object" == typeof exports ? module.exports = factory(require("jquery"), require("./jquery.inputmask")) : factory(jQuery);

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


+ 1 - 1
dist/inputmask/jquery.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.1.64-1
+* Version: 3.1.64-8
 */
 !function(factory) {
     "function" == typeof define && define.amd ? define([ "jquery", "./jquery.inputmask" ], factory) : "object" == typeof exports ? module.exports = factory(require("jquery"), require("./jquery.inputmask")) : factory(jQuery);

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


+ 1 - 1
dist/inputmask/jquery.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.1.64-1
+* Version: 3.1.64-8
 */
 !function(factory) {
     "function" == typeof define && define.amd ? define([ "jquery", "./jquery.inputmask" ], factory) : "object" == typeof exports ? module.exports = factory(require("jquery"), require("./jquery.inputmask")) : factory(jQuery);

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


+ 10 - 7
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.1.64-1
+* Version: 3.1.64-8
 */
 !function($) {
     function isInputEventSupported(eventName) {
@@ -594,11 +594,14 @@
             if (test = test || getTest(pos), void 0 != test.placeholder) return test.placeholder;
             if (null == test.fn) {
                 if (!opts.keepStatic && void 0 == getMaskSet().validPositions[pos]) {
-                    for (var tests = getTests(pos), staticAlternations = !0, i = 0; i < tests.length; i++) if ("" != tests[i].match.def && (null !== tests[i].match.fn || void 0 == tests[i].alternation || tests[i].locator[tests[i].alternation].length > 1)) {
-                        staticAlternations = !1;
-                        break;
+                    for (var prevTest, tests = getTests(pos), hasAlternations = !1, i = 0; i < tests.length; i++) {
+                        if (prevTest && "" != tests[i].match.def && tests[i].match.def != prevTest.match.def && (void 0 == tests[i].alternation || tests[i].alternation == prevTest.alternation)) {
+                            hasAlternations = !0;
+                            break;
+                        }
+                        1 != tests[i].match.optionality && 1 != tests[i].match.optionalQuantifier && (prevTest = tests[i]);
                     }
-                    if (staticAlternations) return opts.placeholder.charAt(pos % opts.placeholder.length);
+                    if (hasAlternations) return opts.placeholder.charAt(pos % opts.placeholder.length);
                 }
                 return test.def;
             }
@@ -941,8 +944,8 @@
                 !1;
                 pasteValue || (pasteValue = inputValue);
             }
-            return checkVal(input, !0, !1, isRTL ? pasteValue.split("").reverse() : pasteValue.split("")), 
-            $input.click(), $input.trigger("input"), isComplete(getBuffer()) === !0 && $input.trigger("complete"), 
+            return checkVal(input, !1, !1, isRTL ? pasteValue.split("").reverse() : pasteValue.split("")), 
+            writeBuffer(input, getBuffer(), void 0, e, !0), $input.click(), isComplete(getBuffer()) === !0 && $input.trigger("complete"), 
             !1;
         }
         function inputFallBackEvent(e) {

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


+ 16 - 13
js/jquery.inputmask.js

@@ -1006,15 +1006,15 @@
                 if (test.fn != null)
                     return test.fn
                 else if (!opts.keepStatic && getMaskSet()["validPositions"][pos] == undefined) {
-                    var tests = getTests(pos), staticAlternations = true;
-                    for (var i = 0; i < tests.length; i++) {
-                        if (tests[i].match.def != "" && (/*tests[i].match.fn !== null || */ (tests[i].alternation == undefined || tests[i].locator[tests[i].alternation].length > 1))) {
-                            staticAlternations = false;
-                            break;
+                        var tests = getTests(pos), staticAlternations = true;
+                        for (var i = 0; i < tests.length; i++) {
+                            if (tests[i].match.def != "" && (/*tests[i].match.fn !== null || */ (tests[i].alternation == undefined || tests[i].locator[tests[i].alternation].length > 1))) {
+                                staticAlternations = false;
+                                break;
+                            }
                         }
+                        return staticAlternations;
                     }
-                    return staticAlternations;
-                }
 
                 return false;
             }
@@ -1082,15 +1082,18 @@
                     return test["placeholder"];
                 else if (test["fn"] == null) {
                     if (!opts.keepStatic && getMaskSet()["validPositions"][pos] == undefined) {
-                        var tests = getTests(pos), staticAlternations = true;
+                        var tests = getTests(pos), hasAlternations = false, prevTest;
                         for (var i = 0; i < tests.length; i++) {
-                            if (tests[i].match.def != "" && (tests[i].match.fn !== null || (tests[i].alternation == undefined || tests[i].locator[tests[i].alternation].length > 1))) {
-                                staticAlternations = false;
+                            if (prevTest && tests[i].match.def != "" && (tests[i].match.def != prevTest.match.def && (tests[i].alternation == undefined || tests[i].alternation == prevTest.alternation ))) {
+                                hasAlternations = true;
                                 break;
                             }
+                            
+                            if(tests[i].match.optionality != true && tests[i].match.optionalQuantifier != true)
+                                prevTest = tests[i];
                         }
 
-                        if (staticAlternations)
+                        if (hasAlternations)
                             return opts.placeholder.charAt(pos % opts.placeholder.length);
                     }
                     return test["def"]
@@ -1693,9 +1696,9 @@
                     if (!pasteValue)
                         pasteValue = inputValue;
                 }
-                checkVal(input, true, false, isRTL ? pasteValue.split('').reverse() : pasteValue.split(''));
+                checkVal(input, false, false, isRTL ? pasteValue.split('').reverse() : pasteValue.split(''));
+                writeBuffer(input, getBuffer(), undefined, e, true);
                 $input.click();
-                $input.trigger("input");
                 if (isComplete(getBuffer()) === true)
                     $input.trigger("complete");
 

+ 1 - 1
package.json

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

+ 1 - 1
qunit/tests_keepStatic.js

@@ -127,7 +127,7 @@ test("(78)|(79) 999 99 99", function () {
     $fixture.append('<input type="text" id="testmask" />');
     $("#testmask").inputmask("(78)|(79) 999 99 99");
     $("#testmask")[0].focus();
-    equal(document.getElementById("testmask")._valueGet(), "78 ___ __ __", "Result " + document.getElementById("testmask")._valueGet());
+    equal(document.getElementById("testmask")._valueGet(), "7_ ___ __ __", "Result " + document.getElementById("testmask")._valueGet());
 
     $("#testmask").remove();
 });

+ 2 - 2
qunit/tests_paste.js

@@ -13,12 +13,12 @@ asyncTest("inputmask(\"+7 (999) 999-99-99\") ~ paste \"+79114041112\"", function
     }, 0);
 
 });
-asyncTest("inputmask(\"+7 (999) 999-99-99\") ~ paste \"+7 (+7 (9114041112___) ___-__-__\"", function () {
+asyncTest("inputmask(\"+7 (999) 999-99-99\") ~ paste \"+7 (9114041112___)\"", function () {
     var $fixture = $("#qunit-fixture");
     $fixture.append('<input type="text" id="testmask" />');
     $("#testmask").inputmask("+7 (999) 999-99-99");
     $("#testmask")[0].focus();
-    $("#testmask").paste("+7 (+7 (9114041112___) ___-__-__");
+    $("#testmask").paste("+7 (9114041112___)");
 
     setTimeout(function () {
         equal($("#testmask").val(), "+7 (911) 404-11-12", "Result " + $("#testmask").val());