Browse Source

Merge branch 'dev'

Robin Herbots 13 years ago
parent
commit
2eb6afc8a8
2 changed files with 50 additions and 29 deletions
  1. 29 13
      jquery.inputmask.extentions.js
  2. 21 16
      jquery.inputmask.js

+ 29 - 13
jquery.inputmask.extentions.js

@@ -3,7 +3,7 @@ Input Mask plugin extentions
 http://github.com/RobinHerbots/jquery.inputmask
 Copyright (c) 2010 Robin Herbots
 Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-Version: 0.0.3c
+Version: 0.0.5
 
 Optional extentions on the jquery.inputmask base
 */
@@ -39,7 +39,7 @@ Optional extentions on the jquery.inputmask base
             prevalidator: [{ validator: "[01]", cardinality: 1}]
         },
         'y': { //basic year
-            validator: "(19|20)\\d\\d",
+            validator: "(19|20)\\d{2}",
             cardinality: 4,
             prevalidator: [
                         { validator: "[12]", cardinality: 1 },
@@ -55,7 +55,7 @@ Optional extentions on the jquery.inputmask base
             regex: {
                 monthpre: new RegExp("[01]"),
                 month: new RegExp("((0[1-9]|[12][0-9])\/(0[1-9]|1[012]))|(30\/(0[13-9]|1[012]))|(31\/(0[13578]|1[02]))"),
-                year: new RegExp("(19|20)\\d\\d"),
+                year: new RegExp("(19|20)\\d{2}"),
                 daypre: new RegExp("[0-3]"),
                 day: new RegExp("0[1-9]|[12][0-9]|3[01]")
             },
@@ -159,7 +159,7 @@ Optional extentions on the jquery.inputmask base
                         daypre: new RegExp("((0[13-9]|1[012])\/[0-3])|(02\/[0-2])"),
                         month: new RegExp("0[1-9]|1[012]"),
                         monthpre: new RegExp("[01]"),
-                        year: new RegExp("(19|20)\\d\\d")
+                        year: new RegExp("(19|20)\\d{2}")
                     },
                     definitions: {
                         'd': { //day
@@ -271,7 +271,7 @@ Optional extentions on the jquery.inputmask base
                             alias: "date"
                         }
                     });
-                    //number aliases by Dean (datimson)
+                    //number aliases 
                     $.extend($.inputmask.defaults, {
                         radixPoint: "\.", // | ","
                         digits: "*", //numer of digits
@@ -284,9 +284,9 @@ Optional extentions on the jquery.inputmask base
                             placeholder: "",
                             repeat: 10,
                             greedy: false,
-                            numericInput: true, //true => not working fixme
+                            numericInput: true,
                             regex: {
-                                number: function(radixPoint, digits) { return new RegExp("^([\+\-]?[0-9]*[" + radixPoint + "]?[0-9]" + digits + ")$"); }
+                                number: function(radixPoint, digits) { return new RegExp("^[\+\-\\d]{1}\\d*[" + radixPoint + "]?\\d" + digits + "$"); }
                             },
                             definitions: {
                                 '~': { //real number
@@ -294,13 +294,29 @@ Optional extentions on the jquery.inputmask base
                                         function digitExpression() {
                                             return isNaN(opts.digits) ? opts.digits : '{0,' + opts.digits + '}';
                                         }
-                                        var cbuf = buffer.slice(0, pos + 1);
-                                        cbuf[pos + 1] = chrs;
+                                        var cbuf = buffer.slice();
+                                        cbuf.splice(pos, 0, chrs);
                                         var bufferStr = cbuf.join('');
                                         var isValid = opts.regex.number(opts.radixPoint, digitExpression()).test(bufferStr);
-                                        if (!strict && !isValid) {
-                                            //todo grouping, radixpoint handling
+                                        if (!isValid) {
+                                            if (strict) { //shiftL & shiftR use strict only validate from 0 to position
+                                                var cbuf = buffer.slice(0, pos);
+                                                cbuf.splice(pos, 0, chrs);
+                                                var bufferStr = cbuf.join('');
+                                                var isValid = opts.regex.number(opts.radixPoint, digitExpression()).test(bufferStr);
+                                            }
+                                            else {
+                                                if (bufferStr == opts.radixPoint) {
+                                                    isValid = opts.regex.number(opts.radixPoint, digitExpression()).test("0" + bufferStr);
+                                                    if (isValid) {
+                                                        buffer[pos] = "0";
+                                                        pos++;
+                                                        return pos;
+                                                    }
+                                                }
+                                            }
                                         }
+                                        //todo grouping, radixpoint positioning
                                         return isValid;
                                     },
                                     cardinality: 1,
@@ -311,13 +327,13 @@ Optional extentions on the jquery.inputmask base
                         },
                         'non-negative-decimal': {
                             regex: {
-                                number: function(radixPoint, digits) { return new RegExp("^([0-9]+[" + radixPoint + "]?[0-9]" + digits + ")$"); }
+                                number: function(radixPoint, digits) { return new RegExp("^\\d+[" + radixPoint + "]?\\d" + digits + "$"); }
                             },
                             alias: "decimal"
                         },
                         'integer': {
                             regex: {
-                                number: function() { return new RegExp("^([\+\-]?[0-9]*)$"); }
+                                number: function() { return new RegExp("^([\+\-]?\\d*)$"); }
                             },
                             alias: "decimal"
                         }

+ 21 - 16
jquery.inputmask.js

@@ -3,7 +3,7 @@ Input Mask plugin for jquery
 http://github.com/RobinHerbots/jquery.inputmask
 Copyright (c) 2010 Robin Herbots
 Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-Version: 0.5.7b
+Version: 0.5.8
  
 This plugin is based on the masked input plugin written by Josh Bush (digitalbush.com)
 */
@@ -149,7 +149,7 @@ This plugin is based on the masked input plugin written by Josh Bush (digitalbus
             }
 
             //helper functions
-           function ResolveAlias(aliasStr) {
+            function ResolveAlias(aliasStr) {
                 var aliasDefinition = opts.aliases[aliasStr];
                 if (aliasDefinition) {
                     if (aliasDefinition.alias) ResolveAlias(aliasDefinition.alias); //alias is another alias
@@ -305,16 +305,20 @@ This plugin is based on the masked input plugin written by Josh Bush (digitalbus
 
             //needed to handle the non-greedy mask repetitions
             function prepareBuffer(buffer, position, isRTL) {
-                while ((buffer.length < position || position < 0) && buffer.length < getMaskLength()) {
-                    var j = 0;
-                    if (isRTL) {
+                var j = 0;
+                if (isRTL) {
+                    while (position < 0 && buffer.length < getMaskLength()) {
                         j = _buffer.length - 1;
-                        position = position + _buffer.length;
-                        while (_buffer[j] !== undefined)
+                        position = _buffer.length;
+                        while (_buffer[j] !== undefined) {
                             buffer.unshift(_buffer[j--]);
-                        break;
-                    } else while (_buffer[j] !== undefined) {
-                        buffer.push(_buffer[j++]);
+                        }
+                    }
+                } else {
+                    while (buffer.length < position && buffer.length < getMaskLength()) {
+                        while (_buffer[j] !== undefined) {
+                            buffer.push(_buffer[j++]);
+                        }
                     }
                 }
 
@@ -681,7 +685,7 @@ This plugin is based on the masked input plugin written by Josh Bush (digitalbus
                 //shift chars to left from start to end and put c at end position if defined
                 function shiftL(start, end, c) {
                     while (!isMask(start) && start - 1 >= 0) start--;
-                    for (var i = start; i <= end && i < getMaskLength(); i++) {
+                    for (var i = start; i < end && i < getMaskLength(); i++) {
                         if (isMask(i)) {
                             SetReTargetPlaceHolder(buffer, i);
                             var j = seekNext(buffer, i);
@@ -689,6 +693,7 @@ This plugin is based on the masked input plugin written by Josh Bush (digitalbus
                             if (p != getPlaceHolder(j)) {
                                 if (j < getMaskLength() && isValid(i, p, buffer, true) !== false && tests[determineTestPosition(i)].def == tests[determineTestPosition(j)].def) {
                                     setBufferElement(buffer, i, getBufferElement(buffer, j));
+                                    SetReTargetPlaceHolder(buffer, j); //cleanup next position
                                 } else {
                                     if (isMask(i))
                                         break;
@@ -820,17 +825,17 @@ This plugin is based on the masked input plugin written by Josh Bush (digitalbus
                         if (k) {
                             var pos = caret(input), c = String.fromCharCode(k), maskL = getMaskLength();
                             if (isRTL) {
-                                var p = seekPrevious(buffer, pos.end), np;
+                                var p = opts.numericInput ? pos.end : seekPrevious(buffer, pos.end), np;
                                 if ((np = isValid(p, c, buffer, false)) !== false) {
                                     if (np !== true) p = np; //set new position from isValid
                                     if (isValid(firstMaskPos, buffer[firstMaskPos], buffer, true) == false || (opts.greedy === false && buffer.length < maskL)) {
                                         if (buffer[firstMaskPos] != getPlaceHolder(firstMaskPos) && buffer.length < maskL) {
-                                            var offset = prepareBuffer(buffer, -1, isRTL) + 1;
-                                            p = p + offset;
+                                            var offset = prepareBuffer(buffer, -1, isRTL);
+                                            if (pos.end != 0) p = p + offset;
                                             maskL = buffer.length;
                                         }
-                                        shiftL(firstMaskPos, p, c);
-                                        writeBuffer(input, buffer, opts.numericInput ? maskL : p);
+                                        shiftL(firstMaskPos, opts.numericInput ? seekPrevious(buffer, p) : p, c);
+                                        writeBuffer(input, buffer, opts.numericInput && p == 0 ? seekNext(buffer, p) : p);
                                     } else if (opts.oncomplete)
                                         opts.oncomplete.call(input);
                                 } else if (android) writeBuffer(input, buffer, pos.begin);