ソースを参照

merge branch '2.x' into 2.6

Robin Herbots 11 年 前
コミット
f179ee3695
8 ファイル変更2011 行追加19 行削除
  1. 24 0
      README.md
  2. 1 1
      bower.json
  3. 1 1
      build.properties
  4. 1 1
      jquery.inputmask.jquery.json
  5. 18 16
      js/jquery.inputmask.js
  6. 3 0
      js/jquery.inputmask.regex.extensions.js
  7. 14 0
      qunit/tests.js
  8. 1949 0
      qunit/tests.js~

+ 24 - 0
README.md

@@ -560,6 +560,30 @@ Show the current mask definition as a tooltip.
   $(selector).inputmask({ mask: ["999-999-9999 [x99999]", "+099 99 99 9999[9]-9999"], showTooltip: true });
 ```
 
+## Function overrides
+### isComplete
+With this call-in you can override the default implementation of the isComplete function.  
+
+```javascript
+$("selector).inputmask("Regex", { 
+	regex: "[0-9]*", 
+	isComplete: function(buffer, opts) {
+		return new RegExp(opts.regex).test(buffer.join(''));
+	}
+});
+```
+
+### getMaskLength
+With this call-in you can override the default implementation of the getMaskLength function.  
+```javascript
+$("selector).inputmask({ 
+	alias: "decimal", 
+	getMaskLength: function(buffer, greedy, repeat, currentBuffer, opts) {
+		var calculatedLength = 10; //do some calculation		
+		return calculatedLength;
+	}
+});
+```
 
 ## Supported markup options
 ### RTL attribute

+ 1 - 1
bower.json

@@ -12,4 +12,4 @@
 		{ "name": "Robin Herbots" }
 	],
 	"homepage": "http://robinherbots.github.io/jquery.inputmask"
-}
+}

+ 1 - 1
build.properties

@@ -7,7 +7,7 @@ distdir = dist
 
 build.major = 2
 build.minor = 5
-build.revision = 4
+build.revision = 6
 
 target = jquery.inputmask.bundle.js
 target.min = jquery.inputmask.bundle.min.js

+ 1 - 1
jquery.inputmask.jquery.json

@@ -8,7 +8,7 @@
 		"inputmask",
 		"mask"
     ],
-    "version": "2.5.4",
+    "version": "2.5.6",
     "author": {
         "name": "Robin Herbots",
         "url": "http://github.com/RobinHerbots/jquery.inputmask"

+ 18 - 16
js/jquery.inputmask.js

@@ -680,19 +680,19 @@
             }
 
             function getMaskLength() {
-                if (opts.getMaskLength)
-                    return opts.getMaskLength(getActiveBufferTemplate(), getActiveMaskSet()['greedy'], getActiveMaskSet()['repeat'], getActiveBuffer(), opts);
-
-                var buffer = getActiveBufferTemplate(), greedy = getActiveMaskSet()['greedy'], repeat = getActiveMaskSet()['repeat'], currentBuffer = getActiveBuffer();
-                var calculatedLength = buffer.length;
-                if (!greedy) {
-                    if (repeat == "*" || repeat == "+") {
-                        calculatedLength = currentBuffer.length + 1;
-                    } else if (repeat > 1) {
-                        calculatedLength += (buffer.length * (repeat - 1));
+				var buffer=getActiveBufferTemplate(), greedy=getActiveMaskSet()['greedy'], repeat=getActiveMaskSet()['repeat'], currentBuffer=getActiveBuffer();
+
+		if($.isFunction(opts.getMaskLength)) return opts.getMaskLength(buffer, greedy, repeat, currentBuffer, opts);
+
+		    var calculatedLength = buffer.length;
+                    if (!greedy) {
+                        if (repeat == "*") {
+                            calculatedLength = currentBuffer.length + 1;
+                        } else if (repeat > 1) {
+                            calculatedLength += (buffer.length * (repeat - 1));
+                        }
                     }
-                }
-                return calculatedLength;
+                    return calculatedLength;
             }
 
             //pos: from position
@@ -836,7 +836,7 @@
                         return isMask(index) && isValid(index, element, true) ? element : null;
                     });
                     var unmaskedValue = (isRTL ? umValue.reverse() : umValue).join('');
-                    return opts.onUnMask != undefined ? opts.onUnMask.call($input, getActiveBuffer().join(''), unmaskedValue, opts) : unmaskedValue;
+                    return $.isFunction(opts.onUnMask) ? opts.onUnMask.call($input, getActiveBuffer().join(''), unmaskedValue, opts) : unmaskedValue;
                 } else {
                     return $input[0]._valueGet();
                 }
@@ -890,6 +890,7 @@
                 }
             }
             function isComplete(buffer) { //return true / false / undefined (repeat *)
+		if($.isFunction(opts.isComplete)) return opts.isComplete.call($el, buffer, opts);
                 if (opts.repeat == "*") return undefined;
                 var complete = false, highestValidPosition = 0, currentActiveMasksetIndex = activeMasksetIndex;
                 $.each(masksets, function (ndx, ms) {
@@ -1396,7 +1397,7 @@
                     return true;
                 }
                 setTimeout(function () {
-                    var pasteValue = opts.onBeforePaste != undefined ? opts.onBeforePaste.call(input, input._valueGet(), opts) : input._valueGet();
+                    var pasteValue = $.isFunction(opts.onBeforePaste) ? opts.onBeforePaste.call(input, input._valueGet(), opts) : input._valueGet();
                     checkVal(input, false, false, pasteValue.split(''), true);
                     writeBuffer(input, getActiveBuffer());
                     if (isComplete(getActiveBuffer()) === true)
@@ -1627,7 +1628,7 @@
                         $el.bind("input.inputmask", pasteEvent);
 
                     //apply mask
-                    var initialValue = opts.onBeforeMask != undefined ? opts.onBeforeMask.call(el, el._valueGet(), opts) : el._valueGet();
+                    var initialValue = $.isFunction(opts.onBeforeMask) ? opts.onBeforeMask.call(el, el._valueGet(), opts) : el._valueGet();
                     checkVal(el, true, false, initialValue.split(''));
                     valueOnFocus = getActiveBuffer().join('');
                     // Wrap document.activeElement in a try/catch block since IE9 throw "Unspecified error" if document.activeElement is undefined when we are in an IFrame.
@@ -1756,7 +1757,8 @@
                 },
                 //specify keycodes which should not be considered in the keypress event, otherwise the preventDefault will stop their default behavior especially in FF
                 ignorables: [8, 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],
-                getMaskLength: undefined
+                getMaskLength: undefined, //override for getMaskLength - args => buffer, greedy, repeat, currentBuffer, opts - return length
+		isComplete: undefined //override for isComplete - args => buffer, opts - return true || false
             },
             escapeRegex: function (str) {
                 var specials = ['/', '.', '*', '+', '?', '|', '(', ')', '[', ']', '{', '}', '\\'];

+ 3 - 0
js/jquery.inputmask.regex.extensions.js

@@ -19,6 +19,9 @@ Allows for using regular expressions as a mask
             //Thx to https://github.com/slevithan/regex-colorizer for the tokenizer regex
             tokenizer: /\[\^?]?(?:[^\\\]]+|\\[\S\s]?)*]?|\\(?:0(?:[0-3][0-7]{0,2}|[4-7][0-7]?)?|[1-9][0-9]*|x[0-9A-Fa-f]{2}|u[0-9A-Fa-f]{4}|c[A-Za-z]|[\S\s]?)|\((?:\?[:=!]?)?|(?:[?*+]|\{[0-9]+(?:,[0-9]*)?\})\??|[^.?*+^${[()|\\]+|./g,
             quantifierFilter: /[0-9]+[^,]/,
+            isComplete: function(buffer, opts){
+            	return new RegExp(opts.regex).test(buffer.join(''));
+            },
             definitions: {
                 'r': {
                     validator: function (chrs, buffer, pos, strict, opts) {

+ 14 - 0
qunit/tests.js

@@ -1567,6 +1567,20 @@ test("inputmask(\"Regex\", { regex: \"[0-9]*\"});", function () {
 
     $("#testmask").remove();
 });
+
+asyncTest("inputmask(\"Regex\", { regex: \"[0-9]*\"}); ~ isComplete", function () {
+    $('body').append('<input type="text" id="testmask" />');
+    $("#testmask").inputmask("Regex", { regex: "[0-9]*",  oncomplete: function () {
+            equal($("#testmask").val(), "1", "Result " + $("#testmask").val());
+            start();
+            $("#testmask").remove();
+         }
+	});
+
+    $("#testmask")[0].focus();
+    $("#testmask").SendKey("1");
+});
+
 test("inputmask(\"Regex\", { regex: \"[A-Za-z\u0410-\u044F\u0401\u04510-9]*\"});", function () {
     $('body').append('<input type="text" id="testmask" />');
     $("#testmask").inputmask("Regex", { regex: "[A-Za-z\u0410-\u044F\u0401\u04510-9]*" });

ファイルの差分が大きいため隠しています
+ 1949 - 0
qunit/tests.js~