Browse Source

update analysemask

Robin Herbots 12 years ago
parent
commit
162116afec
1 changed files with 24 additions and 10 deletions
  1. 24 10
      js/jquery.inputmask.js

+ 24 - 10
js/jquery.inputmask.js

@@ -196,11 +196,11 @@
                 function analyseMask(mask) {
                 function analyseMask(mask) {
                     var tokenizer = /(?:[?*+]|\{[0-9]+(?:,[0-9]*)?\})\??|[^.?*+^${[]()|\\]+|./g,
                     var tokenizer = /(?:[?*+]|\{[0-9]+(?:,[0-9]*)?\})\??|[^.?*+^${[]()|\\]+|./g,
                         escaped = false;
                         escaped = false;
-                    function maskToken() {
+                    function maskToken(isGroup, isOptional, isQuantifier) {
                         this.matches = [];
                         this.matches = [];
-                        this.isGroup = false;
-                        this.isOptional = false;
-                        this.isQuantifier = false;
+                        this.isGroup = isGroup || false;
+                        this.isOptional = isOptional || false;
+                        this.isQuantifier = isQuantifier || false;
                         this.mask; //TODO contains the matches in placeholder form ~ to speedup the placeholder generation
                         this.mask; //TODO contains the matches in placeholder form ~ to speedup the placeholder generation
                     };
                     };
                     function InsertTestDefinition(mtoken, element, position) {
                     function InsertTestDefinition(mtoken, element, position) {
@@ -242,22 +242,19 @@
                                 // optional opening
                                 // optional opening
                                 if (!currentToken.isGroup && currentToken.matches.length > 0)
                                 if (!currentToken.isGroup && currentToken.matches.length > 0)
                                     maskTokens.push(currentToken);
                                     maskTokens.push(currentToken);
-                                currentToken = new maskToken();
-                                currentToken.isOptional = true;
+                                currentToken = new maskToken(false, true);
                                 openenings.push(currentToken);
                                 openenings.push(currentToken);
                                 break;
                                 break;
                             case opts.groupmarker.start:
                             case opts.groupmarker.start:
                                 // Group opening
                                 // Group opening
                                 if (!currentToken.isGroup && currentToken.matches.length > 0)
                                 if (!currentToken.isGroup && currentToken.matches.length > 0)
                                     maskTokens.push(currentToken);
                                     maskTokens.push(currentToken);
-                                currentToken = new maskToken();
-                                currentToken.isGroup = true;
+                                currentToken = new maskToken(true);
                                 openenings.push(currentToken);
                                 openenings.push(currentToken);
                                 break;
                                 break;
                             case opts.quantifiermarker.start:
                             case opts.quantifiermarker.start:
                                 //Quantifier
                                 //Quantifier
-                                var quantifier = new maskToken();
-                                quantifier.isQuantifier = true;
+                                var quantifier = new maskToken(false, false, true);
                                 quantifier.matches.push(m);
                                 quantifier.matches.push(m);
                                 if (openenings.length > 0) {
                                 if (openenings.length > 0) {
                                     openenings[openenings.length - 1]["matches"].push(quantifier);
                                     openenings[openenings.length - 1]["matches"].push(quantifier);
@@ -288,6 +285,23 @@
                     if (currentToken.matches.length > 0)
                     if (currentToken.matches.length > 0)
                         maskTokens.push(currentToken);
                         maskTokens.push(currentToken);
 
 
+                    if (opts.repeat > 0 || opts.repeat == "*" || opts.repeat == "+") {
+                        var groupToken = new maskToken(true),
+                        quantifierToken = new maskToken(false, false, true);
+                        var qntfr = opts.repeat == "*" ? qntfr = "0,*" : (opts.repeat == "+" ? qntfr = "1,*" : (opts.greedy ? opts.repeat : "1," + opts.repeat));
+                        quantifierToken.matches.push(opts.quantifiermarker.start + qntfr + opts.quantifiermarker.end);
+                        if (maskTokens.length > 1) {
+                            groupToken.matches = maskTokens;
+                            groupToken.matches.push(quantifierToken);
+                            maskTokens = [groupToken];
+                        } else {
+                            maskTokens[0].matches.push(quantifierToken);
+
+                        }
+                    }
+
+
+                    console.log(JSON.stringify(maskTokens));
                     return maskTokens;
                     return maskTokens;
                 }
                 }