Browse Source

Merge branch '1.x' into 2.x

Robin Herbots 13 years ago
parent
commit
154f394b38
2 changed files with 31 additions and 3 deletions
  1. 15 0
      README.md
  2. 16 3
      js/jquery.inputmask.js

+ 15 - 0
README.md

@@ -17,6 +17,7 @@ Highlights:
 - non-greedy masks
 - many features can be enabled/disabled/configured by options
 - supports readonly/disabled/dir="rtl" attributes
+- support data-inputmask attribute
 
 
 ## Usage:
@@ -342,6 +343,20 @@ $(document).ready(function(){
 ```html
 <input id="test" maxlength="4" />
 ```
+### data-inputmask attribute
+
+You also apply an inputmask by using the data-inputmask attribute.  In the attribute you specify the options wanted for the inputmask.
+This gets parsed with $.parseJSON (for the moment), so be sure to use a welformed json-string without the {}.
+
+```html
+<input data-inputmask="'alias': 'date'" />
+<input data-inputmask="'mask': '9', 'repeat': '10', 'greedy' : 'false'" />
+```
+```javascript
+$(document).ready(function(){
+    $(":input").inputmask();
+});
+```
 
 ## Compiling with Google Closure Compiler
 

+ 16 - 3
js/jquery.inputmask.js

@@ -3,7 +3,7 @@
 * http://github.com/RobinHerbots/jquery.inputmask
 * Copyright (c) 2010 - 2013 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 2.1.0c
+* Version: 2.1.1
 */
 
 (function ($) {
@@ -55,7 +55,7 @@
                     ALT: 18, BACKSPACE: 8, CAPS_LOCK: 20, COMMA: 188, COMMAND: 91, COMMAND_LEFT: 91, COMMAND_RIGHT: 93, CONTROL: 17, DELETE: 46, DOWN: 40, END: 35, ENTER: 13, ESCAPE: 27, HOME: 36, INSERT: 45, LEFT: 37, MENU: 93, NUMPAD_ADD: 107, NUMPAD_DECIMAL: 110, NUMPAD_DIVIDE: 111, NUMPAD_ENTER: 108,
                     NUMPAD_MULTIPLY: 106, NUMPAD_SUBTRACT: 109, PAGE_DOWN: 34, PAGE_UP: 33, PERIOD: 190, RIGHT: 39, SHIFT: 16, SPACE: 32, TAB: 9, UP: 38, WINDOWS: 91
                 },
-				//specify keycodes which should not be considered in the keypress event, otherwise the preventDefault will stop their default behavior especially in FF
+                //specify keycodes which should not be considered in the keypress event, otherwise the preventDefault will stop their default behavior especially in FF
                 ignorables: [9, 13, 19, 27, 33, 34, 35, 36, 37, 38, 39, 40, 45, 46, 93, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123]
             },
             val: $.fn.val, //store the original jquery val function
@@ -175,7 +175,7 @@
 
                         break;
                 }
-            } if (typeof fn == "object") {
+            } else if (typeof fn == "object") {
                 opts = $.extend(true, {}, $.inputmask.defaults, fn);
                 resolveAlias(opts.alias); //resolve aliases
                 masksets = generateMaskSets();
@@ -183,6 +183,19 @@
                 return this.each(function () {
                     mask(this);
                 });
+            } else if (fn == undefined) {
+                //look for data-inputmask atribute - the attribute should only contain optipns
+                return this.each(function () {
+                    var attrOptions = $(this).attr("data-inputmask");
+                    if (attrOptions && attrOptions != "") {
+                        try {
+                            attrOptions = attrOptions.replace(new RegExp("'", "g"), '"');
+                            var options = $.parseJSON("{" + attrOptions + "}");
+                            opts = $.extend(true, {}, $.inputmask.defaults, options);
+                            $(this).inputmask(opts);
+                        } catch (ex) { } //need a more relax parseJSON
+                    }
+                });
             }
 
             //helper functions