Browse Source

Merge branch 'dev'

Robin Herbots 13 years ago
parent
commit
5a2f0a1d28
1 changed files with 20 additions and 14 deletions
  1. 20 14
      jquery.inputmask.js

+ 20 - 14
jquery.inputmask.js

@@ -3,7 +3,7 @@ Input Mask plugin for jquery
 http://github.com/RobinHerbots/jquery.inputmask
 http://github.com/RobinHerbots/jquery.inputmask
 Copyright (c) 2010 Robin Herbots
 Copyright (c) 2010 Robin Herbots
 Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
 Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-Version: 0.5.4
+Version: 0.5.5
  
  
 This plugin is based on the masked input plugin written by Josh Bush (digitalbush.com)
 This plugin is based on the masked input plugin written by Josh Bush (digitalbush.com)
 */
 */
@@ -190,7 +190,7 @@ This plugin is based on the masked input plugin written by Josh Bush (digitalbus
                 return repeatedMask;
                 return repeatedMask;
             }
             }
 
 
-            //test definition => {fn: RegExp/function, cardinality: int, optionality: bool, newBlockMarker: bool, offset: int}
+            //test definition => {fn: RegExp/function, cardinality: int, optionality: bool, newBlockMarker: bool, offset: int, casing: null/upper/lower, def: definitionSymbol}
             function getTestingChain() {
             function getTestingChain() {
                 var isOptional = false, escaped = false;
                 var isOptional = false, escaped = false;
                 var newBlockMarker = false; //indicates wheter the begin/ending of a block should be indicated
                 var newBlockMarker = false; //indicates wheter the begin/ending of a block should be indicated
@@ -214,13 +214,13 @@ This plugin is based on the masked input plugin written by Josh Bush (digitalbus
                             var prevalidators = maskdef["prevalidator"], prevalidatorsL = prevalidators ? prevalidators.length : 0;
                             var prevalidators = maskdef["prevalidator"], prevalidatorsL = prevalidators ? prevalidators.length : 0;
                             for (i = 1; i < maskdef.cardinality; i++) {
                             for (i = 1; i < maskdef.cardinality; i++) {
                                 var prevalidator = prevalidatorsL >= i ? prevalidators[i - 1] : [], validator = prevalidator["validator"], cardinality = prevalidator["cardinality"];
                                 var prevalidator = prevalidatorsL >= i ? prevalidators[i - 1] : [], validator = prevalidator["validator"], cardinality = prevalidator["cardinality"];
-                                outElem.push({ fn: validator ? typeof validator == 'string' ? new RegExp(validator) : new function() { this.test = validator; } : new RegExp("."), cardinality: cardinality ? cardinality : 1, optionality: isOptional, newBlockMarker: isOptional == true ? newBlockMarker : false, offset: 0, casing: maskdef["casing"] });
+                                outElem.push({ fn: validator ? typeof validator == 'string' ? new RegExp(validator) : new function() { this.test = validator; } : new RegExp("."), cardinality: cardinality ? cardinality : 1, optionality: isOptional, newBlockMarker: isOptional == true ? newBlockMarker : false, offset: 0, casing: maskdef["casing"], def: element });
                                 if (isOptional == true) //reset newBlockMarker
                                 if (isOptional == true) //reset newBlockMarker
                                     newBlockMarker = false;
                                     newBlockMarker = false;
                             }
                             }
-                            outElem.push({ fn: maskdef.validator ? typeof maskdef.validator == 'string' ? new RegExp(maskdef.validator) : new function() { this.test = maskdef.validator; } : new RegExp("."), cardinality: maskdef.cardinality, optionality: isOptional, newBlockMarker: newBlockMarker, offset: 0, casing: maskdef["casing"] });
+                            outElem.push({ fn: maskdef.validator ? typeof maskdef.validator == 'string' ? new RegExp(maskdef.validator) : new function() { this.test = maskdef.validator; } : new RegExp("."), cardinality: maskdef.cardinality, optionality: isOptional, newBlockMarker: newBlockMarker, offset: 0, casing: maskdef["casing"], def: element });
                         } else {
                         } else {
-                            outElem.push({ fn: null, cardinality: 0, optionality: isOptional, newBlockMarker: newBlockMarker, offset: 0, casing: null });
+                            outElem.push({ fn: null, cardinality: 0, optionality: isOptional, newBlockMarker: newBlockMarker, offset: 0, casing: null, def: element });
                             escaped = false;
                             escaped = false;
                         }
                         }
                         //reset newBlockMarker
                         //reset newBlockMarker
@@ -303,10 +303,10 @@ This plugin is based on the masked input plugin written by Josh Bush (digitalbus
             }
             }
 
 
             //needed to handle the non-greedy mask repetitions
             //needed to handle the non-greedy mask repetitions
-            function prepareBuffer(buffer, position) {
+            function prepareBuffer(buffer, position, isRTL) {
                 while ((buffer.length < position || position < 0) && buffer.length < getMaskLength()) {
                 while ((buffer.length < position || position < 0) && buffer.length < getMaskLength()) {
                     var j = 0;
                     var j = 0;
-                    if ($input.data('inputmask')['isRTL']) {
+                    if (isRTL) {
                         j = _buffer.length - 1;
                         j = _buffer.length - 1;
                         position = position + _buffer.length;
                         position = position + _buffer.length;
                         while (_buffer[j] !== undefined)
                         while (_buffer[j] !== undefined)
@@ -344,14 +344,20 @@ This plugin is based on the masked input plugin written by Josh Bush (digitalbus
 
 
             function checkVal(input, buffer, clearInvalid) {
             function checkVal(input, buffer, clearInvalid) {
                 var isRTL = $(input).data('inputmask')['isRTL'],
                 var isRTL = $(input).data('inputmask')['isRTL'],
-                    inputValue = TruncateInput(input._valueGet(), isRTL);
+                    inputValue = TruncateInput(input._valueGet(), isRTL).split('');
+
+                if (isRTL) { //align inputValue for RTL/numeric input
+                    var neededLength = _buffer.length - 1, _bufferPos = neededLength;
+                    while (inputValue[neededLength] === undefined && _buffer[_bufferPos] !== undefined)
+                        inputValue.unshift(_buffer[_bufferPos--]);
+                }
                 clearBuffer(buffer, 0, buffer.length);
                 clearBuffer(buffer, 0, buffer.length);
                 buffer.length = _buffer.length;
                 buffer.length = _buffer.length;
                 var lastMatch = -1, checkPosition = -1, maskL = getMaskLength(), ivl = inputValue.length, rtlMatch = ivl == 0 ? maskL : -1;
                 var lastMatch = -1, checkPosition = -1, maskL = getMaskLength(), ivl = inputValue.length, rtlMatch = ivl == 0 ? maskL : -1;
                 for (var i = 0; i < ivl; i++) {
                 for (var i = 0; i < ivl; i++) {
                     for (var pos = checkPosition + 1; pos < maskL; pos++) {
                     for (var pos = checkPosition + 1; pos < maskL; pos++) {
                         if (isMask(pos)) {
                         if (isMask(pos)) {
-                            var c = inputValue.charAt(i);
+                            var c = inputValue[i];
                             if (isValid(pos, c, buffer) !== false) {
                             if (isValid(pos, c, buffer) !== false) {
                                 setBufferElement(buffer, pos, c);
                                 setBufferElement(buffer, pos, c);
                                 lastMatch = checkPosition = pos;
                                 lastMatch = checkPosition = pos;
@@ -368,7 +374,7 @@ This plugin is based on the masked input plugin written by Josh Bush (digitalbus
                             if (lastMatch == checkPosition) //once outsync the nonmask cannot be the lastmatch
                             if (lastMatch == checkPosition) //once outsync the nonmask cannot be the lastmatch
                                 lastMatch = pos;
                                 lastMatch = pos;
                             checkPosition = pos;
                             checkPosition = pos;
-                            if (inputValue.charAt(i) == getBufferElement(buffer, pos))
+                            if (inputValue[i] == getBufferElement(buffer, pos))
                                 break;
                                 break;
                         }
                         }
                     }
                     }
@@ -679,7 +685,7 @@ This plugin is based on the masked input plugin written by Josh Bush (digitalbus
                             var j = seekNext(buffer, i);
                             var j = seekNext(buffer, i);
                             var p = getBufferElement(buffer, j);
                             var p = getBufferElement(buffer, j);
                             if (p != getPlaceHolder(j)) {
                             if (p != getPlaceHolder(j)) {
-                                if (j < getMaskLength() && isValid(i, p, buffer) !== false) {
+                                if (j < getMaskLength() && isValid(i, p, buffer) !== false && tests[determineTestPosition(i)].def == tests[determineTestPosition(j)].def) {
                                     setBufferElement(buffer, i, getBufferElement(buffer, j));
                                     setBufferElement(buffer, i, getBufferElement(buffer, j));
                                 } else {
                                 } else {
                                     if (isMask(i))
                                     if (isMask(i))
@@ -706,7 +712,7 @@ This plugin is based on the masked input plugin written by Josh Bush (digitalbus
                             if (t != getPlaceHolder(i)) {
                             if (t != getPlaceHolder(i)) {
                                 var j = seekNext(buffer, i);
                                 var j = seekNext(buffer, i);
                                 if (j < getMaskLength()) {
                                 if (j < getMaskLength()) {
-                                    if (isValid(j, t, buffer) !== false)
+                                    if (isValid(j, t, buffer) !== false && tests[determineTestPosition(i)].def == tests[determineTestPosition(j)].def)
                                         c = t;
                                         c = t;
                                     else {
                                     else {
                                         if (isMask(j))
                                         if (isMask(j))
@@ -816,7 +822,7 @@ This plugin is based on the masked input plugin written by Josh Bush (digitalbus
                                 if (isValid(p, c, buffer)) {
                                 if (isValid(p, c, buffer)) {
                                     if (isValid(firstMaskPos, buffer[firstMaskPos], buffer) == false || (opts.greedy === false && buffer.length < maskL)) {
                                     if (isValid(firstMaskPos, buffer[firstMaskPos], buffer) == false || (opts.greedy === false && buffer.length < maskL)) {
                                         if (buffer[firstMaskPos] != getPlaceHolder(firstMaskPos) && buffer.length < maskL) {
                                         if (buffer[firstMaskPos] != getPlaceHolder(firstMaskPos) && buffer.length < maskL) {
-                                            var offset = prepareBuffer(buffer, -1) + 1;
+                                            var offset = prepareBuffer(buffer, -1, isRTL) + 1;
                                             p = p + offset;
                                             p = p + offset;
                                             maskL = buffer.length;
                                             maskL = buffer.length;
                                         }
                                         }
@@ -828,7 +834,7 @@ This plugin is based on the masked input plugin written by Josh Bush (digitalbus
                             }
                             }
                             else {
                             else {
                                 var p = seekNext(buffer, pos.begin - 1);
                                 var p = seekNext(buffer, pos.begin - 1);
-                                prepareBuffer(buffer, p);
+                                prepareBuffer(buffer, p, isRTL);
                                 if (isValid(p, c, buffer)) {
                                 if (isValid(p, c, buffer)) {
                                     if (opts.insertMode == true) shiftR(p, maskL, c); else setBufferElement(buffer, p, c);
                                     if (opts.insertMode == true) shiftR(p, maskL, c); else setBufferElement(buffer, p, c);
                                     var next = seekNext(buffer, p);
                                     var next = seekNext(buffer, p);