Browse Source

move format & isvalid to inputmask

Robin Herbots 10 years ago
parent
commit
25337ee9cf

+ 2 - 2
README.md

@@ -878,14 +878,14 @@ $(document).ready(function(){
 Instead of masking an input element it is also possible to use the inputmask for formatting given values. Think of formatting values to show in jqGrid or on other elements then inputs.
 
 ```javascript
-var formattedDate = $.inputmask.format("2331973", { alias: "dd/mm/yyyy"});
+var formattedDate = inputmask.format("2331973", { alias: "dd/mm/yyyy"});
 ```
 
 ## Value validating
 Validate a given value against the mask.
 
 ```javascript
-var isValid = $.inputmask.isValid("23/03/1973", { alias: "dd/mm/yyyy"});
+var isValid = inputmask.isValid("23/03/1973", { alias: "dd/mm/yyyy"});
 ```
 
 ## .NET Nuget Package Install

+ 1 - 1
bower.json

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

+ 2 - 2
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.1.64-48
+* Version: 3.1.64-54
 */
 !function(factory) {
     "function" == typeof define && define.amd ? define([ "jquery", "./inputmask" ], factory) : "object" == typeof exports ? module.exports = factory(require("jquery"), require("./inputmask")) : factory(jQuery);
@@ -457,5 +457,5 @@
             separator: "/",
             alias: "mm/dd/yyyy"
         }
-    }), $.fn.inputmask;
+    }), inputmask;
 });

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


+ 2 - 2
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.1.64-48
+* Version: 3.1.64-54
 */
 !function(factory) {
     "function" == typeof define && define.amd ? define([ "jquery", "./inputmask" ], factory) : "object" == typeof exports ? module.exports = factory(require("jquery"), require("./inputmask")) : factory(jQuery);
@@ -103,5 +103,5 @@
                 }
             }
         }
-    }), $.fn.inputmask;
+    }), inputmask;
 });

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


+ 45 - 60
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.1.64-48
+* Version: 3.1.64-54
 */
 !function(factory) {
     "function" == typeof define && define.amd ? define([ "jquery" ], factory) : "object" == typeof exports ? module.exports = factory(require("jquery")) : factory(jQuery);
@@ -669,7 +669,7 @@
             return $.inputmask.escapeRegex(str);
         }
         function unmaskedvalue($input) {
-            if ($input.data("_inputmask") && !$input.hasClass("hasDatepicker")) {
+            if ($input[0].inputmask && !$input.hasClass("hasDatepicker")) {
                 var umValue = [], vps = getMaskSet().validPositions;
                 for (var pndx in vps) vps[pndx].match && null != vps[pndx].match.fn && umValue.push(vps[pndx].input);
                 var unmaskedValue = (isRTL ? umValue.reverse() : umValue).join(""), bufferValue = (isRTL ? getBuffer().slice().reverse() : getBuffer()).join("");
@@ -802,17 +802,17 @@
                     };
                     $.valHooks[type] = {
                         get: function(elem) {
-                            var $elem = $(elem);
-                            if ($elem.data("_inputmask")) {
-                                if ($elem.data("_inputmask").opts.autoUnmask) return $elem.inputmask("unmaskedvalue");
-                                var result = valhookGet(elem), inputData = $elem.data("_inputmask"), maskset = inputData.maskset, bufferTemplate = maskset._buffer;
+                            $(elem);
+                            if (elem.inputmask) {
+                                if (elem.inputmask.opts.autoUnmask) return elem.inputmask.unmaskedvalue();
+                                var result = valhookGet(elem), maskset = elem.inputmask.maskset, bufferTemplate = maskset._buffer;
                                 return bufferTemplate = bufferTemplate ? bufferTemplate.join("") : "", result != bufferTemplate ? result : "";
                             }
                             return valhookGet(elem);
                         },
                         set: function(elem, value) {
-                            var result, $elem = $(elem), inputData = $elem.data("_inputmask");
-                            return result = valhookSet(elem, value), inputData && $elem.triggerHandler("setvalue.inputmask"), 
+                            var result, $elem = $(elem);
+                            return result = valhookSet(elem, value), elem.inputmask && $elem.triggerHandler("setvalue.inputmask"), 
                             result;
                         },
                         inputmaskpatch: !0
@@ -820,12 +820,11 @@
                 }
             }
             function getter() {
-                var $self = $(this), inputData = $(this).data("_inputmask");
-                return inputData ? inputData.opts.autoUnmask ? $self.inputmask("unmaskedvalue") : valueGet.call(this) != getBufferTemplate().join("") ? valueGet.call(this) : "" : valueGet.call(this);
+                $(this);
+                return this.inputmask ? this.inputmask.opts.autoUnmask ? this.inputmask.unmaskedvalue() : valueGet.call(this) != getBufferTemplate().join("") ? valueGet.call(this) : "" : valueGet.call(this);
             }
             function setter(value) {
-                var inputData = $(this).data("_inputmask");
-                valueSet.call(this, value), inputData && $(this).triggerHandler("setvalue.inputmask");
+                valueSet.call(this, value), this.inputmask && $(this).triggerHandler("setvalue.inputmask");
             }
             function InstallNativeValueSetFallback(npt) {
                 $(npt).bind("mouseenter.inputmask", function(event) {
@@ -1005,17 +1004,9 @@
         }
         function compositionEndEvent(e) {}
         function mask(el) {
-            if ($el = $(el), $el.data("_inputmask", {
-                maskset: maskset,
-                opts: opts,
-                isRTL: !1
-            }), opts.showTooltip && $el.prop("title", getMaskSet().mask), ("rtl" == el.dir || opts.rightAlign) && $el.css("text-align", "right"), 
-            "rtl" == el.dir || opts.numericInput) {
-                el.dir = "ltr", $el.removeAttr("dir");
-                var inputData = $el.data("_inputmask");
-                inputData.isRTL = !0, $el.data("_inputmask", inputData), isRTL = !0;
-            }
-            $el.unbind(".inputmask"), ($el.is(":input") && isInputTypeSupported($el.attr("type")) || el.isContentEditable) && ($el.closest("form").bind("submit", function(e) {
+            $el = $(el), opts.showTooltip && $el.prop("title", getMaskSet().mask), ("rtl" == el.dir || opts.rightAlign) && $el.css("text-align", "right"), 
+            ("rtl" == el.dir || opts.numericInput) && (el.dir = "ltr", $el.removeAttr("dir"), 
+            el.inputmask.isRTL = !0, isRTL = !0), $el.unbind(".inputmask"), ($el.is(":input") && isInputTypeSupported($el.attr("type")) || el.isContentEditable) && ($el.closest("form").bind("submit", function(e) {
                 undoValue != getBuffer().join("") && $el.change(), opts.clearMaskOnLostFocus && $el[0]._valueGet && $el[0]._valueGet() == getBufferTemplate().join("") && $el[0]._valueSet(""), 
                 opts.removeMaskOnSubmit && $el.inputmask("remove");
             }).bind("reset", function() {
@@ -1027,7 +1018,7 @@
                 !$input.is(":focus") && opts.showMaskOnHover && input._valueGet() != getBuffer().join("") && writeBuffer(input, getBuffer());
             }).bind("blur.inputmask", function(e) {
                 var $input = $(this), input = this;
-                if ($input.data("_inputmask")) {
+                if (input.inputmask) {
                     var nptValue = input._valueGet(), buffer = getBuffer().slice();
                     firstClick = !0, undoValue != buffer.join("") && setTimeout(function() {
                         $input.change(), undoValue = buffer.join("");
@@ -1091,23 +1082,21 @@
         var undoValue, compositionCaretPos, compositionData, $el, maxLength, isRTL = !1, skipKeyPressEvent = !1, skipInputEvent = !1, ignorable = !1, firstClick = !0;
         if (void 0 != actionObj) switch (actionObj.action) {
           case "isComplete":
-            return $el = $(actionObj.el), maskset = $el.data("_inputmask").maskset, opts = $el.data("_inputmask").opts, 
+            return el = actionObj.el, $el = $(el), maskset = el.inputmask.maskset, opts = el.inputmask.opts, 
             isComplete(actionObj.buffer);
 
           case "unmaskedvalue":
-            return $el = $(actionObj.el), maskset = $el.data("_inputmask").maskset, opts = $el.data("_inputmask").opts, 
-            isRTL = $el.data("_inputmask").isRTL, unmaskedvalue($el);
+            return el = actionObj.el, $el = $(el), maskset = el.inputmask.maskset, opts = el.inputmask.opts, 
+            isRTL = el.inputmask.isRTL, unmaskedvalue($el);
 
           case "mask":
             undoValue = getBuffer().join(""), mask(actionObj.el);
             break;
 
           case "format":
-            $el = $({}), $el.data("_inputmask", {
-                maskset: maskset,
-                opts: opts,
-                isRTL: opts.numericInput
-            }), opts.numericInput && (isRTL = !0);
+            $el = $({}), $el[0].inputmask = new inputmask(), $el[0].inputmask.opts = opts, $el[0].inputmask.el = $el[0], 
+            $el[0].inputmask.maskset = maskset, $el[0].inputmask.isRTL = opts.numericInput, 
+            opts.numericInput && (isRTL = !0);
             var valueBuffer = ($.isFunction(opts.onBeforeMask) ? opts.onBeforeMask.call($el, actionObj.value, opts) || actionObj.value : actionObj.value).split("");
             return checkVal($el, !1, !1, isRTL ? valueBuffer.reverse() : valueBuffer), $.isFunction(opts.onBeforeWrite) && opts.onBeforeWrite.call(this, void 0, getBuffer(), 0, opts), 
             actionObj.metadata ? {
@@ -1116,24 +1105,21 @@
             } : isRTL ? getBuffer().slice().reverse().join("") : getBuffer().join("");
 
           case "isValid":
-            $el = $({}), $el.data("_inputmask", {
-                maskset: maskset,
-                opts: opts,
-                isRTL: opts.numericInput
-            }), opts.numericInput && (isRTL = !0);
+            $el = $({}), $el[0].inputmask = new inputmask(), $el[0].inputmask.opts = opts, $el[0].inputmask.el = $el[0], 
+            $el[0].inputmask.maskset = maskset, $el[0].inputmask.isRTL = opts.numericInput, 
+            opts.numericInput && (isRTL = !0);
             var valueBuffer = actionObj.value.split("");
             checkVal($el, !1, !0, isRTL ? valueBuffer.reverse() : valueBuffer);
             for (var buffer = getBuffer(), rl = determineLastRequiredPosition(), lmib = buffer.length - 1; lmib > rl && !isMask(lmib); lmib--) ;
             return buffer.splice(rl, lmib + 1 - rl), isComplete(buffer) && actionObj.value == buffer.join("");
 
           case "getemptymask":
-            return $el = $(actionObj.el), maskset = $el.data("_inputmask").maskset, opts = $el.data("_inputmask").opts, 
+            return el = actionObj.el, $el = $(el), maskset = el.inputmask.maskset, opts = el.inputmask.opts, 
             getBufferTemplate();
 
           case "remove":
-            var el = actionObj.el;
-            $el = $(el), maskset = $el.data("_inputmask").maskset, opts = $el.data("_inputmask").opts, 
-            el._valueSet(unmaskedvalue($el)), $el.unbind(".inputmask"), $el.removeData("_inputmask");
+            el = actionObj.el, $el = $(el), maskset = el.inputmask.maskset, opts = el.inputmask.opts, 
+            el._valueSet(unmaskedvalue($el)), $el.unbind(".inputmask"), el.inputmask = void 0;
             var valueProperty;
             Object.getOwnPropertyDescriptor && (valueProperty = Object.getOwnPropertyDescriptor(el, "value")), 
             valueProperty && valueProperty.get ? el._valueGet && Object.defineProperty(el, "value", {
@@ -1149,7 +1135,7 @@
             break;
 
           case "getmetadata":
-            if ($el = $(actionObj.el), maskset = $el.data("_inputmask").maskset, opts = $el.data("_inputmask").opts, 
+            if (el = actionObj.el, $el = $(el), maskset = el.inputmask.maskset, opts = el.inputmask.opts, 
             $.isArray(maskset.metadata)) {
                 for (var alternation, lvp = getLastValidPosition(), firstAlt = lvp; firstAlt >= 0; firstAlt--) if (getMaskSet().validPositions[firstAlt] && void 0 != getMaskSet().validPositions[firstAlt].alternation) {
                     alternation = getMaskSet().validPositions[firstAlt].alternation;
@@ -1268,30 +1254,16 @@
             var specials = [ "/", ".", "*", "+", "?", "|", "(", ")", "[", "]", "{", "}", "\\", "$", "^" ];
             return str.replace(new RegExp("(\\" + specials.join("|\\") + ")", "gim"), "\\$1");
         },
-        format: function(value, options, metadata) {
-            var opts = $.extend(!0, {}, $.inputmask.defaults, options);
-            return resolveAlias(opts.alias, options, opts), maskScope({
-                action: "format",
-                value: value,
-                metadata: metadata
-            }, generateMaskSet(opts, options && void 0 !== options.definitions), opts);
-        },
-        isValid: function(value, options) {
-            var opts = $.extend(!0, {}, $.inputmask.defaults, options);
-            return resolveAlias(opts.alias, options, opts), maskScope({
-                action: "isValid",
-                value: value
-            }, generateMaskSet(opts, options && void 0 !== options.definitions), opts);
-        },
         mask: function(el) {
             var input = el.jquery && el.length > 0 ? el[0] : el;
             importAttributeOptions(el, this.opts, this.userOptions);
             var maskset = generateMaskSet(this.opts, this.noMasksCache);
-            return void 0 != maskset && maskScope({
+            return void 0 != maskset && (input.inputmask = new inputmask(), input.inputmask.opts = this.opts, 
+            input.inputmask.noMasksCache = this.noMasksCache, input.inputmask.el = input, input.inputmask.maskset = maskset, 
+            input.inputmask.isRTL = !1, maskScope({
                 action: "mask",
                 el: input
-            }, maskset, this.opts), input.inputmask = new inputmask(), input.inputmask.opts = this.opts, 
-            input.inputmask.noMasksCache = this.noMasksCache, input.inputmask.el = input, el;
+            }, maskset, this.opts)), el;
         },
         unmaskedvalue: function() {
             return this.el ? maskScope({
@@ -1333,6 +1305,19 @@
         $.extend(inputmask.prototype.defaults.definitions, definition);
     }, inputmask.extendAliases = function(alias) {
         $.extend(inputmask.prototype.defaults.aliases, alias);
+    }, inputmask.format = function(value, options, metadata) {
+        var opts = $.extend(!0, {}, $.inputmask.defaults, options);
+        return resolveAlias(opts.alias, options, opts), maskScope({
+            action: "format",
+            value: value,
+            metadata: metadata
+        }, generateMaskSet(opts, options && void 0 !== options.definitions), opts);
+    }, inputmask.isValid = function(value, options) {
+        var opts = $.extend(!0, {}, $.inputmask.defaults, options);
+        return resolveAlias(opts.alias, options, opts), maskScope({
+            action: "isValid",
+            value: value
+        }, generateMaskSet(opts, options && void 0 !== options.definitions), opts);
     };
     var ua = navigator.userAgent, iphone = null !== ua.match(new RegExp("iphone", "i")), androidchrome = (null !== ua.match(new RegExp("android.*safari.*", "i")), 
     null !== ua.match(new RegExp("android.*chrome.*", "i"))), androidfirefox = null !== ua.match(new RegExp("android.*firefox.*", "i")), PasteEventType = (/Kindle/i.test(ua) || /Silk/i.test(ua) || /KFTT/i.test(ua) || /KFOT/i.test(ua) || /KFJWA/i.test(ua) || /KFJWI/i.test(ua) || /KFSOWI/i.test(ua) || /KFTHWA/i.test(ua) || /KFTHWI/i.test(ua) || /KFAPWA/i.test(ua) || /KFAPWI/i.test(ua), 

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


+ 2 - 2
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.1.64-48
+* Version: 3.1.64-54
 */
 !function(factory) {
     "function" == typeof define && define.amd ? define([ "jquery", "./inputmask" ], factory) : "object" == typeof exports ? module.exports = factory(require("jquery"), require("./inputmask")) : factory(jQuery);
@@ -355,5 +355,5 @@
             digits: "0",
             radixPoint: ""
         }
-    }), $.fn.inputmask;
+    }), inputmask;
 });

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


+ 2 - 2
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.1.64-48
+* Version: 3.1.64-54
 */
 !function(factory) {
     "function" == typeof define && define.amd ? define([ "jquery", "./inputmask" ], factory) : "object" == typeof exports ? module.exports = factory(require("jquery"), require("./inputmask")) : factory(jQuery);
@@ -44,5 +44,5 @@
             countrycode: "32",
             nojumpsThreshold: 4
         }
-    }), $.fn.inputmask;
+    }), inputmask;
 });

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


+ 2 - 2
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.1.64-48
+* Version: 3.1.64-54
 */
 !function(factory) {
     "function" == typeof define && define.amd ? define([ "jquery", "./inputmask" ], factory) : "object" == typeof exports ? module.exports = factory(require("jquery"), require("./inputmask")) : factory(jQuery);
@@ -120,5 +120,5 @@
                 }
             }
         }
-    }), $.fn.inputmask;
+    }), inputmask;
 });

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


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

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


+ 50 - 65
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-48
+* Version: 3.1.64-54
 */
 !function($) {
     function inputmask(options) {
@@ -667,7 +667,7 @@
             return $.inputmask.escapeRegex(str);
         }
         function unmaskedvalue($input) {
-            if ($input.data("_inputmask") && !$input.hasClass("hasDatepicker")) {
+            if ($input[0].inputmask && !$input.hasClass("hasDatepicker")) {
                 var umValue = [], vps = getMaskSet().validPositions;
                 for (var pndx in vps) vps[pndx].match && null != vps[pndx].match.fn && umValue.push(vps[pndx].input);
                 var unmaskedValue = (isRTL ? umValue.reverse() : umValue).join(""), bufferValue = (isRTL ? getBuffer().slice().reverse() : getBuffer()).join("");
@@ -800,17 +800,17 @@
                     };
                     $.valHooks[type] = {
                         get: function(elem) {
-                            var $elem = $(elem);
-                            if ($elem.data("_inputmask")) {
-                                if ($elem.data("_inputmask").opts.autoUnmask) return $elem.inputmask("unmaskedvalue");
-                                var result = valhookGet(elem), inputData = $elem.data("_inputmask"), maskset = inputData.maskset, bufferTemplate = maskset._buffer;
+                            $(elem);
+                            if (elem.inputmask) {
+                                if (elem.inputmask.opts.autoUnmask) return elem.inputmask.unmaskedvalue();
+                                var result = valhookGet(elem), maskset = elem.inputmask.maskset, bufferTemplate = maskset._buffer;
                                 return bufferTemplate = bufferTemplate ? bufferTemplate.join("") : "", result != bufferTemplate ? result : "";
                             }
                             return valhookGet(elem);
                         },
                         set: function(elem, value) {
-                            var result, $elem = $(elem), inputData = $elem.data("_inputmask");
-                            return result = valhookSet(elem, value), inputData && $elem.triggerHandler("setvalue.inputmask"), 
+                            var result, $elem = $(elem);
+                            return result = valhookSet(elem, value), elem.inputmask && $elem.triggerHandler("setvalue.inputmask"), 
                             result;
                         },
                         inputmaskpatch: !0
@@ -818,12 +818,11 @@
                 }
             }
             function getter() {
-                var $self = $(this), inputData = $(this).data("_inputmask");
-                return inputData ? inputData.opts.autoUnmask ? $self.inputmask("unmaskedvalue") : valueGet.call(this) != getBufferTemplate().join("") ? valueGet.call(this) : "" : valueGet.call(this);
+                $(this);
+                return this.inputmask ? this.inputmask.opts.autoUnmask ? this.inputmask.unmaskedvalue() : valueGet.call(this) != getBufferTemplate().join("") ? valueGet.call(this) : "" : valueGet.call(this);
             }
             function setter(value) {
-                var inputData = $(this).data("_inputmask");
-                valueSet.call(this, value), inputData && $(this).triggerHandler("setvalue.inputmask");
+                valueSet.call(this, value), this.inputmask && $(this).triggerHandler("setvalue.inputmask");
             }
             function InstallNativeValueSetFallback(npt) {
                 $(npt).bind("mouseenter.inputmask", function(event) {
@@ -1003,17 +1002,9 @@
         }
         function compositionEndEvent(e) {}
         function mask(el) {
-            if ($el = $(el), $el.data("_inputmask", {
-                maskset: maskset,
-                opts: opts,
-                isRTL: !1
-            }), opts.showTooltip && $el.prop("title", getMaskSet().mask), ("rtl" == el.dir || opts.rightAlign) && $el.css("text-align", "right"), 
-            "rtl" == el.dir || opts.numericInput) {
-                el.dir = "ltr", $el.removeAttr("dir");
-                var inputData = $el.data("_inputmask");
-                inputData.isRTL = !0, $el.data("_inputmask", inputData), isRTL = !0;
-            }
-            $el.unbind(".inputmask"), ($el.is(":input") && isInputTypeSupported($el.attr("type")) || el.isContentEditable) && ($el.closest("form").bind("submit", function(e) {
+            $el = $(el), opts.showTooltip && $el.prop("title", getMaskSet().mask), ("rtl" == el.dir || opts.rightAlign) && $el.css("text-align", "right"), 
+            ("rtl" == el.dir || opts.numericInput) && (el.dir = "ltr", $el.removeAttr("dir"), 
+            el.inputmask.isRTL = !0, isRTL = !0), $el.unbind(".inputmask"), ($el.is(":input") && isInputTypeSupported($el.attr("type")) || el.isContentEditable) && ($el.closest("form").bind("submit", function(e) {
                 undoValue != getBuffer().join("") && $el.change(), opts.clearMaskOnLostFocus && $el[0]._valueGet && $el[0]._valueGet() == getBufferTemplate().join("") && $el[0]._valueSet(""), 
                 opts.removeMaskOnSubmit && $el.inputmask("remove");
             }).bind("reset", function() {
@@ -1025,7 +1016,7 @@
                 !$input.is(":focus") && opts.showMaskOnHover && input._valueGet() != getBuffer().join("") && writeBuffer(input, getBuffer());
             }).bind("blur.inputmask", function(e) {
                 var $input = $(this), input = this;
-                if ($input.data("_inputmask")) {
+                if (input.inputmask) {
                     var nptValue = input._valueGet(), buffer = getBuffer().slice();
                     firstClick = !0, undoValue != buffer.join("") && setTimeout(function() {
                         $input.change(), undoValue = buffer.join("");
@@ -1089,23 +1080,21 @@
         var undoValue, compositionCaretPos, compositionData, $el, maxLength, isRTL = !1, skipKeyPressEvent = !1, skipInputEvent = !1, ignorable = !1, firstClick = !0;
         if (void 0 != actionObj) switch (actionObj.action) {
           case "isComplete":
-            return $el = $(actionObj.el), maskset = $el.data("_inputmask").maskset, opts = $el.data("_inputmask").opts, 
+            return el = actionObj.el, $el = $(el), maskset = el.inputmask.maskset, opts = el.inputmask.opts, 
             isComplete(actionObj.buffer);
 
           case "unmaskedvalue":
-            return $el = $(actionObj.el), maskset = $el.data("_inputmask").maskset, opts = $el.data("_inputmask").opts, 
-            isRTL = $el.data("_inputmask").isRTL, unmaskedvalue($el);
+            return el = actionObj.el, $el = $(el), maskset = el.inputmask.maskset, opts = el.inputmask.opts, 
+            isRTL = el.inputmask.isRTL, unmaskedvalue($el);
 
           case "mask":
             undoValue = getBuffer().join(""), mask(actionObj.el);
             break;
 
           case "format":
-            $el = $({}), $el.data("_inputmask", {
-                maskset: maskset,
-                opts: opts,
-                isRTL: opts.numericInput
-            }), opts.numericInput && (isRTL = !0);
+            $el = $({}), $el[0].inputmask = new inputmask(), $el[0].inputmask.opts = opts, $el[0].inputmask.el = $el[0], 
+            $el[0].inputmask.maskset = maskset, $el[0].inputmask.isRTL = opts.numericInput, 
+            opts.numericInput && (isRTL = !0);
             var valueBuffer = ($.isFunction(opts.onBeforeMask) ? opts.onBeforeMask.call($el, actionObj.value, opts) || actionObj.value : actionObj.value).split("");
             return checkVal($el, !1, !1, isRTL ? valueBuffer.reverse() : valueBuffer), $.isFunction(opts.onBeforeWrite) && opts.onBeforeWrite.call(this, void 0, getBuffer(), 0, opts), 
             actionObj.metadata ? {
@@ -1114,24 +1103,21 @@
             } : isRTL ? getBuffer().slice().reverse().join("") : getBuffer().join("");
 
           case "isValid":
-            $el = $({}), $el.data("_inputmask", {
-                maskset: maskset,
-                opts: opts,
-                isRTL: opts.numericInput
-            }), opts.numericInput && (isRTL = !0);
+            $el = $({}), $el[0].inputmask = new inputmask(), $el[0].inputmask.opts = opts, $el[0].inputmask.el = $el[0], 
+            $el[0].inputmask.maskset = maskset, $el[0].inputmask.isRTL = opts.numericInput, 
+            opts.numericInput && (isRTL = !0);
             var valueBuffer = actionObj.value.split("");
             checkVal($el, !1, !0, isRTL ? valueBuffer.reverse() : valueBuffer);
             for (var buffer = getBuffer(), rl = determineLastRequiredPosition(), lmib = buffer.length - 1; lmib > rl && !isMask(lmib); lmib--) ;
             return buffer.splice(rl, lmib + 1 - rl), isComplete(buffer) && actionObj.value == buffer.join("");
 
           case "getemptymask":
-            return $el = $(actionObj.el), maskset = $el.data("_inputmask").maskset, opts = $el.data("_inputmask").opts, 
+            return el = actionObj.el, $el = $(el), maskset = el.inputmask.maskset, opts = el.inputmask.opts, 
             getBufferTemplate();
 
           case "remove":
-            var el = actionObj.el;
-            $el = $(el), maskset = $el.data("_inputmask").maskset, opts = $el.data("_inputmask").opts, 
-            el._valueSet(unmaskedvalue($el)), $el.unbind(".inputmask"), $el.removeData("_inputmask");
+            el = actionObj.el, $el = $(el), maskset = el.inputmask.maskset, opts = el.inputmask.opts, 
+            el._valueSet(unmaskedvalue($el)), $el.unbind(".inputmask"), el.inputmask = void 0;
             var valueProperty;
             Object.getOwnPropertyDescriptor && (valueProperty = Object.getOwnPropertyDescriptor(el, "value")), 
             valueProperty && valueProperty.get ? el._valueGet && Object.defineProperty(el, "value", {
@@ -1147,7 +1133,7 @@
             break;
 
           case "getmetadata":
-            if ($el = $(actionObj.el), maskset = $el.data("_inputmask").maskset, opts = $el.data("_inputmask").opts, 
+            if (el = actionObj.el, $el = $(el), maskset = el.inputmask.maskset, opts = el.inputmask.opts, 
             $.isArray(maskset.metadata)) {
                 for (var alternation, lvp = getLastValidPosition(), firstAlt = lvp; firstAlt >= 0; firstAlt--) if (getMaskSet().validPositions[firstAlt] && void 0 != getMaskSet().validPositions[firstAlt].alternation) {
                     alternation = getMaskSet().validPositions[firstAlt].alternation;
@@ -1266,30 +1252,16 @@
             var specials = [ "/", ".", "*", "+", "?", "|", "(", ")", "[", "]", "{", "}", "\\", "$", "^" ];
             return str.replace(new RegExp("(\\" + specials.join("|\\") + ")", "gim"), "\\$1");
         },
-        format: function(value, options, metadata) {
-            var opts = $.extend(!0, {}, $.inputmask.defaults, options);
-            return resolveAlias(opts.alias, options, opts), maskScope({
-                action: "format",
-                value: value,
-                metadata: metadata
-            }, generateMaskSet(opts, options && void 0 !== options.definitions), opts);
-        },
-        isValid: function(value, options) {
-            var opts = $.extend(!0, {}, $.inputmask.defaults, options);
-            return resolveAlias(opts.alias, options, opts), maskScope({
-                action: "isValid",
-                value: value
-            }, generateMaskSet(opts, options && void 0 !== options.definitions), opts);
-        },
         mask: function(el) {
             var input = el.jquery && el.length > 0 ? el[0] : el;
             importAttributeOptions(el, this.opts, this.userOptions);
             var maskset = generateMaskSet(this.opts, this.noMasksCache);
-            return void 0 != maskset && maskScope({
+            return void 0 != maskset && (input.inputmask = new inputmask(), input.inputmask.opts = this.opts, 
+            input.inputmask.noMasksCache = this.noMasksCache, input.inputmask.el = input, input.inputmask.maskset = maskset, 
+            input.inputmask.isRTL = !1, maskScope({
                 action: "mask",
                 el: input
-            }, maskset, this.opts), input.inputmask = new inputmask(), input.inputmask.opts = this.opts, 
-            input.inputmask.noMasksCache = this.noMasksCache, input.inputmask.el = input, el;
+            }, maskset, this.opts)), el;
         },
         unmaskedvalue: function() {
             return this.el ? maskScope({
@@ -1331,6 +1303,19 @@
         $.extend(inputmask.prototype.defaults.definitions, definition);
     }, inputmask.extendAliases = function(alias) {
         $.extend(inputmask.prototype.defaults.aliases, alias);
+    }, inputmask.format = function(value, options, metadata) {
+        var opts = $.extend(!0, {}, $.inputmask.defaults, options);
+        return resolveAlias(opts.alias, options, opts), maskScope({
+            action: "format",
+            value: value,
+            metadata: metadata
+        }, generateMaskSet(opts, options && void 0 !== options.definitions), opts);
+    }, inputmask.isValid = function(value, options) {
+        var opts = $.extend(!0, {}, $.inputmask.defaults, options);
+        return resolveAlias(opts.alias, options, opts), maskScope({
+            action: "isValid",
+            value: value
+        }, generateMaskSet(opts, options && void 0 !== options.definitions), opts);
     };
     var ua = navigator.userAgent, iphone = null !== ua.match(new RegExp("iphone", "i")), androidchrome = (null !== ua.match(new RegExp("android.*safari.*", "i")), 
     null !== ua.match(new RegExp("android.*chrome.*", "i"))), androidfirefox = null !== ua.match(new RegExp("android.*firefox.*", "i")), PasteEventType = (/Kindle/i.test(ua) || /Silk/i.test(ua) || /KFTT/i.test(ua) || /KFOT/i.test(ua) || /KFJWA/i.test(ua) || /KFJWI/i.test(ua) || /KFSOWI/i.test(ua) || /KFTHWA/i.test(ua) || /KFTHWI/i.test(ua) || /KFAPWA/i.test(ua) || /KFAPWI/i.test(ua), 
@@ -1834,7 +1819,7 @@
             separator: "/",
             alias: "mm/dd/yyyy"
         }
-    }), $.fn.inputmask;
+    }), inputmask;
 }(jQuery), function($) {
     return inputmask.extendDefinitions({
         A: {
@@ -1931,7 +1916,7 @@
                 }
             }
         }
-    }), $.fn.inputmask;
+    }), inputmask;
 }(jQuery), function($) {
     return inputmask.extendAliases({
         numeric: {
@@ -2280,7 +2265,7 @@
             digits: "0",
             radixPoint: ""
         }
-    }), $.fn.inputmask;
+    }), inputmask;
 }(jQuery), function($) {
     return inputmask.extendAliases({
         phone: {
@@ -2318,7 +2303,7 @@
             countrycode: "32",
             nojumpsThreshold: 4
         }
-    }), $.fn.inputmask;
+    }), inputmask;
 }(jQuery), function($) {
     return inputmask.extendAliases({
         Regex: {
@@ -2432,5 +2417,5 @@
                 }
             }
         }
-    }), $.fn.inputmask;
+    }), inputmask;
 }(jQuery);

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


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

@@ -599,5 +599,5 @@ Optional extensions on the jquery.inputmask base
     }
   });
 
-  return $.fn.inputmask;
+  return inputmask;
 })(jQuery);

+ 1 - 1
js/inputmask.extensions.js

@@ -125,5 +125,5 @@ Optional extensions on the jquery.inputmask base
       }
     }
   });
-  return $.fn.inputmask;
+  return inputmask;
 })(jQuery);

+ 74 - 76
js/inputmask.js

@@ -128,39 +128,24 @@
       var specials = ['/', '.', '*', '+', '?', '|', '(', ')', '[', ']', '{', '}', '\\', '$', '^'];
       return str.replace(new RegExp('(\\' + specials.join('|\\') + ')', 'gim'), '\\$1');
     },
-    format: function(value, options, metadata) {
-      var opts = $.extend(true, {}, $.inputmask.defaults, options);
-      resolveAlias(opts.alias, options, opts);
-      return maskScope({
-        "action": "format",
-        "value": value,
-        "metadata": metadata
-      }, generateMaskSet(opts, options && options.definitions !== undefined), opts);
-    },
-    isValid: function(value, options) {
-      var opts = $.extend(true, {}, $.inputmask.defaults, options);
-      resolveAlias(opts.alias, options, opts);
-      return maskScope({
-        "action": "isValid",
-        "value": value
-      }, generateMaskSet(opts, options && options.definitions !== undefined), opts);
-    },
     mask: function(el) {
       var input = el.jquery && el.length > 0 ? el[0] : el;
       importAttributeOptions(el, this.opts, this.userOptions);
       var maskset = generateMaskSet(this.opts, this.noMasksCache);
       if (maskset != undefined) {
+        //store inputmask instance on the input with element reference
+        input.inputmask = new inputmask();
+        input.inputmask.opts = this.opts;
+        input.inputmask.noMasksCache = this.noMasksCache;
+        input.inputmask.el = input;
+        input.inputmask.maskset = maskset;
+        input.inputmask.isRTL = false;
+
         maskScope({
           "action": "mask",
           "el": input
         }, maskset, this.opts);
       }
-      //store inputmask instance on the input with element reference
-      input.inputmask = new inputmask();
-      input.inputmask.opts = this.opts;
-      input.inputmask.noMasksCache = this.noMasksCache;
-      input.inputmask.el = input;
-
       return el;
     },
     unmaskedvalue: function() {
@@ -219,7 +204,25 @@
     $.extend(inputmask.prototype.defaults.definitions, definition);
   }
   inputmask.extendAliases = function(alias) {
-    $.extend(inputmask.prototype.defaults.aliases, alias);
+      $.extend(inputmask.prototype.defaults.aliases, alias);
+    }
+    //static fn on inputmask
+  inputmask.format = function(value, options, metadata) {
+    var opts = $.extend(true, {}, $.inputmask.defaults, options);
+    resolveAlias(opts.alias, options, opts);
+    return maskScope({
+      "action": "format",
+      "value": value,
+      "metadata": metadata //true/false getmetadata
+    }, generateMaskSet(opts, options && options.definitions !== undefined), opts);
+  }
+  inputmask.isValid = function(value, options) {
+    var opts = $.extend(true, {}, $.inputmask.defaults, options);
+    resolveAlias(opts.alias, options, opts);
+    return maskScope({
+      "action": "isValid",
+      "value": value
+    }, generateMaskSet(opts, options && options.definitions !== undefined), opts);
   }
 
   //helper functions
@@ -1525,7 +1528,7 @@
     }
 
     function unmaskedvalue($input) {
-      if ($input.data('_inputmask') && !$input.hasClass('hasDatepicker')) {
+      if ($input[0].inputmask && !$input.hasClass('hasDatepicker')) {
         var umValue = [],
           vps = getMaskSet()["validPositions"];
         for (var pndx in vps) {
@@ -1748,13 +1751,12 @@
           $.valHooks[type] = {
             get: function(elem) {
               var $elem = $(elem);
-              if ($elem.data('_inputmask')) {
-                if ($elem.data('_inputmask')['opts'].autoUnmask)
-                  return $elem.inputmask('unmaskedvalue');
+              if (elem.inputmask) {
+                if (elem.inputmask.opts.autoUnmask)
+                  return elem.inputmask.unmaskedvalue();
                 else {
                   var result = valhookGet(elem),
-                    inputData = $elem.data('_inputmask'),
-                    maskset = inputData['maskset'],
+                    maskset = elem.inputmask.maskset,
                     bufferTemplate = maskset['_buffer'];
                   bufferTemplate = bufferTemplate ? bufferTemplate.join('') : '';
                   return result != bufferTemplate ? result : '';
@@ -1763,10 +1765,9 @@
             },
             set: function(elem, value) {
               var $elem = $(elem),
-                inputData = $elem.data('_inputmask'),
                 result;
               result = valhookSet(elem, value);
-              if (inputData)
+              if (elem.inputmask)
                 $elem.triggerHandler('setvalue.inputmask');
               return result;
             },
@@ -1776,17 +1777,15 @@
       }
 
       function getter() {
-        var $self = $(this),
-          inputData = $(this).data('_inputmask');
-        if (inputData) {
-          return inputData['opts'].autoUnmask ? $self.inputmask('unmaskedvalue') : (valueGet.call(this) != getBufferTemplate().join('') ? valueGet.call(this) : '');
+        var $self = $(this);
+        if (this.inputmask) {
+          return this.inputmask.opts.autoUnmask ? this.inputmask.unmaskedvalue() : (valueGet.call(this) != getBufferTemplate().join('') ? valueGet.call(this) : '');
         } else return valueGet.call(this);
       }
 
       function setter(value) {
-        var inputData = $(this).data('_inputmask');
         valueSet.call(this, value);
-        if (inputData)
+        if (this.inputmask)
           $(this).triggerHandler('setvalue.inputmask');
       }
 
@@ -2209,13 +2208,6 @@
     function mask(el) {
       $el = $(el);
 
-      //store tests & original buffer in the input element - used to get the unmasked value
-      $el.data('_inputmask', {
-        'maskset': maskset,
-        'opts': opts,
-        'isRTL': false
-      });
-
       //show tooltip
       if (opts.showTooltip) {
         $el.prop("title", getMaskSet()["mask"]);
@@ -2227,9 +2219,7 @@
       if (el.dir == "rtl" || opts.numericInput) {
         el.dir = "ltr";
         $el.removeAttr("dir");
-        var inputData = $el.data('_inputmask');
-        inputData['isRTL'] = true;
-        $el.data('_inputmask', inputData);
+        el.inputmask.isRTL = true;
         isRTL = true;
       }
 
@@ -2264,7 +2254,7 @@
         }).bind("blur.inputmask", function(e) {
           var $input = $(this),
             input = this;
-          if ($input.data('_inputmask')) {
+          if (input.inputmask) {
             var nptValue = input._valueGet(),
               buffer = getBuffer().slice();
             firstClick = true;
@@ -2429,15 +2419,17 @@
     if (actionObj != undefined) {
       switch (actionObj["action"]) {
         case "isComplete":
-          $el = $(actionObj["el"]);
-          maskset = $el.data('_inputmask')['maskset'];
-          opts = $el.data('_inputmask')['opts'];
+          el = actionObj["el"]
+          $el = $(el);
+          maskset = el.inputmask.maskset;
+          opts = el.inputmask.opts;
           return isComplete(actionObj["buffer"]);
         case "unmaskedvalue":
-          $el = $(actionObj["el"]);
-          maskset = $el.data('_inputmask')['maskset'];
-          opts = $el.data('_inputmask')['opts'];
-          isRTL = $el.data('_inputmask')['isRTL'];
+          el = actionObj["el"]
+          $el = $(el);
+          maskset = el.inputmask.maskset;
+          opts = el.inputmask.opts;
+          isRTL = el.inputmask.isRTL;
           return unmaskedvalue($el);
         case "mask":
           undoValue = getBuffer().join('');
@@ -2445,11 +2437,13 @@
           break;
         case "format":
           $el = $({});
-          $el.data('_inputmask', {
-            'maskset': maskset,
-            'opts': opts,
-            'isRTL': opts.numericInput
-          });
+          //store inputmask instance on the input with element reference
+          $el[0].inputmask = new inputmask();
+          $el[0].inputmask.opts = opts;
+          $el[0].inputmask.el = $el[0];
+          $el[0].inputmask.maskset = maskset;
+          $el[0].inputmask.isRTL = opts.numericInput;
+
           if (opts.numericInput) {
             isRTL = true;
           }
@@ -2467,11 +2461,13 @@
           return isRTL ? getBuffer().slice().reverse().join('') : getBuffer().join('');
         case "isValid":
           $el = $({});
-          $el.data('_inputmask', {
-            'maskset': maskset,
-            'opts': opts,
-            'isRTL': opts.numericInput
-          });
+          //store inputmask instance on the input with element reference
+          $el[0].inputmask = new inputmask();
+          $el[0].inputmask.opts = opts;
+          $el[0].inputmask.el = $el[0];
+          $el[0].inputmask.maskset = maskset;
+          $el[0].inputmask.isRTL = opts.numericInput;
+
           if (opts.numericInput) {
             isRTL = true;
           }
@@ -2487,21 +2483,22 @@
 
           return isComplete(buffer) && actionObj["value"] == buffer.join('');
         case "getemptymask":
-          $el = $(actionObj["el"]);
-          maskset = $el.data('_inputmask')['maskset'];
-          opts = $el.data('_inputmask')['opts'];
+          el = actionObj["el"]
+          $el = $(el);
+          maskset = el.inputmask.maskset;
+          opts = el.inputmask.opts;
           return getBufferTemplate();
         case "remove":
-          var el = actionObj["el"];
+          el = actionObj["el"]
           $el = $(el);
-          maskset = $el.data('_inputmask')['maskset'];
-          opts = $el.data('_inputmask')['opts'];
+          maskset = el.inputmask.maskset;
+          opts = el.inputmask.opts;
           //writeout the unmaskedvalue
           el._valueSet(unmaskedvalue($el));
           //unbind all events
           $el.unbind(".inputmask");
           //clear data
-          $el.removeData('_inputmask');
+          el.inputmask = undefined;
           //restore the value property
           var valueProperty;
           if (Object.getOwnPropertyDescriptor)
@@ -2529,9 +2526,10 @@
           }
           break;
         case "getmetadata":
-          $el = $(actionObj["el"]);
-          maskset = $el.data('_inputmask')['maskset'];
-          opts = $el.data('_inputmask')['opts'];
+          el = actionObj["el"]
+          $el = $(el);
+          maskset = el.inputmask.maskset;
+          opts = el.inputmask.opts;
           if ($.isArray(maskset["metadata"])) {
             //find last alternation
             var alternation, lvp = getLastValidPosition();

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

@@ -591,5 +591,5 @@ Optional extensions on the jquery.inputmask base
       radixPoint: ""
     }
   });
-  return $.fn.inputmask;
+  return inputmask;
 })(jQuery);

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

@@ -62,5 +62,5 @@ When using this extension make sure you specify the correct url to get the masks
       nojumpsThreshold: 4
     }
   });
-  return $.fn.inputmask;
+  return inputmask;
 })(jQuery);

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

@@ -199,5 +199,5 @@ Allows for using regular expressions as a mask
       }
     }
   });
-  return $.fn.inputmask;
+  return inputmask;
 })(jQuery);

+ 1 - 1
package.json

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

+ 99 - 87
qunit/simulator.js

@@ -1,94 +1,106 @@
-(function ($) {
-    $.caret = function (input, begin, end) {
-        var npt = input.jquery && input.length > 0 ? input[0] : input, range;
-        if (typeof begin == 'number') {
-            if (!$(input).is(':visible')) {
-                return;
-            }
-            end = (typeof end == 'number') ? end : begin;
-            if (npt.setSelectionRange) {
-                npt.selectionStart = begin;
-                npt.selectionEnd = end;
+(function($) {
+  $.caret = function(input, begin, end) {
+    var npt = input.jquery && input.length > 0 ? input[0] : input,
+      range;
+    if (typeof begin == 'number') {
+      if (!$(input).is(':visible')) {
+        return;
+      }
+      end = (typeof end == 'number') ? end : begin;
+      if (npt.setSelectionRange) {
+        npt.selectionStart = begin;
+        npt.selectionEnd = end;
 
-            } else if (npt.createTextRange) {
-                range = npt.createTextRange();
-                range.collapse(true);
-                range.moveEnd('character', end);
-                range.moveStart('character', begin);
-                range.select();
-            }
-        } else {
-            if (!$(input).is(':visible')) {
-                return { "begin": 0, "end": 0 };
-            }
-            if (npt.setSelectionRange) {
-                begin = npt.selectionStart;
-                end = npt.selectionEnd;
-            } else if (document.selection && document.selection.createRange) {
-                range = document.selection.createRange();
-                begin = 0 - range.duplicate().moveStart('character', -100000);
-                end = begin + range.text.length;
-            }
-            return { "begin": begin, "end": end };
+      } else if (npt.createTextRange) {
+        range = npt.createTextRange();
+        range.collapse(true);
+        range.moveEnd('character', end);
+        range.moveStart('character', begin);
+        range.select();
+      }
+    } else {
+      if (!$(input).is(':visible')) {
+        return {
+          "begin": 0,
+          "end": 0
+        };
+      }
+      if (npt.setSelectionRange) {
+        begin = npt.selectionStart;
+        end = npt.selectionEnd;
+      } else if (document.selection && document.selection.createRange) {
+        range = document.selection.createRange();
+        begin = 0 - range.duplicate().moveStart('character', -100000);
+        end = begin + range.text.length;
+      }
+      return {
+        "begin": begin,
+        "end": end
+      };
+    }
+  };
+  $.fn.SendKey = function(keyCode, modifier) {
+    var sendDummyKeydown = false;
+    if (Object.prototype.toString.call(keyCode) == '[object String]') {
+      keyCode = keyCode.charCodeAt(0);
+      sendDummyKeydown = true;
+    }
+
+    switch (keyCode) {
+      case $.inputmask.keyCode.LEFT:
+        {
+          if (modifier == undefined) {
+            var pos = $.caret(this);
+            $.caret(this, pos.begin - 1);
+            break;
+          }
         }
-    };
-    $.fn.SendKey = function (keyCode, modifier) {
-        var sendDummyKeydown = false;
-        if (Object.prototype.toString.call(keyCode) == '[object String]') {
-            keyCode = keyCode.charCodeAt(0);
-            sendDummyKeydown = true;
+      case $.inputmask.keyCode.RIGHT:
+        {
+          if (modifier == undefined) {
+            var pos = $.caret(this);
+            $.caret(this, pos.begin + 1);
+            break;
+          }
         }
+      default:
+        {
+          var keydown = $.Event("keydown"),
+            keypress = $.Event("keypress"),
+            keyup = $.Event("keyup");
 
-        switch (keyCode) {
-            case $.inputmask.keyCode.LEFT: {
-                if (modifier == undefined) {
-                    var pos = $.caret(this);
-                    $.caret(this, pos.begin - 1);
-                    break;
-                }
-            }
-            case $.inputmask.keyCode.RIGHT: {
-                if (modifier == undefined) {
-                    var pos = $.caret(this);
-                    $.caret(this, pos.begin + 1);
-                    break;
-                }
-            }
-            default: {
-                var keydown = $.Event("keydown"),
-                    keypress = $.Event("keypress"),
-                    keyup = $.Event("keyup");
-
-                if (!sendDummyKeydown) {
-                    keydown.keyCode = keyCode;
-                    if (modifier == $.inputmask.keyCode.CONTROL)
-                        keydown.ctrlKey = true;
-                }
-                $(this).trigger(keydown);
-                if (!keydown.isDefaultPrevented()) {
-                    keypress.keyCode = keyCode;
-                    if (modifier == $.inputmask.keyCode.CONTROL)
-                        keypress.ctrlKey = true;
-                    $(this).trigger(keypress);
-                    //if (!keypress.isDefaultPrevented()) {
-                    keyup.keyCode = keyCode;
-                    if (modifier == $.inputmask.keyCode.CONTROL)
-                        keyup.ctrlKey = true;
-                    $(this).trigger(keyup);
-                    //}
-                }
-            }
+          if (!sendDummyKeydown) {
+            keydown.keyCode = keyCode;
+            if (modifier == $.inputmask.keyCode.CONTROL)
+              keydown.ctrlKey = true;
+          }
+          $(this).trigger(keydown);
+          if (!keydown.isDefaultPrevented()) {
+            keypress.keyCode = keyCode;
+            if (modifier == $.inputmask.keyCode.CONTROL)
+              keypress.ctrlKey = true;
+            $(this).trigger(keypress);
+            //if (!keypress.isDefaultPrevented()) {
+            keyup.keyCode = keyCode;
+            if (modifier == $.inputmask.keyCode.CONTROL)
+              keyup.ctrlKey = true;
+            $(this).trigger(keyup);
+            //}
+          }
         }
     }
-    $.fn.Type = function (inputStr) {
-        var $input = $(this);
-        $.each(inputStr.split(''), function (ndx, lmnt) {
-            $input.SendKey(lmnt);
-        });
-    }
-    $.fn.paste = function (inputStr) {
-        var $input = $(this), isRTL = $input.data("_inputmask").isRTL;
-        window.clipboardData ? window.clipboardData.setData("Text", inputStr) : $input[0]._valueSet(isRTL ? inputStr.split('').reverse().join('') : inputStr);
-        $input.trigger('paste');
-    }
+  }
+  $.fn.Type = function(inputStr) {
+    var $input = $(this);
+    $.each(inputStr.split(''), function(ndx, lmnt) {
+      $input.SendKey(lmnt);
+    });
+  }
+  $.fn.paste = function(inputStr) {
+    var input = this.jquery && this.length > 0 ? this[0] : this,
+      $input = $(input),
+      isRTL = input.inputmask.isRTL;
+    window.clipboardData ? window.clipboardData.setData("Text", inputStr) : $input[0]._valueSet(isRTL ? inputStr.split('').reverse().join('') : inputStr);
+    $input.trigger('paste');
+  }
 })(jQuery);

+ 37 - 37
qunit/tests_formatvalidate.js

@@ -1,22 +1,22 @@
 module("Value formatting");
-test("$.inputmask.format(\"2331973\", { alias: \"date\"})", function () {
-    var formattedValue = $.inputmask.format("2331973", { alias: "date" });
+test("inputmask.format(\"2331973\", { alias: \"date\"})", function () {
+    var formattedValue = inputmask.format("2331973", { alias: "date" });
     equal(formattedValue, "23/03/1973", "Result " + formattedValue);
 });
 
-test("$.inputmask.format(\"016501030020001DE1015170\", { mask: \"99 999 999 999 9999 \\D\\E*** 9999\"})", function () {
-    var formattedValue = $.inputmask.format("016501030020001DE1015170", { mask: "99 999 999 999 9999 \\D\\E*** 9999" });
+test("inputmask.format(\"016501030020001DE1015170\", { mask: \"99 999 999 999 9999 \\D\\E*** 9999\"})", function () {
+    var formattedValue = inputmask.format("016501030020001DE1015170", { mask: "99 999 999 999 9999 \\D\\E*** 9999" });
     equal(formattedValue, "01 650 103 002 0001 DE101 5170", "Result " + formattedValue);
 });
 
-test("$.inputmask.format(\"12\", {  mask: \"$ 999999\", numericInput: true, placeholder: \"0\" }); - gigermocas", function () {
-    var formattedValue = $.inputmask.format("12", { mask: "$ 999999", numericInput: true, placeholder: "0" });
+test("inputmask.format(\"12\", {  mask: \"$ 999999\", numericInput: true, placeholder: \"0\" }); - gigermocas", function () {
+    var formattedValue = inputmask.format("12", { mask: "$ 999999", numericInput: true, placeholder: "0" });
     equal(formattedValue, "$ 000012", "Result " + formattedValue);
 });
 
 
-test("$.inputmask.format(\"1111111.11\" - ... autoGroup: true - swd120", function () {
-    var formattedValue = $.inputmask.format("1111111.11", {
+test("inputmask.format(\"1111111.11\" - ... autoGroup: true - swd120", function () {
+    var formattedValue = inputmask.format("1111111.11", {
         alias: "decimal",
         radixPoint: ".",
         digits: 2,
@@ -28,66 +28,66 @@ test("$.inputmask.format(\"1111111.11\" - ... autoGroup: true - swd120", functio
     equal(formattedValue, "1,111,111.11", "Result " + formattedValue);
 });
 
-test("$.inputmask.format(phone, { mask: '(999) 999-9999' })); - krivaten", function () {
+test("inputmask.format(phone, { mask: '(999) 999-9999' })); - krivaten", function () {
     var phone = '5551112222';
-    var formattedValue = $.inputmask.format(phone, { mask: '(999) 999-9999' });
+    var formattedValue = inputmask.format(phone, { mask: '(999) 999-9999' });
     equal(formattedValue, "(555) 111-2222", "Result " + formattedValue);
 });
 
 
 module("Value Validating");
-test("$.inputmask.isValid(\"23/03/1973\", { alias: \"date\"})", function () {
-    var isValid = $.inputmask.isValid("23/03/1973", { alias: "date" });
+test("inputmask.isValid(\"23/03/1973\", { alias: \"date\"})", function () {
+    var isValid = inputmask.isValid("23/03/1973", { alias: "date" });
     equal(isValid, true, "Result " + isValid);
 });
 
-test("$.inputmask.isValid(\"01 650 103 002 0001 DE101 5170\", { mask: \"99 999 999 999 9999 \\D\\E*** 9999\"})", function () {
-    var isValid = $.inputmask.isValid("01 650 103 002 0001 DE101 5170", { mask: "99 999 999 999 9999 \\D\\E*** 9999" });
+test("inputmask.isValid(\"01 650 103 002 0001 DE101 5170\", { mask: \"99 999 999 999 9999 \\D\\E*** 9999\"})", function () {
+    var isValid = inputmask.isValid("01 650 103 002 0001 DE101 5170", { mask: "99 999 999 999 9999 \\D\\E*** 9999" });
     equal(isValid, true, "Result " + isValid);
 });
 
-test("$.inputmask.isValid email => false", function () {
-    var isValid = $.inputmask.isValid("some.body@mail.c", { alias: "email" });
+test("inputmask.isValid email => false", function () {
+    var isValid = inputmask.isValid("some.body@mail.c", { alias: "email" });
     equal(isValid, true, "Result " + isValid);
 });
 
-test("$.inputmask.isValid email => true", function () {
-    var isValid = $.inputmask.isValid("some.body@mail.com", { alias: "email" });
+test("inputmask.isValid email => true", function () {
+    var isValid = inputmask.isValid("some.body@mail.com", { alias: "email" });
     equal(isValid, true, "Result " + isValid);
 });
 
-test("$.inputmask.isValid email greedy => false", function () {
-    var isValid = $.inputmask.isValid("some.body@mail.c", { alias: "email", greedy: true });
+test("inputmask.isValid email greedy => false", function () {
+    var isValid = inputmask.isValid("some.body@mail.c", { alias: "email", greedy: true });
     equal(isValid, true, "Result " + isValid);
 });
 
-test("$.inputmask.isValid email greedy => true", function () {
-    var isValid = $.inputmask.isValid("some.body@mail.com", { alias: "email", greedy: true });
+test("inputmask.isValid email greedy => true", function () {
+    var isValid = inputmask.isValid("some.body@mail.com", { alias: "email", greedy: true });
     equal(isValid, true, "Result " + isValid);
 });
 
 test("YoussefTaghlabi isValid(\"100\", { alias: \"integer\" }", function () {
-    var isValid = $.inputmask.isValid("100", { alias: "integer" });
+    var isValid = inputmask.isValid("100", { alias: "integer" });
     equal(isValid, true, "Result " + isValid);
 });
 test("YoussefTaghlabi isValid(\"100.00\", { alias: \"integer\" }", function () {
-    var isValid = $.inputmask.isValid("100.00", { alias: "integer" });
+    var isValid = inputmask.isValid("100.00", { alias: "integer" });
     equal(isValid, false, "Result " + isValid);
 });
 test("YoussefTaghlabi isValid(\"123\", { alias: \"decimal\" }", function () {
-    var isValid = $.inputmask.isValid("123", { alias: "decimal" });
+    var isValid = inputmask.isValid("123", { alias: "decimal" });
     equal(isValid, true, "Result " + isValid);
 });
 test("YoussefTaghlabi isValid(\"123.45\", { alias: \"decimal\" }", function () {
-    var isValid = $.inputmask.isValid("123.45", { alias: "decimal" });
+    var isValid = inputmask.isValid("123.45", { alias: "decimal" });
     equal(isValid, true, "Result " + isValid);
 });
 test("YoussefTaghlabi isValid(\"123456.78\", { alias: \"decimal\" }", function () {
-    var isValid = $.inputmask.isValid("123456.78", { alias: "decimal" });
+    var isValid = inputmask.isValid("123456.78", { alias: "decimal" });
     equal(isValid, true, "Result " + isValid);
 });
 test("YoussefTaghlabi isValid(\"123,456.78\", { alias: \"decimal\" }", function () {
-    var isValid = $.inputmask.isValid("123,456.78", {
+    var isValid = inputmask.isValid("123,456.78", {
         alias: "decimal", radixPoint: ".",
         groupSeparator: ",",
         groupSize: 3
@@ -95,7 +95,7 @@ test("YoussefTaghlabi isValid(\"123,456.78\", { alias: \"decimal\" }", function
     equal(isValid, true, "Result " + isValid);
 });
 test("YoussefTaghlabi isValid(\"12,\", { alias: \"decimal\" }", function () {
-    var isValid = $.inputmask.isValid("12,", {
+    var isValid = inputmask.isValid("12,", {
         alias: "decimal", radixPoint: ".",
         groupSeparator: ",",
         groupSize: 3
@@ -103,7 +103,7 @@ test("YoussefTaghlabi isValid(\"12,\", { alias: \"decimal\" }", function () {
     equal(isValid, false, "Result " + isValid);
 });
 test("YoussefTaghlabi isValid(\"12,1.45\", { alias: \"decimal\" }", function () {
-    var isValid = $.inputmask.isValid("12,1.45", {
+    var isValid = inputmask.isValid("12,1.45", {
         alias: "decimal", radixPoint: ".",
         groupSeparator: ",",
         groupSize: 3
@@ -111,7 +111,7 @@ test("YoussefTaghlabi isValid(\"12,1.45\", { alias: \"decimal\" }", function ()
     equal(isValid, false, "Result " + isValid);
 });
 test("YoussefTaghlabi isValid(\"12,345.67\", { alias: \"decimal\" }", function () {
-    var isValid = $.inputmask.isValid("12,345.67", {
+    var isValid = inputmask.isValid("12,345.67", {
         alias: "decimal", radixPoint: ".",
         groupSeparator: ",",
         groupSize: 3
@@ -120,26 +120,26 @@ test("YoussefTaghlabi isValid(\"12,345.67\", { alias: \"decimal\" }", function (
 });
 
 test("thomstark isValid(\"12lbs\", {mask:\"99[9]lb\\s\", greedy:false, skipOptionalPartCharacter: \"\", \"clearIncomplete\":true}", function () {
-    var isValid = $.inputmask.isValid("12lbs", { mask: "99[9]lb\\s", greedy: false, skipOptionalPartCharacter: "", "clearIncomplete": true });
+    var isValid = inputmask.isValid("12lbs", { mask: "99[9]lb\\s", greedy: false, skipOptionalPartCharacter: "", "clearIncomplete": true });
     equal(isValid, true, "Result " + isValid);
 });
 
 test("thomstark isValid(\"1'2\"\", {mask:\"9'9[9]\"\", greedy:false, skipOptionalPartCharacter: \"\", \"clearIncomplete\":true}", function () {
-    var isValid = $.inputmask.isValid("1'2\"", { mask: "9'9[9]\"", greedy: false, skipOptionalPartCharacter: "", "clearIncomplete": true });
+    var isValid = inputmask.isValid("1'2\"", { mask: "9'9[9]\"", greedy: false, skipOptionalPartCharacter: "", "clearIncomplete": true });
     equal(isValid, true, "Result " + isValid);
 });
 
 test("thomstark isValid(\"12lbs\", {mask:\"99{1,2}lb\\s\", greedy:false, skipOptionalPartCharacter: \"\", \"clearIncomplete\":true}", function () {
-    var isValid = $.inputmask.isValid("12lbs", { mask: "99{1,2}lb\\s", greedy: false, skipOptionalPartCharacter: "", "clearIncomplete": true });
+    var isValid = inputmask.isValid("12lbs", { mask: "99{1,2}lb\\s", greedy: false, skipOptionalPartCharacter: "", "clearIncomplete": true });
     equal(isValid, true, "Result " + isValid);
 });
 
 test("thomstark isValid(\"9'9{1,2}\", {mask:\"9'9[9]\"\", greedy:false, skipOptionalPartCharacter: \"\", \"clearIncomplete\":true}", function () {
-    var isValid = $.inputmask.isValid("1'2\"", { mask: "9'9{1,2}\"", greedy: false, skipOptionalPartCharacter: "", "clearIncomplete": true });
+    var isValid = inputmask.isValid("1'2\"", { mask: "9'9{1,2}\"", greedy: false, skipOptionalPartCharacter: "", "clearIncomplete": true });
     equal(isValid, true, "Result " + isValid);
 });
 
 test("a13x3y isValid(\"some_body@mail.com\", {alias:\"email\"}", function () {
-    var isValid = $.inputmask.isValid("some_body@mail.com", { alias: "email" });
+    var isValid = inputmask.isValid("some_body@mail.com", { alias: "email" });
     equal(isValid, true, "Result " + isValid);
-});
+});