Browse Source

update on dependencyLib

Robin Herbots 10 years ago
parent
commit
e7f3814e05

+ 1 - 0
CHANGELOG.md

@@ -9,6 +9,7 @@ All notable changes to this project will be documented in this file.
 - update files to be included for package.json, bower.json, component.json
 
 ### Fixed
+- Dynamically switching mask in same input box not functioning as expected #1016
 - 3.2.0 Error extendDefinitions and extendAliases not functions #1024
 - Browserify error: `Error: Cannot find module 'inputmask' from '/Users/.../node_modules/jquery.inputmask/dist/inputmask` #1030
 - Invalid JSON phone-uk.js #1025

+ 2 - 2
Gruntfile.js

@@ -14,8 +14,8 @@ module.exports = function(grunt) {
 			var srcFile = grunt.file.read(src);
 			srcFile = srcFile.replace(new RegExp("\\(function\\(factory\\)[\\s\\S]*\\(function\\(\\$"), "(function($");
 			if (src.indexOf("extensions") === -1 && src.indexOf("jquery.inputmask") === -1) {
-				srcFile = srcFile.replace(new RegExp("\\}\\)\\);[\\s\\S]*$"), "})(jQuery);");
-			} else srcFile = srcFile.replace(new RegExp("\\}\\)\\);[\\s\\S]*$"), "})(jQuery, Inputmask);");
+				srcFile = srcFile.replace(new RegExp("\\}\\)\\);[\\s]*$"), "})(jQuery);");
+			} else srcFile = srcFile.replace(new RegExp("\\}\\)\\);[\\s]*$"), "})(jQuery, Inputmask);");
 			grunt.file.write(dst, srcFile);
 		}
 		var uglifyConfig = {};

+ 1 - 1
bower.json

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

+ 18 - 6
dist/inputmask/dependencyLib.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.1-55
+* Version: 3.2.1-85
 */
 !function(factory) {
     "function" == typeof define && define.amd ? define([ "jquery" ], factory) : "object" == typeof exports ? module.exports = factory(require("jquery")) : factory(jQuery);
@@ -13,13 +13,13 @@
         return -1;
     }
     function type(obj) {
-        return null == obj ? obj + "" : "object" == typeof obj || "function" == typeof obj ? class2type[toString.call(obj)] || "object" : typeof obj;
+        return null == obj ? obj + "" : "object" == typeof obj || "function" == typeof obj ? class2type[class2type.toString.call(obj)] || "object" : typeof obj;
     }
     function Event(elem) {
         this[0] = elem;
     }
     function DependencyLib(elem) {
-        return new Event(elem);
+        return this[0] = elem, this instanceof DependencyLib ? void 0 : new DependencyLib(elem);
     }
     for (var class2type = {}, classTypes = "Boolean Number String Function Array Date RegExp Object Error".split(" "), nameNdx = 0; nameNdx < classTypes.length; nameNdx++) class2type["[object " + classTypes[nameNdx] + "]"] = classTypes[nameNdx].toLowerCase();
     return Event.prototype = {
@@ -35,13 +35,25 @@
         triggerHandler: function() {
             return $.fn.triggerHandler.apply($(this[0]), arguments), this;
         }
-    }, DependencyLib.isFunction = function(obj) {
+    }, DependencyLib.prototype = Event.prototype, DependencyLib.isFunction = function(obj) {
         return "function" === type(obj);
     }, DependencyLib.noop = function() {}, DependencyLib.parseJSON = function(data) {
         return JSON.parse(data + "");
     }, DependencyLib.isArray = Array.isArray, DependencyLib.inArray = function(elem, arr, i) {
         return null == arr ? -1 : indexOf(arr, elem, i);
-    }, DependencyLib.valHooks = void 0, DependencyLib.extend = $.extend, DependencyLib.each = $.each, 
-    DependencyLib.map = $.map, DependencyLib.Event = $.Event, DependencyLib._data = $._data, 
+    }, DependencyLib.valHooks = $.valHooks, DependencyLib.isWindow = function(obj) {
+        return null != obj && obj === obj.window;
+    }, DependencyLib.isPlainObject = function(obj) {
+        return "object" !== type(obj) || obj.nodeType || DependencyLib.isWindow(obj) ? !1 : obj.constructor && !class2type.hasOwnProperty.call(obj.constructor.prototype, "isPrototypeOf") ? !1 : !0;
+    }, DependencyLib.extend = function() {
+        var options, name, src, copy, copyIsArray, clone, target = arguments[0] || {}, i = 1, length = arguments.length, deep = !1;
+        for ("boolean" == typeof target && (deep = target, target = arguments[i] || {}, 
+        i++), "object" == typeof target || DependencyLib.isFunction(target) || (target = {}), 
+        i === length && (target = this, i--); length > i; i++) if (null != (options = arguments[i])) for (name in options) src = target[name], 
+        copy = options[name], target !== copy && (deep && copy && (DependencyLib.isPlainObject(copy) || (copyIsArray = DependencyLib.isArray(copy))) ? (copyIsArray ? (copyIsArray = !1, 
+        clone = src && DependencyLib.isArray(src) ? src : []) : clone = src && DependencyLib.isPlainObject(src) ? src : {}, 
+        target[name] = DependencyLib.extend(deep, clone, copy)) : void 0 !== copy && (target[name] = copy));
+        return target;
+    }, DependencyLib.each = $.each, DependencyLib.map = $.map, DependencyLib.Event = $.Event, 
     DependencyLib.data = $.data, window.dependencyLib = DependencyLib, DependencyLib;
 });

+ 24 - 3
dist/inputmask/dependencyLib_jqlite.js

@@ -3,10 +3,31 @@
 * 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.1-55
+* Version: 3.2.1-85
 */
 !function(factory) {
-    "function" == typeof define && define.amd ? define([ "jqlite" ], factory) : "object" == typeof exports ? module.exports = factory(require("jqlite")) : factory(jqlite);
+    "function" == typeof define && define.amd ? define([ "jqlite" ], factory) : "object" == typeof exports ? module.exports = factory(require("jqlite")) : factory(jQuery);
 }(function($) {
-    return window.dependencyLib = $, $;
+    function type(obj) {
+        return null == obj ? obj + "" : "object" == typeof obj || "function" == typeof obj ? class2type[class2type.toString.call(obj)] || "object" : typeof obj;
+    }
+    for (var class2type = {}, classTypes = "Boolean Number String Function Array Date RegExp Object Error".split(" "), nameNdx = 0; nameNdx < classTypes.length; nameNdx++) class2type["[object " + classTypes[nameNdx] + "]"] = classTypes[nameNdx].toLowerCase();
+    return $.isFunction = function(obj) {
+        return "function" === type(obj);
+    }, $.isArray = Array.isArray, $.isWindow = function(obj) {
+        return null != obj && obj === obj.window;
+    }, $.isPlainObject = function(obj) {
+        return "object" !== type(obj) || obj.nodeType || $.isWindow(obj) ? !1 : obj.constructor && !class2type.hasOwnProperty.call(obj.constructor.prototype, "isPrototypeOf") ? !1 : !0;
+    }, $.extend = function() {
+        var options, name, src, copy, copyIsArray, clone, target = arguments[0] || {}, i = 1, length = arguments.length, deep = !1;
+        for ("boolean" == typeof target && (deep = target, target = arguments[i] || {}, 
+        i++), "object" == typeof target || $.isFunction(target) || (target = {}), i === length && (target = this, 
+        i--); length > i; i++) if (null != (options = arguments[i])) for (name in options) src = target[name], 
+        copy = options[name], target !== copy && (deep && copy && ($.isPlainObject(copy) || (copyIsArray = $.isArray(copy))) ? (copyIsArray ? (copyIsArray = !1, 
+        clone = src && $.isArray(src) ? src : []) : clone = src && $.isPlainObject(src) ? src : {}, 
+        target[name] = $.extend(deep, clone, copy)) : void 0 !== copy && (target[name] = copy));
+        return target;
+    }, $.data = function(elem, name, data) {
+        return $(elem).data(name, data);
+    }, window.dependencyLib = $, $;
 });

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

+ 21 - 0
dist/inputmask/dependencyLib_zepto.js

@@ -0,0 +1,21 @@
+/*!
+* dependencyLib_zepto.js
+* 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.1-85
+*/
+!function(factory) {
+    "function" == typeof define && define.amd ? define([ "zepto", "zepto_data", "zepto_event" ], factory) : "object" == typeof exports ? module.exports = factory(require("zepto"), require("zepto_data"), require("zepto_event")) : factory(Zepto);
+}(function($) {
+    return $.extend = function() {
+        var options, name, src, copy, copyIsArray, clone, target = arguments[0] || {}, i = 1, length = arguments.length, deep = !1;
+        for ("boolean" == typeof target && (deep = target, target = arguments[i] || {}, 
+        i++), "object" == typeof target || $.isFunction(target) || (target = {}), i === length && (target = this, 
+        i--); length > i; i++) if (null != (options = arguments[i])) for (name in options) src = target[name], 
+        copy = options[name], target !== copy && (deep && copy && ($.isPlainObject(copy) || (copyIsArray = $.isArray(copy))) ? (copyIsArray ? (copyIsArray = !1, 
+        clone = src && $.isArray(src) ? src : []) : clone = src && $.isPlainObject(src) ? src : {}, 
+        target[name] = $.extend(deep, clone, copy)) : void 0 !== copy && (target[name] = copy));
+        return target;
+    }, $.data = $.fn.data, window.dependencyLib = $, $;
+});

+ 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.1-55
+* Version: 3.2.1-85
 */
 !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.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.1-55
+* Version: 3.2.1-85
 */
 !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);

File diff suppressed because it is too large
+ 50 - 62
dist/inputmask/inputmask.js


+ 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.1-55
+* Version: 3.2.1-85
 */
 !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.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.1-55
+* Version: 3.2.1-85
 */
 !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.1-55
+* Version: 3.2.1-85
 */
 !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/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.1-55
+* Version: 3.2.1-85
 */
 !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);

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


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


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


+ 1 - 1
dist/min/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.1-55
+* Version: 3.2.1-85
 */
 !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
+ 8 - 0
dist/min/inputmask/dependencyLib_zepto.min.js


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


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 - 4
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


+ 93 - 5
js/dependencyLib.js

@@ -36,7 +36,7 @@
 			}
 			// Support: Android<4.0, iOS<6 (functionish RegExp)
 			return typeof obj === "object" || typeof obj === "function" ?
-				class2type[toString.call(obj)] || "object" :
+				class2type[class2type.toString.call(obj)] || "object" :
 				typeof obj;
 		}
 
@@ -75,8 +75,12 @@
 
 
 		function DependencyLib(elem) {
-			return new Event(elem);
+			this[0] = elem;
+			if (!(this instanceof DependencyLib)) {
+				return new DependencyLib(elem);
+			}
 		}
+		DependencyLib.prototype = Event.prototype;
 
 		//static
 		DependencyLib.isFunction = function(obj) {
@@ -90,12 +94,96 @@
 		DependencyLib.inArray = function(elem, arr, i) {
 			return arr == null ? -1 : indexOf(arr, elem, i);
 		};
-		DependencyLib.valHooks = undefined;
-		DependencyLib.extend = $.extend;
+		DependencyLib.valHooks = $.valHooks;
+		DependencyLib.isWindow = function(obj) {
+			return obj != null && obj === obj.window;
+		};
+		DependencyLib.isPlainObject = function(obj) {
+			// Not plain objects:
+			// - Any object or value whose internal [[Class]] property is not "[object Object]"
+			// - DOM nodes
+			// - window
+			if (type(obj) !== "object" || obj.nodeType || DependencyLib.isWindow(obj)) {
+				return false;
+			}
+
+			if (obj.constructor && !class2type.hasOwnProperty.call(obj.constructor.prototype, "isPrototypeOf")) {
+				return false;
+			}
+
+			// If the function hasn't returned already, we're confident that
+			// |obj| is a plain object, created by {} or constructed with new Object
+			return true;
+		};
+
+		DependencyLib.extend = function() {
+			var options, name, src, copy, copyIsArray, clone,
+				target = arguments[0] || {},
+				i = 1,
+				length = arguments.length,
+				deep = false;
+
+			// Handle a deep copy situation
+			if (typeof target === "boolean") {
+				deep = target;
+
+				// Skip the boolean and the target
+				target = arguments[i] || {};
+				i++;
+			}
+
+			// Handle case when target is a string or something (possible in deep copy)
+			if (typeof target !== "object" && !DependencyLib.isFunction(target)) {
+				target = {};
+			}
+
+			// Extend jQuery itself if only one argument is passed
+			if (i === length) {
+				target = this;
+				i--;
+			}
+
+			for (; i < length; i++) {
+				// Only deal with non-null/undefined values
+				if ((options = arguments[i]) != null) {
+					// Extend the base object
+					for (name in options) {
+						src = target[name];
+						copy = options[name];
+
+						// Prevent never-ending loop
+						if (target === copy) {
+							continue;
+						}
+
+						// Recurse if we're merging plain objects or arrays
+						if (deep && copy && (DependencyLib.isPlainObject(copy) || (copyIsArray = DependencyLib.isArray(copy)))) {
+							if (copyIsArray) {
+								copyIsArray = false;
+								clone = src && DependencyLib.isArray(src) ? src : [];
+
+							} else {
+								clone = src && DependencyLib.isPlainObject(src) ? src : {};
+							}
+
+							// Never move original objects, clone them
+							target[name] = DependencyLib.extend(deep, clone, copy);
+
+							// Don't bring in undefined values
+						} else if (copy !== undefined) {
+							target[name] = copy;
+						}
+					}
+				}
+			}
+
+			// Return the modified object
+			return target;
+		};
+
 		DependencyLib.each = $.each;
 		DependencyLib.map = $.map;
 		DependencyLib.Event = $.Event; //needs to be replaced
-		DependencyLib._data = $._data; //needs to be replaced
 		DependencyLib.data = $.data; //needs to be replaced
 
 		window.dependencyLib = DependencyLib;

+ 108 - 1
js/dependencyLib_jqlite.js

@@ -4,10 +4,117 @@
 		} else if (typeof exports === "object") {
 			module.exports = factory(require("jqlite"));
 		} else {
-			factory(jqlite);
+			factory(jQuery);
 		}
 	}
 	(function($) {
+		var class2type = {},
+			classTypes = "Boolean Number String Function Array Date RegExp Object Error".split(" ");
+		for (var nameNdx = 0; nameNdx < classTypes.length; nameNdx++) {
+			class2type["[object " + classTypes[nameNdx] + "]"] = classTypes[nameNdx].toLowerCase();
+		}
+
+		function type(obj) {
+			if (obj == null) {
+				return obj + "";
+			}
+			// Support: Android<4.0, iOS<6 (functionish RegExp)
+			return typeof obj === "object" || typeof obj === "function" ?
+				class2type[class2type.toString.call(obj)] || "object" :
+				typeof obj;
+		}
+		$.isFunction = function(obj) {
+			return type(obj) === "function";
+		};
+		$.isArray = Array.isArray;
+		$.isWindow = function(obj) {
+			return obj != null && obj === obj.window;
+		};
+		$.isPlainObject = function(obj) {
+			// Not plain objects:
+			// - Any object or value whose internal [[Class]] property is not "[object Object]"
+			// - DOM nodes
+			// - window
+			if (type(obj) !== "object" || obj.nodeType || $.isWindow(obj)) {
+				return false;
+			}
+
+			if (obj.constructor && !class2type.hasOwnProperty.call(obj.constructor.prototype, "isPrototypeOf")) {
+				return false;
+			}
+
+			// If the function hasn't returned already, we're confident that
+			// |obj| is a plain object, created by {} or constructed with new Object
+			return true;
+		};
+		$.extend = function() {
+			var options, name, src, copy, copyIsArray, clone,
+				target = arguments[0] || {},
+				i = 1,
+				length = arguments.length,
+				deep = false;
+
+			// Handle a deep copy situation
+			if (typeof target === "boolean") {
+				deep = target;
+
+				// Skip the boolean and the target
+				target = arguments[i] || {};
+				i++;
+			}
+
+			// Handle case when target is a string or something (possible in deep copy)
+			if (typeof target !== "object" && !$.isFunction(target)) {
+				target = {};
+			}
+
+			// Extend jQuery itself if only one argument is passed
+			if (i === length) {
+				target = this;
+				i--;
+			}
+
+			for (; i < length; i++) {
+				// Only deal with non-null/undefined values
+				if ((options = arguments[i]) != null) {
+					// Extend the base object
+					for (name in options) {
+						src = target[name];
+						copy = options[name];
+
+						// Prevent never-ending loop
+						if (target === copy) {
+							continue;
+						}
+
+						// Recurse if we're merging plain objects or arrays
+						if (deep && copy && ($.isPlainObject(copy) || (copyIsArray = $.isArray(copy)))) {
+							if (copyIsArray) {
+								copyIsArray = false;
+								clone = src && $.isArray(src) ? src : [];
+
+							} else {
+								clone = src && $.isPlainObject(src) ? src : {};
+							}
+
+							// Never move original objects, clone them
+							target[name] = $.extend(deep, clone, copy);
+
+							// Don't bring in undefined values
+						} else if (copy !== undefined) {
+							target[name] = copy;
+						}
+					}
+				}
+			}
+
+			// Return the modified object
+			return target;
+		};
+		$.data = function(elem, name, data) {
+			return $(elem).data(name, data);
+		};
+
 		window.dependencyLib = $;
 		return $;
 	}));

+ 80 - 0
js/dependencyLib_zepto.js

@@ -0,0 +1,80 @@
+(function(factory) {
+		if (typeof define === "function" && define.amd) {
+			define(["zepto", "zepto_data", "zepto_event"], factory);
+		} else if (typeof exports === "object") {
+			module.exports = factory(require("zepto"), require("zepto_data"), require("zepto_event"));
+		} else {
+			factory(Zepto); //requires a zepto build with data & event
+		}
+	}
+	(function($) {
+		$.extend = function() {
+			var options, name, src, copy, copyIsArray, clone,
+				target = arguments[0] || {},
+				i = 1,
+				length = arguments.length,
+				deep = false;
+
+			// Handle a deep copy situation
+			if (typeof target === "boolean") {
+				deep = target;
+
+				// Skip the boolean and the target
+				target = arguments[i] || {};
+				i++;
+			}
+
+			// Handle case when target is a string or something (possible in deep copy)
+			if (typeof target !== "object" && !$.isFunction(target)) {
+				target = {};
+			}
+
+			// Extend jQuery itself if only one argument is passed
+			if (i === length) {
+				target = this;
+				i--;
+			}
+
+			for (; i < length; i++) {
+				// Only deal with non-null/undefined values
+				if ((options = arguments[i]) != null) {
+					// Extend the base object
+					for (name in options) {
+						src = target[name];
+						copy = options[name];
+
+						// Prevent never-ending loop
+						if (target === copy) {
+							continue;
+						}
+
+						// Recurse if we're merging plain objects or arrays
+						if (deep && copy && ($.isPlainObject(copy) || (copyIsArray = $.isArray(copy)))) {
+							if (copyIsArray) {
+								copyIsArray = false;
+								clone = src && $.isArray(src) ? src : [];
+
+							} else {
+								clone = src && $.isPlainObject(src) ? src : {};
+							}
+
+							// Never move original objects, clone them
+							target[name] = $.extend(deep, clone, copy);
+
+							// Don't bring in undefined values
+						} else if (copy !== undefined) {
+							target[name] = copy;
+						}
+					}
+				}
+			}
+
+			// Return the modified object
+			return target;
+		};
+		$.data = function(elem, name, data) {
+			return $(elem).data(name, data);
+		};
+		window.dependencyLib = $;
+		return $;
+	}));

+ 82 - 89
js/inputmask.js

@@ -7,7 +7,7 @@
  */
 (function(factory) {
 		if (typeof define === "function" && define.amd) {
-			define(["dependencyLib"], factory);
+			define(["./dependencyLib"], factory);
 		} else if (typeof exports === "object") {
 			module.exports = factory(require("./dependencyLib"));
 		} else {
@@ -109,8 +109,11 @@
 				importAttributeOptions(el, scopedOpts, $.extend(true, {}, this.userOptions));
 				var maskset = generateMaskSet(scopedOpts, this.noMasksCache);
 				if (maskset !== undefined) {
+					if (el.inputmask !== undefined) {
+						el.inputmask.remove();
+					}
 					//store inputmask instance on the input with element reference
-					el.inputmask = el.inputmask || new Inputmask(); //in case of remasking reuse the inputmask object
+					el.inputmask = new Inputmask();
 					el.inputmask.opts = scopedOpts;
 					el.inputmask.noMasksCache = this.noMasksCache;
 					el.inputmask.userOptions = $.extend(true, {}, this.userOptions);
@@ -184,7 +187,7 @@
 			}
 		};
 
-		//aply defaults, definitions, aliases
+		//apply defaults, definitions, aliases
 		Inputmask.extendDefaults = function(options) {
 			$.extend(Inputmask.prototype.defaults, options);
 		};
@@ -1782,59 +1785,50 @@
 					(end - begin) > 1 || ((end - begin) === 1 && opts.insertMode);
 			}
 
-			function installEventRuler(npt) {
-				var events = $._data(npt).events,
-					inComposition = false;
-
-				$.each(events, function(eventType, eventHandlers) {
-					$.each(eventHandlers, function(ndx, eventHandler) {
-						if (eventHandler.namespace === "inputmask") {
-							var handler = eventHandler.handler;
-							eventHandler.handler = function(e) {
-								// console.log("triggered " + e.type);
-								if (this.inputmask === undefined) { //happens when cloning an object with jquery.clone
-									var imOpts = $.data(this, "_inputmask_opts");
-									if (imOpts)(new Inputmask(imOpts)).mask(this);
-									else $(this).off(".inputmask");
-								} else if (e.type !== "setvalue" && (this.disabled || (this.readOnly && !(e.type === "keydown" && (e.ctrlKey && e.keyCode === 67) || (opts.tabThrough === false && e.keyCode === Inputmask.keyCode.TAB))))) {
-									e.preventDefault();
-								} else {
-									switch (e.type) {
-										case "input":
-											if (skipInputEvent === true || inComposition === true) {
-												skipInputEvent = false;
-												return e.preventDefault();
-											}
-											break;
-										case "keydown":
-											//Safari 5.1.x - modal dialog fires keypress twice workaround
-											skipKeyPressEvent = false;
-											inComposition = false;
-											break;
-										case "keypress":
-											if (skipKeyPressEvent === true) {
-												return e.preventDefault();
-											}
-											skipKeyPressEvent = true;
-
-											break;
-										case "compositionstart":
-											inComposition = true;
-											break;
-										case "compositionupdate":
-											skipInputEvent = true;
-											break;
-										case "compositionend":
-											inComposition = false;
-											break;
-									}
-									//console.log("executed " + e.type);
-									return handler.apply(this, arguments);
+			function wrapEvent(eventHandler) {
+				return function(e) {
+					// console.log("triggered " + e.type);
+					var inComposition = false;
+					if (this.inputmask === undefined) { //happens when cloning an object with jquery.clone
+						var imOpts = $.data(this, "_inputmask_opts");
+						if (imOpts)(new Inputmask(imOpts)).mask(this);
+						else $(this).off(".inputmask");
+					} else if (e.type !== "setvalue" && (this.disabled || (this.readOnly && !(e.type === "keydown" && (e.ctrlKey && e.keyCode === 67) || (opts.tabThrough === false && e.keyCode === Inputmask.keyCode.TAB))))) {
+						e.preventDefault();
+					} else {
+						switch (e.type) {
+							case "input":
+								if (skipInputEvent === true || inComposition === true) {
+									skipInputEvent = false;
+									return e.preventDefault();
 								}
-							};
+								break;
+							case "keydown":
+								//Safari 5.1.x - modal dialog fires keypress twice workaround
+								skipKeyPressEvent = false;
+								inComposition = false;
+								break;
+							case "keypress":
+								if (skipKeyPressEvent === true) {
+									return e.preventDefault();
+								}
+								skipKeyPressEvent = true;
+
+								break;
+							case "compositionstart":
+								inComposition = true;
+								break;
+							case "compositionupdate":
+								skipInputEvent = true;
+								break;
+							case "compositionend":
+								inComposition = false;
+								break;
 						}
-					});
-				});
+						//console.log("executed " + e.type);
+						return eventHandler.apply(this, arguments);
+					}
+				};
 			}
 
 			function patchValueProperty(npt) {
@@ -1893,25 +1887,25 @@
 				}
 
 				function installNativeValueSetFallback(npt) {
-					$(npt).on("mouseenter.inputmask", function(event) {
+					$(npt).on("mouseenter.inputmask", wrapEvent(function(event) {
 						var $input = $(this),
 							input = this,
 							value = input.inputmask._valueGet();
 						if (value !== "" && value !== getBuffer().join("")) {
 							$input.triggerHandler("setvalue.inputmask");
 						}
-					});
-					//!! the bound handlers are executed in the order they where bound
-					//reorder the events - the mouseenter event is internally mapped to the mouseover event
-					var events = $._data(npt).events;
-					var handlers = events.mouseover;
-					if (handlers) {
-						var ourHandler = handlers[handlers.length - 1];
-						for (var i = handlers.length - 1; i > 0; i--) {
-							handlers[i] = handlers[i - 1];
-						}
-						handlers[0] = ourHandler;
-					}
+					}));
+					// //!! the bound handlers are executed in the order they where bound
+					// //reorder the events - the mouseenter event is internally mapped to the mouseover event
+					// var events = $._data(npt).events;
+					// var handlers = events.mouseover;
+					// if (handlers) {
+					// 	var ourHandler = handlers[handlers.length - 1];
+					// 	for (var i = handlers.length - 1; i > 0; i--) {
+					// 		handlers[i] = handlers[i - 1];
+					// 	}
+					// 	handlers[0] = ourHandler;
+					// }
 				}
 
 				if (!npt.inputmask.__valueGet) {
@@ -1949,7 +1943,7 @@
 					};
 					npt.inputmask.__valueSet = valueSet; //store native property setter
 					npt.inputmask._valueSet = function(value, overruleRTL) {
-						valueSet.call(this.el, (overruleRTL !== true && isRTL) ? value.split("").reverse().join("") : value);
+						valueSet.call(this.el, (overruleRTL !== true && isRTL && value !== null && value !== undefined) ? value.split("").reverse().join("") : value);
 					};
 				}
 			}
@@ -2471,7 +2465,7 @@
 
 				//unbind all events - to make sure that no other mask will interfere when re-masking
 				$el.off(".inputmask");
-
+				patchValueProperty(el);
 				if ((el.tagName === "INPUT" && isInputTypeSupported(el.getAttribute("type"))) || el.isContentEditable) {
 					//bind events
 					$(el.form).on("submit", function() { //trigger change on submit if any
@@ -2493,35 +2487,36 @@
 						}, 0);
 					});
 
-					$el.on("mouseenter.inputmask", mouseenterEvent)
-						.on("blur.inputmask", blurEvent)
-						.on("focus.inputmask", focusEvent)
-						.on("mouseleave.inputmask", mouseleaveEvent)
-						.on("click.inputmask", clickEvent)
-						.on("dblclick.inputmask", dblclickEvent)
-						.on(PasteEventType + ".inputmask dragdrop.inputmask drop.inputmask", pasteEvent)
-						.on("cut.inputmask", cutEvent)
-						.on("complete.inputmask", opts.oncomplete)
-						.on("incomplete.inputmask", opts.onincomplete)
-						.on("cleared.inputmask", opts.oncleared)
-						.on("keydown.inputmask", keydownEvent)
-						.on("keypress.inputmask", keypressEvent);
+					$el.on("mouseenter.inputmask", wrapEvent(mouseenterEvent))
+						.on("blur.inputmask", wrapEvent(blurEvent))
+						.on("focus.inputmask", wrapEvent(focusEvent))
+						.on("mouseleave.inputmask", wrapEvent(mouseleaveEvent))
+						.on("click.inputmask", wrapEvent(clickEvent))
+						.on("dblclick.inputmask", wrapEvent(dblclickEvent))
+						.on(PasteEventType + ".inputmask dragdrop.inputmask drop.inputmask", wrapEvent(pasteEvent))
+						.on("cut.inputmask", wrapEvent(cutEvent))
+						.on("complete.inputmask", wrapEvent(opts.oncomplete))
+						.on("incomplete.inputmask", wrapEvent(opts.onincomplete))
+						.on("cleared.inputmask", wrapEvent(opts.oncleared))
+						.on("keydown.inputmask", wrapEvent(keydownEvent))
+						.on("keypress.inputmask", wrapEvent(keypressEvent));
 
 
 					if (!androidfirefox) {
-						$el.on("compositionstart.inputmask", compositionStartEvent).on("compositionupdate.inputmask", compositionUpdateEvent).on("compositionend.inputmask", compositionEndEvent);
+						$el.on("compositionstart.inputmask", wrapEvent(compositionStartEvent))
+							.on("compositionupdate.inputmask", wrapEvent(compositionUpdateEvent))
+							.on("compositionend.inputmask", wrapEvent(compositionEndEvent));
 					}
 
 					if (PasteEventType === "paste") {
-						$el.on("input.inputmask", inputFallBackEvent);
+						$el.on("input.inputmask", wrapEvent(inputFallBackEvent));
 					}
 					//if (android || androidfirefox || androidchrome || kindle) {
 					//		$el.off("input.inputmask");
 					//		$el.on("input.inputmask", mobileInputEvent);
 					//}
 				}
-				$el.on("setvalue.inputmask", setValueEvent);
-				patchValueProperty(el);
+				$el.on("setvalue.inputmask", wrapEvent(setValueEvent));
 
 				//apply mask
 				var initialValue = $.isFunction(opts.onBeforeMask) ? (opts.onBeforeMask.call(el, el.inputmask._valueGet(), opts) || el.inputmask._valueGet()) : el.inputmask._valueGet();
@@ -2549,8 +2544,6 @@
 				if (activeElement === el) { //position the caret when in focus
 					caret(el, seekNext(getLastValidPosition()));
 				}
-
-				installEventRuler(el);
 			}
 
 			//action object
@@ -2650,7 +2643,7 @@
 						maskset = el.inputmask.maskset;
 						opts = el.inputmask.opts;
 						//writeout the unmaskedvalue
-						el.inputmask._valueSet(unmaskedvalue($el));
+						el.inputmask._valueSet(unmaskedvalue(el));
 						//unbind all events
 						$el.off(".inputmask");
 						//restore the value property

+ 3 - 2
package.json

@@ -1,6 +1,6 @@
 {
   "name": "jquery.inputmask",
-  "version": "3.2.1-55",
+  "version": "3.2.1-85",
   "description": "jquery.inputmask is a jquery plugin which create an input mask.",
   "main": "./dist/inputmask/jquery.inputmask.js",
   "files": [
@@ -56,6 +56,7 @@
     "karma-qunit": "^0.1.5",
     "load-grunt-tasks": "^3.2.0",
     "qunitjs": "^1.19.0",
-    "requirejs": "^2.1.20"
+    "requirejs": "^2.1.20",
+    "zepto-component": "^1.0.0"
   }
 }

+ 21 - 5
qunit/config.js

@@ -3,6 +3,9 @@ requirejs.config({
 	paths: {
 		"jquery": "../node_modules/jquery/dist/jquery",
 		"jqlite": "../node_modules/jqlite/jqlite",
+		"zepto": "../node_modules/zepto-component/zepto",
+		"zepto_event": "../node_modules/zepto-component/src/event",
+		"zepto_data": "../node_modules/zepto-component/src/data",
 		"qunit": "../node_modules/qunitjs/qunit/qunit",
 		"dependencyLib": "../dist/inputmask/dependencyLib",
 		"inputmask": "../dist/inputmask/inputmask"
@@ -14,11 +17,24 @@ requirejs.config({
 			]
 		},
 		'qunit': {
-					exports: 'QUnit',
-					init: function() {
-							QUnit.config.autoload = false;
-							QUnit.config.autostart = false;
-					}
+			exports: 'QUnit',
+			init: function() {
+				QUnit.config.autoload = false;
+				QUnit.config.autostart = false;
 			}
+		},
+		"zepto": {
+			exports: "Zepto"
+		},
+		"zepto_data": {
+			deps: [
+				"zepto"
+			]
+		},
+		"zepto_event": {
+			deps: [
+				"zepto"
+			]
+		}
 	}
 });