浏览代码

ie placeholder workaround

Robin Herbots 7 年之前
父节点
当前提交
ea0bc4f793

+ 1 - 0
CHANGELOG.md

@@ -5,6 +5,7 @@
 ### Updates
 
 ### Fixed
+- Strange Calendar popup issue in IE Only when used with Daterangepicker #1965
 - incorrect work min max date - #2011, #2013
 
 ## [4.0.2 - 2018-09-14]

+ 3 - 6
bower.json

@@ -1,6 +1,6 @@
 {
   "name": "inputmask",
-  "version": "4.0.3-beta.0",
+  "version": "4.0.3-beta.1",
   "main": [
 	  "./index.js",
     "./css/inputmask.css"
@@ -11,11 +11,8 @@
   "ignore": [
     "**/*",
     "!index.js",
-    "!css/*",
-    "!dist/*",
-    "!dist/inputmask/*",
-    "!dist/min/*",
-    "!dist/min/inputmask/*"
+    "!css/**/*",
+    "!dist/**/*"
   ],
   "dependencies": {
     "jquery": ">=1.7"

+ 1 - 1
composer.json

@@ -1,7 +1,7 @@
 {
   "name": "robinherbots/inputmask",
   "description": "Inputmask is a javascript library which creates an input mask.  Inputmask can run against vanilla javascript, jQuery and jqlite.",
-  "version": "4.0.3-beta.0",
+  "version": "4.0.3-beta.1",
   "type": "library",
   "keywords": ["jquery", "plugins", "input", "form", "inputmask", "mask"],
   "homepage": "http://robinherbots.github.io/Inputmask",

+ 1 - 1
dist/inputmask/bindings/inputmask.binding.js

@@ -3,7 +3,7 @@
 * https://github.com/RobinHerbots/Inputmask
 * Copyright (c) 2010 - 2018 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 4.0.3-beta.0
+* Version: 4.0.3-beta.1
 */
 
 (function(factory) {

+ 1 - 1
dist/inputmask/dependencyLibs/inputmask.dependencyLib.jqlite.js

@@ -3,7 +3,7 @@
 * https://github.com/RobinHerbots/Inputmask
 * Copyright (c) 2010 - 2018 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 4.0.3-beta.0
+* Version: 4.0.3-beta.1
 */
 
 (function(factory) {

+ 1 - 1
dist/inputmask/dependencyLibs/inputmask.dependencyLib.jquery.js

@@ -3,7 +3,7 @@
 * https://github.com/RobinHerbots/Inputmask
 * Copyright (c) 2010 - 2018 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 4.0.3-beta.0
+* Version: 4.0.3-beta.1
 */
 
 (function(factory) {

+ 1 - 1
dist/inputmask/dependencyLibs/inputmask.dependencyLib.js

@@ -3,7 +3,7 @@
 * https://github.com/RobinHerbots/Inputmask
 * Copyright (c) 2010 - 2018 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 4.0.3-beta.0
+* Version: 4.0.3-beta.1
 */
 
 (function(factory) {

+ 1 - 1
dist/inputmask/global/window.js

@@ -3,7 +3,7 @@
 * https://github.com/RobinHerbots/Inputmask
 * Copyright (c) 2010 - 2018 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 4.0.3-beta.0
+* Version: 4.0.3-beta.1
 */
 
 if (typeof define === "function" && define.amd) define(function() {

+ 1 - 1
dist/inputmask/inputmask.date.extensions.js

@@ -3,7 +3,7 @@
 * https://github.com/RobinHerbots/Inputmask
 * Copyright (c) 2010 - 2018 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 4.0.3-beta.0
+* Version: 4.0.3-beta.1
 */
 
 (function(factory) {

+ 1 - 1
dist/inputmask/inputmask.extensions.js

@@ -3,7 +3,7 @@
 * https://github.com/RobinHerbots/Inputmask
 * Copyright (c) 2010 - 2018 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 4.0.3-beta.0
+* Version: 4.0.3-beta.1
 */
 
 (function(factory) {

+ 21 - 7
dist/inputmask/inputmask.js

@@ -3,7 +3,7 @@
 * https://github.com/RobinHerbots/Inputmask
 * Copyright (c) 2010 - 2018 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 4.0.3-beta.0
+* Version: 4.0.3-beta.1
 */
 
 (function(factory) {
@@ -15,7 +15,7 @@
         window.Inputmask = factory(window.dependencyLib || jQuery, window);
     }
 })(function($, window, undefined) {
-    var document = window.document, ua = navigator.userAgent, mobile = isInputEventSupported("touchstart"), iemobile = /iemobile/i.test(ua), iphone = /iphone/i.test(ua) && !iemobile;
+    var document = window.document, ua = navigator.userAgent, ie = ua.indexOf("MSIE ") > 0 || ua.indexOf("Trident/") > 0, mobile = isInputEventSupported("touchstart"), iemobile = /iemobile/i.test(ua), iphone = /iphone/i.test(ua) && !iemobile;
     function Inputmask(alias, options, internal) {
         if (!(this instanceof Inputmask)) {
             return new Inputmask(alias, options, internal);
@@ -1573,6 +1573,22 @@
             }
             return opts.placeholder.charAt(pos % opts.placeholder.length);
         }
+        function HandleNativePlaceholder(npt, value) {
+            if (ie && npt.inputmask._valueGet() !== value) {
+                var buffer = getBuffer().slice(), nptValue = npt.inputmask._valueGet();
+                if (nptValue !== value) {
+                    if (getLastValidPosition() === -1 && nptValue === getBufferTemplate().join("")) {
+                        buffer = [];
+                    } else {
+                        clearOptionalTail(buffer);
+                    }
+                    writeBuffer(npt, buffer);
+                }
+            } else if (npt.placeholder !== value) {
+                npt.placeholder = value;
+                if (npt.placeholder === "") npt.removeAttribute("placeholder");
+            }
+        }
         var EventRuler = {
             on: function(input, eventName, eventHandler) {
                 var ev = function(e) {
@@ -1912,8 +1928,7 @@
                 var input = this;
                 mouseEnter = false;
                 if (opts.clearMaskOnLostFocus && document.activeElement !== input) {
-                    input.placeholder = originalPlaceholder;
-                    if (input.placeholder === "") input.removeAttribute("placeholder");
+                    HandleNativePlaceholder(input, originalPlaceholder);
                 }
             },
             clickEvent: function(e, tabbed) {
@@ -1997,8 +2012,7 @@
             blurEvent: function(e) {
                 var $input = $(this), input = this;
                 if (input.inputmask) {
-                    input.placeholder = originalPlaceholder;
-                    if (input.placeholder === "") input.removeAttribute("placeholder");
+                    HandleNativePlaceholder(input, originalPlaceholder);
                     var nptValue = input.inputmask._valueGet(), buffer = getBuffer().slice();
                     if (nptValue !== "" || colorMask !== undefined) {
                         if (opts.clearMaskOnLostFocus) {
@@ -2033,7 +2047,7 @@
                 var input = this;
                 mouseEnter = true;
                 if (document.activeElement !== input && opts.showMaskOnHover) {
-                    input.placeholder = (isRTL ? getBuffer().slice().reverse() : getBuffer()).join("");
+                    HandleNativePlaceholder(input, (isRTL ? getBuffer().slice().reverse() : getBuffer()).join(""));
                 }
             },
             submitEvent: function(e) {

+ 1 - 1
dist/inputmask/inputmask.numeric.extensions.js

@@ -3,7 +3,7 @@
 * https://github.com/RobinHerbots/Inputmask
 * Copyright (c) 2010 - 2018 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 4.0.3-beta.0
+* Version: 4.0.3-beta.1
 */
 
 (function(factory) {

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

@@ -3,7 +3,7 @@
 * https://github.com/RobinHerbots/Inputmask
 * Copyright (c) 2010 - 2018 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 4.0.3-beta.0
+* Version: 4.0.3-beta.1
 */
 
 (function(factory) {

+ 21 - 7
dist/jquery.inputmask.bundle.js

@@ -3,7 +3,7 @@
 * https://github.com/RobinHerbots/Inputmask
 * Copyright (c) 2010 - 2018 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 4.0.3-beta.0
+* Version: 4.0.3-beta.1
 */
 
 (function(modules) {
@@ -200,7 +200,7 @@
             __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
         } else {}
     })(function($, window, undefined) {
-        var document = window.document, ua = navigator.userAgent, mobile = isInputEventSupported("touchstart"), iemobile = /iemobile/i.test(ua), iphone = /iphone/i.test(ua) && !iemobile;
+        var document = window.document, ua = navigator.userAgent, ie = ua.indexOf("MSIE ") > 0 || ua.indexOf("Trident/") > 0, mobile = isInputEventSupported("touchstart"), iemobile = /iemobile/i.test(ua), iphone = /iphone/i.test(ua) && !iemobile;
         function Inputmask(alias, options, internal) {
             if (!(this instanceof Inputmask)) {
                 return new Inputmask(alias, options, internal);
@@ -1764,6 +1764,22 @@
                 }
                 return opts.placeholder.charAt(pos % opts.placeholder.length);
             }
+            function HandleNativePlaceholder(npt, value) {
+                if (ie && npt.inputmask._valueGet() !== value) {
+                    var buffer = getBuffer().slice(), nptValue = npt.inputmask._valueGet();
+                    if (nptValue !== value) {
+                        if (getLastValidPosition() === -1 && nptValue === getBufferTemplate().join("")) {
+                            buffer = [];
+                        } else {
+                            clearOptionalTail(buffer);
+                        }
+                        writeBuffer(npt, buffer);
+                    }
+                } else if (npt.placeholder !== value) {
+                    npt.placeholder = value;
+                    if (npt.placeholder === "") npt.removeAttribute("placeholder");
+                }
+            }
             var EventRuler = {
                 on: function on(input, eventName, eventHandler) {
                     var ev = function ev(e) {
@@ -2103,8 +2119,7 @@
                     var input = this;
                     mouseEnter = false;
                     if (opts.clearMaskOnLostFocus && document.activeElement !== input) {
-                        input.placeholder = originalPlaceholder;
-                        if (input.placeholder === "") input.removeAttribute("placeholder");
+                        HandleNativePlaceholder(input, originalPlaceholder);
                     }
                 },
                 clickEvent: function clickEvent(e, tabbed) {
@@ -2188,8 +2203,7 @@
                 blurEvent: function blurEvent(e) {
                     var $input = $(this), input = this;
                     if (input.inputmask) {
-                        input.placeholder = originalPlaceholder;
-                        if (input.placeholder === "") input.removeAttribute("placeholder");
+                        HandleNativePlaceholder(input, originalPlaceholder);
                         var nptValue = input.inputmask._valueGet(), buffer = getBuffer().slice();
                         if (nptValue !== "" || colorMask !== undefined) {
                             if (opts.clearMaskOnLostFocus) {
@@ -2224,7 +2238,7 @@
                     var input = this;
                     mouseEnter = true;
                     if (document.activeElement !== input && opts.showMaskOnHover) {
-                        input.placeholder = (isRTL ? getBuffer().slice().reverse() : getBuffer()).join("");
+                        HandleNativePlaceholder(input, (isRTL ? getBuffer().slice().reverse() : getBuffer()).join(""));
                     }
                 },
                 submitEvent: function submitEvent(e) {

文件差异内容过多而无法显示
+ 1 - 1
dist/min/inputmask/bindings/inputmask.binding.min.js


文件差异内容过多而无法显示
+ 1 - 1
dist/min/inputmask/dependencyLibs/inputmask.dependencyLib.jqlite.min.js


+ 1 - 1
dist/min/inputmask/dependencyLibs/inputmask.dependencyLib.jquery.min.js

@@ -3,7 +3,7 @@
 * https://github.com/RobinHerbots/Inputmask
 * Copyright (c) 2010 - 2018 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 4.0.3-beta.0
+* Version: 4.0.3-beta.1
 */
 
 (function(factory){if(typeof define==="function"&&define.amd){define(["jquery"],factory)}else if(typeof exports==="object"){module.exports=factory(require("jquery"))}else{window.dependencyLib=factory(jQuery)}})(function($){return $});

文件差异内容过多而无法显示
+ 1 - 1
dist/min/inputmask/dependencyLibs/inputmask.dependencyLib.min.js


+ 1 - 1
dist/min/inputmask/global/window.min.js

@@ -3,7 +3,7 @@
 * https://github.com/RobinHerbots/Inputmask
 * Copyright (c) 2010 - 2018 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 4.0.3-beta.0
+* Version: 4.0.3-beta.1
 */
 
 if(typeof define==="function"&&define.amd)define(function(){return window||new(eval("require('jsdom')")("").window)});else if(typeof exports==="object")module.exports=window||new(eval("require('jsdom')")("").window);

文件差异内容过多而无法显示
+ 1 - 1
dist/min/inputmask/inputmask.date.extensions.min.js


文件差异内容过多而无法显示
+ 1 - 1
dist/min/inputmask/inputmask.extensions.min.js


文件差异内容过多而无法显示
+ 2 - 2
dist/min/inputmask/inputmask.min.js


文件差异内容过多而无法显示
+ 1 - 1
dist/min/inputmask/inputmask.numeric.extensions.min.js


文件差异内容过多而无法显示
+ 1 - 1
dist/min/inputmask/jquery.inputmask.min.js


文件差异内容过多而无法显示
+ 2 - 2
dist/min/jquery.inputmask.bundle.min.js


+ 22 - 5
js/inputmask.js

@@ -17,6 +17,7 @@
 (function ($, window, undefined) {
         var document = window.document,
             ua = navigator.userAgent,
+            ie = (ua.indexOf('MSIE ') > 0) || (ua.indexOf('Trident/') > 0),
             mobile = isInputEventSupported("touchstart"), //not entirely correct but will currently do
             iemobile = /iemobile/i.test(ua),
             iphone = /iphone/i.test(ua) && !iemobile;
@@ -1868,6 +1869,23 @@
                 return opts.placeholder.charAt(pos % opts.placeholder.length);
             }
 
+            function HandleNativePlaceholder(npt, value) {
+                if (ie && npt.inputmask._valueGet() !== value) {
+                    var buffer = getBuffer().slice(),
+                        nptValue = npt.inputmask._valueGet();
+                    if (nptValue !== value) {
+                        if (getLastValidPosition() === -1 && nptValue === getBufferTemplate().join("")) {
+                            buffer = [];
+                        } else { //clearout optional tail of the mask
+                            clearOptionalTail(buffer);
+                        }
+                        writeBuffer(npt, buffer);
+                    }
+                } else if (npt.placeholder !== value) {
+                    npt.placeholder = value;
+                    if (npt.placeholder === "") npt.removeAttribute("placeholder");
+                }
+            }
 
             var EventRuler = {
                 on: function (input, eventName, eventHandler) {
@@ -1887,6 +1905,7 @@
                                         skipInputEvent = false;
                                         return e.preventDefault();
                                     }
+
                                     if (mobile) {
                                         var args = arguments;
                                         setTimeout(function () { //needed for caret selection when entering a char on Android 8 - #1818
@@ -2265,8 +2284,7 @@
                     var input = this;
                     mouseEnter = false;
                     if (opts.clearMaskOnLostFocus && document.activeElement !== input) {
-                        input.placeholder = originalPlaceholder;
-                        if (input.placeholder === "") input.removeAttribute("placeholder");
+                        HandleNativePlaceholder(input, originalPlaceholder);
                     }
                 },
                 clickEvent: function (e, tabbed) {
@@ -2359,8 +2377,7 @@
                     var $input = $(this),
                         input = this;
                     if (input.inputmask) {
-                        input.placeholder = originalPlaceholder;
-                        if (input.placeholder === "") input.removeAttribute("placeholder");
+                        HandleNativePlaceholder(input, originalPlaceholder);
                         var nptValue = input.inputmask._valueGet(),
                             buffer = getBuffer().slice();
 
@@ -2399,7 +2416,7 @@
                     var input = this;
                     mouseEnter = true;
                     if (document.activeElement !== input && opts.showMaskOnHover) {
-                        input.placeholder = (isRTL ? getBuffer().slice().reverse() : getBuffer()).join("");
+                        HandleNativePlaceholder(input, (isRTL ? getBuffer().slice().reverse() : getBuffer()).join(""));
                     }
                 },
                 submitEvent: function (e) { //trigger change on submit if any

+ 1 - 1
package.json

@@ -1,6 +1,6 @@
 {
   "name": "inputmask",
-  "version": "4.0.3-beta.0",
+  "version": "4.0.3-beta.1",
   "description": "Inputmask is a javascript library which creates an input mask.  Inputmask can run against vanilla javascript, jQuery and jqlite.",
   "main": "index.js",
   "files": [