浏览代码

Merge branch 'dev'

Robin Herbots 13 年之前
父节点
当前提交
38074533ff
共有 3 个文件被更改,包括 36 次插入5 次删除
  1. 15 0
      README.md
  2. 18 3
      js/jquery.inputmask.js
  3. 3 2
      js/jquery.inputmask.numeric.extensions.js

+ 15 - 0
README.md

@@ -289,6 +289,21 @@ This can be usefull when implementing an alias, ex. decimal alias, autofill the
 
 see jquery.inputmask.extensions.js for some examples
 
+### hasMaskedValue
+
+Check wheter the returned value is masked or not; currently only works reliable when using jquery.val fn to retrieve the value 
+
+```javascript
+$(document).ready(function(){
+	function validateMaskedValue(val){}
+	function validateValue(val){}
+
+	var val = $("#test").val();
+    if($("#test").inputmask("hasMaskedValue"))
+	  validateMaskedValue(val); 
+   else validateValue(val); 
+});
+```
 
 ## Supported markup options
 ### RTL attribute

+ 18 - 3
js/jquery.inputmask.js

@@ -3,7 +3,7 @@
 * http://github.com/RobinHerbots/jquery.inputmask
 * Copyright (c) 2010 - 2012 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 1.0.21
+* Version: 1.0.22a
 */
 
 (function ($) {
@@ -63,6 +63,7 @@
 
         $.fn.inputmask = function (fn, options) {
             var opts = $.extend(true, {}, $.inputmask.defaults, options);
+            var pasteEvent = isInputEventSupported('paste') ? 'paste' : 'input';
 
             var iphone = navigator.userAgent.match(/iphone/i) != null;
             var android = navigator.userAgent.match(/android.*mobile safari.*/i) != null;
@@ -137,6 +138,8 @@
                         if (this.data('inputmask'))
                             return this.data('inputmask')['_buffer'].join('');
                         else return "";
+                    case "hasMaskedValue": //check wheter the returned value is masked or not; currently only works reliable when using jquery.val fn to retrieve the value 
+                        return this.data('inputmask') ? !this.data('inputmask')['autoUnmask'] : false;
                     default:
                         //check if the fn is an alias
                         if (!resolveAlias(fn)) {
@@ -167,6 +170,18 @@
             }
 
             //helper functions
+            function isInputEventSupported(eventName) {
+                var el = document.createElement('input'), 
+		  eventName = 'on' + eventName,
+		  isSupported = (eventName in el);
+                if (!isSupported) {
+                  el.setAttribute(eventName, 'return;');
+                  isSupported = typeof el[eventName] == 'function';
+                }
+                el = null;
+                return isSupported;
+            }
+
             function resolveAlias(aliasStr) {
                 var aliasDefinition = opts.aliases[aliasStr];
                 if (aliasDefinition) {
@@ -636,7 +651,7 @@
                 }).bind("keydown.inputmask", keydownEvent
                 ).bind("keypress.inputmask", keypressEvent
                 ).bind("keyup.inputmask", keyupEvent
-                ).bind("paste.inputmask", function () {
+                ).bind(pasteEvent + ".inputmask", function () {
                     var input = this;
                     setTimeout(function () {
                         caret(input, checkVal(input, buffer, true));
@@ -1002,4 +1017,4 @@
             }
         };
     }
-})(jQuery);
+})(jQuery);

+ 3 - 2
js/jquery.inputmask.numeric.extensions.js

@@ -3,7 +3,7 @@ Input Mask plugin extensions
 http://github.com/RobinHerbots/jquery.inputmask
 Copyright (c) 2010 - 2012 Robin Herbots
 Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-Version: 1.0.19a
+Version: 1.0.22
 
 Optional extensions on the jquery.inputmask base
 */
@@ -93,7 +93,8 @@ Optional extensions on the jquery.inputmask base
                     prevalidator: null
                 }
             },
-            insertMode: true
+            insertMode: true,
+            autoUnmask: false
         },
         'non-negative-decimal': {
             regex: {