Browse Source

optimize init + readd bundle/min

Robin Herbots 10 years ago
parent
commit
a058fd3dde

+ 1 - 0
CHANGELOG.md

@@ -4,6 +4,7 @@ All notable changes to this project will be documented in this file.
 ## [UNRELEASED]
 
 ### Added
+- Inputmask.remove
 - inputmask.binding => automated inputmask binding for html attributes
 - Add tooltip option
 

+ 10 - 1
Gruntfile.js

@@ -60,6 +60,15 @@ module.exports = function(grunt) {
 				ASCIIOnly: true
 			}
 		};
+		uglifyConfig["bundlemin"] = {
+			dest: "dist/min/jquery.inputmask.bundle.min.js",
+			src: srcFiles,
+			options: {
+				banner: createBanner("jquery.inputmask.bundle.js"),
+				preserveComments: "some",
+				ASCIIOnly: true
+			}
+		};
 
 		return uglifyConfig;
 	}
@@ -110,7 +119,7 @@ module.exports = function(grunt) {
 			dist: {
 				src: 'dist/jQuery.InputMask.<%= pkg.version %>.nupkg',
 				options: {
-						source: "https://www.nuget.org"
+					source: "https://www.nuget.org"
 				}
 			}
 		},

+ 6 - 0
README.md

@@ -469,6 +469,12 @@ var input = document.getElementById(selector);
 if(input.inputmask)
   input.inputmask.remove()
 ```
+or
+
+```javascript
+Inputmask.remove(document.getElementById(selector));
+```
+
 
 ### getemptymask
 return the default (empty) mask value

+ 1 - 1
bower.json

@@ -1,6 +1,6 @@
 {
   "name": "jquery.inputmask",
-  "version": "3.2.3-22",
+  "version": "3.2.3-24",
   "main": [
     "./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-22",
+  "version": "3.2.3-24",
   "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-22",
+  "version": "3.2.3-24",
   "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-22
+* Version: 3.2.3-24
 */
 !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-22
+* Version: 3.2.3-24
 */
 !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-22
+* Version: 3.2.3-24
 */
 !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);

+ 19 - 18
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-22
+* Version: 3.2.3-24
 */
 !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);
@@ -36,14 +36,13 @@
     function importAttributeOptions(npt, opts, userOptions) {
         function importOption(option, optionData) {
             optionData = void 0 !== optionData ? optionData : npt.getAttribute("data-inputmask-" + option), 
-            null !== optionData && ("string" != typeof optionData || 0 !== option.indexOf("on") && "false" !== optionData && "true" !== optionData || (optionData = eval("(" + optionData + ")")), 
+            null !== optionData && ("string" == typeof optionData && (0 === option.indexOf("on") ? optionData = window[optionData] : "false" === optionData ? optionData = !1 : "true" === optionData && (optionData = !0)), 
             "mask" === option && 0 === optionData.indexOf("[") ? (userOptions[option] = optionData.replace(/[\s[\]]/g, "").split(","), 
             userOptions[option][0] = userOptions[option][0].replace("'", ""), userOptions[option][userOptions[option].length - 1] = userOptions[option][userOptions[option].length - 1].replace("'", "")) : userOptions[option] = optionData);
         }
-        var attrOptions = npt.getAttribute("data-inputmask"), option, dataoptions, optionData;
-        if (attrOptions && "" !== attrOptions) try {
-            attrOptions = attrOptions.replace(new RegExp("'", "g"), '"'), dataoptions = $.parseJSON("{" + attrOptions + "}");
-        } catch (ex) {}
+        var option, dataoptions, optionData, attrOptions = npt.getAttribute("data-inputmask");
+        attrOptions && "" !== attrOptions && (attrOptions = attrOptions.replace(new RegExp("'", "g"), '"'), 
+        dataoptions = JSON.parse("{" + attrOptions + "}"));
         for (option in opts) {
             if (dataoptions) {
                 optionData = void 0;
@@ -1098,7 +1097,7 @@
             mouseEnter = !0, document.activeElement !== input && opts.showMaskOnHover && input.inputmask._valueGet() !== getBuffer().join("") && writeBuffer(input, getBuffer());
         }
         function mask(elem) {
-            el = elem, $el = $(el), opts.showTooltip && (el.title = opts.tooltip || getMaskSet().mask), 
+            if (el = elem, $el = $(el), opts.showTooltip && (el.title = opts.tooltip || getMaskSet().mask), 
             ("rtl" === el.dir || opts.rightAlign) && (el.style.textAlign = "right"), ("rtl" === el.dir || opts.numericInput) && (el.dir = "ltr", 
             el.removeAttribute("dir"), el.inputmask.isRTL = !0, isRTL = !0), $el.off(".inputmask"), 
             patchValueProperty(el), ("INPUT" === el.tagName && isInputTypeSupported(el.getAttribute("type")) || el.isContentEditable) && ($(el.form).on("submit", function() {
@@ -1115,17 +1114,15 @@
             androidfirefox || $el.on("compositionstart.inputmask", wrapEventRuler(compositionStartEvent)).on("compositionupdate.inputmask", wrapEventRuler(compositionUpdateEvent)).on("compositionend.inputmask", wrapEventRuler(compositionEndEvent)), 
             "paste" === PasteEventType && $el.on("input.inputmask", wrapEventRuler(inputFallBackEvent)), 
             (android || androidfirefox || androidchrome || kindle) && ($el.off("input.inputmask"), 
-            $el.on("input.inputmask", wrapEventRuler(mobileInputEvent)))), $el.on("setvalue.inputmask", wrapEventRuler(setValueEvent));
-            var initialValue = $.isFunction(opts.onBeforeMask) ? opts.onBeforeMask.call(el, el.inputmask._valueGet(), opts) || el.inputmask._valueGet() : el.inputmask._valueGet();
-            checkVal(el, !0, !1, initialValue.split(""));
-            var buffer = getBuffer().slice();
-            undoValue = buffer.join("");
-            var activeElement;
-            try {
-                activeElement = document.activeElement;
-            } catch (e) {}
-            isComplete(buffer) === !1 && opts.clearIncomplete && resetMaskSet(), opts.clearMaskOnLostFocus && (buffer.join("") === getBufferTemplate().join("") ? buffer = [] : clearOptionalTail(buffer)), 
-            writeBuffer(el, buffer), activeElement === el && caret(el, seekNext(getLastValidPosition()));
+            $el.on("input.inputmask", wrapEventRuler(mobileInputEvent)))), $el.on("setvalue.inputmask", wrapEventRuler(setValueEvent)), 
+            "" !== el.inputmask._valueGet() || opts.clearMaskOnLostFocus === !1) {
+                var initialValue = $.isFunction(opts.onBeforeMask) ? opts.onBeforeMask.call(el, el.inputmask._valueGet(), opts) || el.inputmask._valueGet() : el.inputmask._valueGet();
+                checkVal(el, !0, !1, initialValue.split(""));
+                var buffer = getBuffer().slice();
+                undoValue = buffer.join(""), isComplete(buffer) === !1 && opts.clearIncomplete && resetMaskSet(), 
+                opts.clearMaskOnLostFocus && (buffer.join("") === getBufferTemplate().join("") ? buffer = [] : clearOptionalTail(buffer)), 
+                writeBuffer(el, buffer), document.activeElement === el && caret(el, seekNext(getLastValidPosition()));
+            }
         }
         var undoValue, compositionData, el, $el, maxLength, valueBuffer, isRTL = !1, skipKeyPressEvent = !1, skipInputEvent = !1, ignorable = !1, mouseEnter = !0;
         if (void 0 !== actionObj) switch (actionObj.action) {
@@ -1342,6 +1339,10 @@
         return Inputmask(options).unmaskedvalue(value);
     }, Inputmask.isValid = function(value, options) {
         return Inputmask(options).isValid(value);
+    }, Inputmask.remove = function(elems) {
+        $.each(elems, function(ndx, el) {
+            el.inputmask && el.inputmask.remove();
+        });
     }, Inputmask.escapeRegex = function(str) {
         var specials = [ "/", ".", "*", "+", "?", "|", "(", ")", "[", "]", "{", "}", "\\", "$", "^" ];
         return str.replace(new RegExp("(\\" + specials.join("|\\") + ")", "gim"), "\\$1");

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

+ 19 - 18
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-22
+* Version: 3.2.3-24
 */
 !function($) {
     function Inputmask(alias, options) {
@@ -34,14 +34,13 @@
     function importAttributeOptions(npt, opts, userOptions) {
         function importOption(option, optionData) {
             optionData = void 0 !== optionData ? optionData : npt.getAttribute("data-inputmask-" + option), 
-            null !== optionData && ("string" != typeof optionData || 0 !== option.indexOf("on") && "false" !== optionData && "true" !== optionData || (optionData = eval("(" + optionData + ")")), 
+            null !== optionData && ("string" == typeof optionData && (0 === option.indexOf("on") ? optionData = window[optionData] : "false" === optionData ? optionData = !1 : "true" === optionData && (optionData = !0)), 
             "mask" === option && 0 === optionData.indexOf("[") ? (userOptions[option] = optionData.replace(/[\s[\]]/g, "").split(","), 
             userOptions[option][0] = userOptions[option][0].replace("'", ""), userOptions[option][userOptions[option].length - 1] = userOptions[option][userOptions[option].length - 1].replace("'", "")) : userOptions[option] = optionData);
         }
-        var attrOptions = npt.getAttribute("data-inputmask"), option, dataoptions, optionData;
-        if (attrOptions && "" !== attrOptions) try {
-            attrOptions = attrOptions.replace(new RegExp("'", "g"), '"'), dataoptions = $.parseJSON("{" + attrOptions + "}");
-        } catch (ex) {}
+        var option, dataoptions, optionData, attrOptions = npt.getAttribute("data-inputmask");
+        attrOptions && "" !== attrOptions && (attrOptions = attrOptions.replace(new RegExp("'", "g"), '"'), 
+        dataoptions = JSON.parse("{" + attrOptions + "}"));
         for (option in opts) {
             if (dataoptions) {
                 optionData = void 0;
@@ -1096,7 +1095,7 @@
             mouseEnter = !0, document.activeElement !== input && opts.showMaskOnHover && input.inputmask._valueGet() !== getBuffer().join("") && writeBuffer(input, getBuffer());
         }
         function mask(elem) {
-            el = elem, $el = $(el), opts.showTooltip && (el.title = opts.tooltip || getMaskSet().mask), 
+            if (el = elem, $el = $(el), opts.showTooltip && (el.title = opts.tooltip || getMaskSet().mask), 
             ("rtl" === el.dir || opts.rightAlign) && (el.style.textAlign = "right"), ("rtl" === el.dir || opts.numericInput) && (el.dir = "ltr", 
             el.removeAttribute("dir"), el.inputmask.isRTL = !0, isRTL = !0), $el.off(".inputmask"), 
             patchValueProperty(el), ("INPUT" === el.tagName && isInputTypeSupported(el.getAttribute("type")) || el.isContentEditable) && ($(el.form).on("submit", function() {
@@ -1113,17 +1112,15 @@
             androidfirefox || $el.on("compositionstart.inputmask", wrapEventRuler(compositionStartEvent)).on("compositionupdate.inputmask", wrapEventRuler(compositionUpdateEvent)).on("compositionend.inputmask", wrapEventRuler(compositionEndEvent)), 
             "paste" === PasteEventType && $el.on("input.inputmask", wrapEventRuler(inputFallBackEvent)), 
             (android || androidfirefox || androidchrome || kindle) && ($el.off("input.inputmask"), 
-            $el.on("input.inputmask", wrapEventRuler(mobileInputEvent)))), $el.on("setvalue.inputmask", wrapEventRuler(setValueEvent));
-            var initialValue = $.isFunction(opts.onBeforeMask) ? opts.onBeforeMask.call(el, el.inputmask._valueGet(), opts) || el.inputmask._valueGet() : el.inputmask._valueGet();
-            checkVal(el, !0, !1, initialValue.split(""));
-            var buffer = getBuffer().slice();
-            undoValue = buffer.join("");
-            var activeElement;
-            try {
-                activeElement = document.activeElement;
-            } catch (e) {}
-            isComplete(buffer) === !1 && opts.clearIncomplete && resetMaskSet(), opts.clearMaskOnLostFocus && (buffer.join("") === getBufferTemplate().join("") ? buffer = [] : clearOptionalTail(buffer)), 
-            writeBuffer(el, buffer), activeElement === el && caret(el, seekNext(getLastValidPosition()));
+            $el.on("input.inputmask", wrapEventRuler(mobileInputEvent)))), $el.on("setvalue.inputmask", wrapEventRuler(setValueEvent)), 
+            "" !== el.inputmask._valueGet() || opts.clearMaskOnLostFocus === !1) {
+                var initialValue = $.isFunction(opts.onBeforeMask) ? opts.onBeforeMask.call(el, el.inputmask._valueGet(), opts) || el.inputmask._valueGet() : el.inputmask._valueGet();
+                checkVal(el, !0, !1, initialValue.split(""));
+                var buffer = getBuffer().slice();
+                undoValue = buffer.join(""), isComplete(buffer) === !1 && opts.clearIncomplete && resetMaskSet(), 
+                opts.clearMaskOnLostFocus && (buffer.join("") === getBufferTemplate().join("") ? buffer = [] : clearOptionalTail(buffer)), 
+                writeBuffer(el, buffer), document.activeElement === el && caret(el, seekNext(getLastValidPosition()));
+            }
         }
         var undoValue, compositionData, el, $el, maxLength, valueBuffer, isRTL = !1, skipKeyPressEvent = !1, skipInputEvent = !1, ignorable = !1, mouseEnter = !0;
         if (void 0 !== actionObj) switch (actionObj.action) {
@@ -1340,6 +1337,10 @@
         return Inputmask(options).unmaskedvalue(value);
     }, Inputmask.isValid = function(value, options) {
         return Inputmask(options).isValid(value);
+    }, Inputmask.remove = function(elems) {
+        $.each(elems, function(ndx, el) {
+            el.inputmask && el.inputmask.remove();
+        });
     }, Inputmask.escapeRegex = function(str) {
         var specials = [ "/", ".", "*", "+", "?", "|", "(", ")", "[", "]", "{", "}", "\\", "$", "^" ];
         return str.replace(new RegExp("(\\" + specials.join("|\\") + ")", "gim"), "\\$1");

File diff suppressed because it is too large
+ 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-22
+* Version: 3.2.3-24
 */
 !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});

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


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


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


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


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


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


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


+ 1 - 4
extra/dependencyLibs/inputmask.dependencyLib.js

@@ -280,9 +280,6 @@ Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.p
 			return type(obj) === "function";
 		};
 		DependencyLib.noop = function() {};
-		DependencyLib.parseJSON = function(data) {
-			return JSON.parse(data + "");
-		};
 		DependencyLib.isArray = Array.isArray;
 		DependencyLib.inArray = function(elem, arr, i) {
 			return arr == null ? -1 : indexOf(arr, elem, i);
@@ -447,7 +444,7 @@ Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.p
 				type: type,
 				which: 0
 			};
-		}
+		};
 		DependencyLib.data = function(owner, key, value) {
 			if (value === undefined) {
 				return owner.__data ? owner.__data[key] : null;

+ 31 - 33
js/inputmask.js

@@ -239,6 +239,11 @@
 		Inputmask.isValid = function(value, options) {
 			return Inputmask(options).isValid(value);
 		};
+		Inputmask.remove = function(elems) {
+			$.each(elems, function(ndx, el) {
+				if (el.inputmask) el.inputmask.remove();
+			});
+		};
 		Inputmask.escapeRegex = function(str) {
 			var specials = ["/", ".", "*", "+", "?", "|", "(", ")", "[", "]", "{", "}", "\\", "$", "^"];
 			return str.replace(new RegExp("(\\" + specials.join("|\\") + ")", "gim"), "\\$1");
@@ -324,12 +329,11 @@
 			function importOption(option, optionData) {
 				optionData = optionData !== undefined ? optionData : npt.getAttribute("data-inputmask-" + option);
 				if (optionData !== null) {
-					// optionData = typeof optionData == "boolean" ? optionData : optionData.toString();
-					/*eslint-disable no-eval */
-					if (typeof optionData === "string" && (option.indexOf("on") === 0 || optionData === "false" || optionData === "true")) {
-						optionData = eval("(" + optionData + ")");
+					if (typeof optionData === "string") {
+						if (option.indexOf("on") === 0) optionData = window[optionData]; //get function definition
+						else if (optionData === "false") optionData = false;
+						else if (optionData === "true") optionData = true;
 					}
-					/*eslint-enable no-eval */
 					if (option === "mask" && optionData.indexOf("[") === 0) {
 						userOptions[option] = optionData.replace(/[\s[\]]/g, "").split(",");
 						userOptions[option][0] = userOptions[option][0].replace("'", "");
@@ -339,12 +343,8 @@
 			}
 
 			if (attrOptions && attrOptions !== "") {
-				try {
-					attrOptions = attrOptions.replace(new RegExp("'", "g"), '"');
-					dataoptions = $.parseJSON("{" + attrOptions + "}");
-				} catch (ex) {
-					//need a more relax parseJSON
-				}
+				attrOptions = attrOptions.replace(new RegExp("'", "g"), '"');
+				dataoptions = JSON.parse("{" + attrOptions + "}");
 			}
 			for (option in opts) {
 				if (dataoptions) {
@@ -2568,30 +2568,28 @@
 				$el.on("setvalue.inputmask", wrapEventRuler(setValueEvent));
 
 				//apply mask
-				var initialValue = $.isFunction(opts.onBeforeMask) ? (opts.onBeforeMask.call(el, el.inputmask._valueGet(), opts) || el.inputmask._valueGet()) : el.inputmask._valueGet();
-				checkVal(el, true, false, initialValue.split(""));
-				var buffer = getBuffer().slice();
-				undoValue = buffer.join("");
-				// Wrap document.activeElement in a try/catch block since IE9 throw "Unspecified error" if document.activeElement is undefined when we are in an IFrame.
-				var activeElement;
-				try {
-					activeElement = document.activeElement;
-				} catch (e) {}
-				if (isComplete(buffer) === false) {
-					if (opts.clearIncomplete) {
-						resetMaskSet();
+				if (el.inputmask._valueGet() !== "" || opts.clearMaskOnLostFocus === false) {
+					var initialValue = $.isFunction(opts.onBeforeMask) ? (opts.onBeforeMask.call(el, el.inputmask._valueGet(), opts) || el.inputmask._valueGet()) : el.inputmask._valueGet();
+					checkVal(el, true, false, initialValue.split(""));
+					var buffer = getBuffer().slice();
+					undoValue = buffer.join("");
+					// Wrap document.activeElement in a try/catch block since IE9 throw "Unspecified error" if document.activeElement is undefined when we are in an IFrame.
+					if (isComplete(buffer) === false) {
+						if (opts.clearIncomplete) {
+							resetMaskSet();
+						}
 					}
-				}
-				if (opts.clearMaskOnLostFocus) {
-					if (buffer.join("") === getBufferTemplate().join("")) {
-						buffer = [];
-					} else {
-						clearOptionalTail(buffer);
+					if (opts.clearMaskOnLostFocus) {
+						if (buffer.join("") === getBufferTemplate().join("")) {
+							buffer = [];
+						} else {
+							clearOptionalTail(buffer);
+						}
+					}
+					writeBuffer(el, buffer);
+					if (document.activeElement === el) { //position the caret when in focus
+						caret(el, seekNext(getLastValidPosition()));
 					}
-				}
-				writeBuffer(el, buffer);
-				if (activeElement === el) { //position the caret when in focus
-					caret(el, seekNext(getLastValidPosition()));
 				}
 			}
 

+ 1 - 1
package.json

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