Browse Source

Merge pull request #72 from RobinHerbots/dev

Dev
Robin Herbots 13 years ago
parent
commit
3b0c98be84

+ 8 - 8
js/jquery.inputmask.date.extentions.js

@@ -3,7 +3,7 @@ Input Mask plugin extentions
 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.4
+Version: 1.0.5
 
 Optional extentions on the jquery.inputmask base
 */
@@ -73,7 +73,7 @@ Optional extentions on the jquery.inputmask base
                                     buffer[pos - 1] = "0";
                                     buffer[pos] = chrs.charAt(0);
                                     pos++;
-                                    return pos;
+                                    return { "pos": pos };
                                 }
                             }
                         }
@@ -87,7 +87,7 @@ Optional extentions on the jquery.inputmask base
                             if (isValid) {
                                 buffer[pos] = "0";
                                 pos++;
-                                return pos;
+                                return { "pos": pos };
                             }
                         }
                         return isValid;
@@ -104,7 +104,7 @@ Optional extentions on the jquery.inputmask base
                                         buffer[pos - 1] = "0";
                                         buffer[pos] = chrs.charAt(0);
                                         pos++;
-                                        return pos;
+                                        return { "pos": pos };
                                     }
                                 }
                             }
@@ -119,7 +119,7 @@ Optional extentions on the jquery.inputmask base
                                 if (isValid) {
                                     buffer[pos] = "0";
                                     pos++;
-                                    return pos;
+                                    return { "pos": pos };
                                 }
                             }
                             return isValid;
@@ -154,7 +154,7 @@ Optional extentions on the jquery.inputmask base
                                 if (isValid) {
                                     buffer[pos++] = yearPrefix[0];
                                     buffer[pos++] = yearPrefix[1];
-                                    return pos;
+                                    return { "pos": pos };
                                 }
                             }
                             return isValid;
@@ -211,7 +211,7 @@ Optional extentions on the jquery.inputmask base
                                             buffer[pos - 1] = "0";
                                             buffer[pos] = chrs.charAt(0);
                                             pos++;
-                                            return pos;
+                                            return { "pos": pos };
                                         }
                                     }
                                 }
@@ -244,7 +244,7 @@ Optional extentions on the jquery.inputmask base
                                     if (isValid) {
                                         buffer[pos] = "0";
                                         pos++;
-                                        return pos;
+                                        return { "pos": pos };
                                     }
                                 }
                                 return isValid;

+ 25 - 5
js/jquery.inputmask.js

@@ -3,7 +3,7 @@ Input Mask plugin for jquery
 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.7
+Version: 1.0.9
  
 This plugin is based on the masked input plugin written by Josh Bush (digitalbush.com)
 */
@@ -256,6 +256,7 @@ This plugin is based on the masked input plugin written by Josh Bush (digitalbus
                 }
 
                 if (c) { chrs += c; }
+                //return is false or a json object => { pos: ??, c: ??}
                 return tests[testPos].fn != null ? tests[testPos].fn.test(chrs, buffer, pos, strict, opts) : false;
             }
 
@@ -391,7 +392,10 @@ This plugin is based on the masked input plugin written by Josh Bush (digitalbus
                         if (isMask(pos)) {
                             var c = inputValue[i];
                             if ((np = isValid(pos, c, buffer, !clearInvalid)) !== false) {
-                                if (np !== true) pos = np; //set new position from isValid
+                                if (np !== true) {
+                                    pos = np.pos || pos; //set new position from isValid
+                                    c = np.c || c; //set new char from isValid
+                                }
                                 setBufferElement(buffer, pos, c);
                                 lastMatch = checkPosition = pos;
                             } else {
@@ -530,6 +534,7 @@ This plugin is based on the masked input plugin written by Josh Bush (digitalbus
                 ignorable = false,
                 lastPosition = -1,
                 firstMaskPos = seekNext(buffer, -1),
+                lastMaskPos = seekPrevious(buffer, getMaskLength()),
                 isRTL = false;
                 if (el.dir == "rtl" || opts.numericInput) {
                     el.dir = "ltr"
@@ -870,7 +875,10 @@ This plugin is based on the masked input plugin written by Josh Bush (digitalbus
                             if (isRTL) {
                                 var p = opts.numericInput ? pos.end : seekPrevious(buffer, pos.end), np;
                                 if ((np = isValid(p == maskL || getBufferElement(buffer, p) == opts.radixPoint[opts.radixPoint.length - 1] ? seekPrevious(buffer, p) : p, c, buffer, false)) !== false) {
-                                    if (np !== true) p = np; //set new position from isValid
+                                    if (np !== true) {
+                                        p = np.pos || pos; //set new position from isValid
+                                        c = np.c || c; //set new char 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);
@@ -887,8 +895,20 @@ This plugin is based on the masked input plugin written by Josh Bush (digitalbus
                                 var p = seekNext(buffer, pos.begin - 1), np;
                                 prepareBuffer(buffer, p, isRTL);
                                 if ((np = isValid(p, c, buffer, false)) !== false) {
-                                    if (np !== true) p = np; //set new position from isValid
-                                    if (opts.insertMode == true) shiftR(p, buffer.length, c); else setBufferElement(buffer, p, c);
+                                    if (np !== true) {
+                                        p = np.pos || p; //set new position from isValid
+                                        c = np.c || c; //set new char from isValid
+                                    }
+                                    if (opts.insertMode == true) {
+                                        var lastUnmaskedPosition = getMaskLength();
+                                        while (getBufferElement(buffer, lastUnmaskedPosition) != getPlaceHolder(lastUnmaskedPosition) && lastUnmaskedPosition >= p) {
+                                            lastUnmaskedPosition = seekPrevious(buffer, lastUnmaskedPosition);
+                                        }
+                                        if (lastUnmaskedPosition >= p)
+                                            shiftR(p, buffer.length, c);
+                                        else return false;
+                                    }
+                                    else setBufferElement(buffer, p, c);
                                     var next = seekNext(buffer, p);
                                     writeBuffer(input, buffer, next);
 

+ 86 - 86
js/jquery.inputmask.numeric.extentions.js

@@ -3,98 +3,98 @@ Input Mask plugin extentions
 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.2
+Version: 1.0.3
 
 Optional extentions on the jquery.inputmask base
 */
-(function($) {
-    //number aliases 
-    $.extend($.inputmask.defaults, {
-        definitions: {
-            '9': {
-                validator: function(chrs, buffer, pos, strict, opts) {
-                    var isValid = opts.definitions['9'].regex.test(chrs);
-                    if (isValid) {
-                        //do some grouping
-                    }
-                    return isValid;
-                },
-                cardinality: 1,
-                regex: new RegExp("[0-9]")
-            }
-        }
-    });
-    $.extend($.inputmask.defaults.aliases, {
-        'decimal': {
-            mask: "~",
-            placeholder: "",
-            repeat: 10,
-            greedy: false,
-            numericInput: true,
-            regex: {
-                number: function(radixPoint, digits) { return new RegExp("^[\+\\d\-]{1}\\d*[" + radixPoint + "]?\\d" + digits + "$"); }
-            },
-            onKeyDown: function(e, opts) {
-                var $input = $(this), input = this;
-                if (e.keyCode == opts.keyCode.TAB) {
-                    var nptStr = input._valueGet();
-                    var radixPosition = nptStr.indexOf(opts.radixPoint[opts.radixPoint.length - 1]);
-                    if (radixPosition != -1) {
-                        for (var i = 1; i < opts.digits; i++) {
-                            if (nptStr[radixPosition + i]) nptStr = nptStr + "0";
+            (function($) {
+                //number aliases 
+                $.extend($.inputmask.defaults, {
+                    definitions: {
+                        '9': {
+                            validator: function(chrs, buffer, pos, strict, opts) {
+                                var isValid = opts.definitions['9'].regex.test(chrs);
+                                if (isValid) {
+                                    //do some grouping
+                                }
+                                return isValid;
+                            },
+                            cardinality: 1,
+                            regex: new RegExp("[0-9]")
                         }
-                        $input.val(nptStr);
                     }
-                }
-            },
-            definitions: {
-                '~': { //real number
-                    validator: function(chrs, buffer, pos, strict, opts) {
-                        function digitExpression() {
-                            return isNaN(opts.digits) ? opts.digits : '{0,' + opts.digits + '}';
-                        }
-                        var cbuf = buffer.slice();
-                        cbuf.splice(pos, 0, chrs);
-                        var bufferStr = cbuf.join('');
-                        var isValid = opts.regex.number(opts.radixPoint, digitExpression()).test(bufferStr);
-                        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;
+                });
+                $.extend($.inputmask.defaults.aliases, {
+                    'decimal': {
+                        mask: "~",
+                        placeholder: "",
+                        repeat: 10,
+                        greedy: false,
+                        numericInput: true,
+                        regex: {
+                            number: function(radixPoint, digits) { return new RegExp("^[\+\\d\-]{1}\\d*[" + radixPoint + "]?\\d" + digits + "$"); }
+                        },
+                        onKeyDown: function(e, opts) {
+                            var $input = $(this), input = this;
+                            if (e.keyCode == opts.keyCode.TAB) {
+                                var nptStr = input._valueGet();
+                                var radixPosition = nptStr.indexOf(opts.radixPoint[opts.radixPoint.length - 1]);
+                                if (radixPosition != -1) {
+                                    for (var i = 1; i < opts.digits; i++) {
+                                        if (nptStr[radixPosition + i]) nptStr = nptStr + "0";
                                     }
+                                    $input.val(nptStr);
                                 }
                             }
-                        }
-                        //todo grouping, radixpoint positioning
-                        return isValid;
+                        },
+                        definitions: {
+                            '~': { //real number
+                                validator: function(chrs, buffer, pos, strict, opts) {
+                                    function digitExpression() {
+                                        return isNaN(opts.digits) ? opts.digits : '{0,' + opts.digits + '}';
+                                    }
+                                    var cbuf = buffer.slice();
+                                    cbuf.splice(pos, 0, chrs);
+                                    var bufferStr = cbuf.join('');
+                                    var isValid = opts.regex.number(opts.radixPoint, digitExpression()).test(bufferStr);
+                                    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": pos };
+                                                }
+                                            }
+                                        }
+                                    }
+                                    //todo grouping, radixpoint positioning
+                                    return isValid;
+                                },
+                                cardinality: 1,
+                                prevalidator: null
+                            }
+                        },
+                        insertMode: true
                     },
-                    cardinality: 1,
-                    prevalidator: null
-                }
-            },
-            insertMode: true
-        },
-        'non-negative-decimal': {
-            regex: {
-                number: function(radixPoint, digits) { return new RegExp("^\\d+[" + radixPoint + "]?\\d" + digits + "$"); }
-            },
-            alias: "decimal"
-        },
-        'integer': {
-            regex: {
-                number: function() { return new RegExp("^([\+\-]?\\d*)$"); }
-            },
-            alias: "decimal"
-        }
-    });
-})(jQuery);
+                    'non-negative-decimal': {
+                        regex: {
+                            number: function(radixPoint, digits) { return new RegExp("^\\d+[" + radixPoint + "]?\\d" + digits + "$"); }
+                        },
+                        alias: "decimal"
+                    },
+                    'integer': {
+                        regex: {
+                            number: function() { return new RegExp("^([\+\-]?\\d*)$"); }
+                        },
+                        alias: "decimal"
+                    }
+                });
+            })(jQuery);