Browse Source

refactoring

Robin Herbots 7 years ago
parent
commit
146d7a8201
52 changed files with 240 additions and 402 deletions
  1. 9 8
      CHANGELOG.md
  2. 0 3
      README.md
  3. 1 1
      bower.json
  4. 1 1
      component.json
  5. 1 1
      composer.json
  6. 1 1
      dist/inputmask/bindings/inputmask.binding.js
  7. 1 1
      dist/inputmask/dependencyLibs/inputmask.dependencyLib.jqlite.js
  8. 1 1
      dist/inputmask/dependencyLibs/inputmask.dependencyLib.jquery.js
  9. 1 1
      dist/inputmask/dependencyLibs/inputmask.dependencyLib.js
  10. 1 1
      dist/inputmask/global/document.js
  11. 1 1
      dist/inputmask/global/window.js
  12. 1 1
      dist/inputmask/inputmask.date.extensions.js
  13. 1 1
      dist/inputmask/inputmask.extensions.js
  14. 44 74
      dist/inputmask/inputmask.js
  15. 9 9
      dist/inputmask/inputmask.numeric.extensions.js
  16. 1 1
      dist/inputmask/inputmask.phone.extensions.js
  17. 1 1
      dist/inputmask/jquery.inputmask.js
  18. 1 1
      dist/inputmask/phone-codes/phone-be.js
  19. 1 1
      dist/inputmask/phone-codes/phone-ca.js
  20. 1 1
      dist/inputmask/phone-codes/phone-hu.js
  21. 1 1
      dist/inputmask/phone-codes/phone-mx.js
  22. 1 1
      dist/inputmask/phone-codes/phone-nl.js
  23. 1 1
      dist/inputmask/phone-codes/phone-ru.js
  24. 1 1
      dist/inputmask/phone-codes/phone-uk.js
  25. 1 1
      dist/inputmask/phone-codes/phone.js
  26. 52 82
      dist/jquery.inputmask.bundle.js
  27. 1 1
      dist/min/inputmask/bindings/inputmask.binding.min.js
  28. 1 1
      dist/min/inputmask/dependencyLibs/inputmask.dependencyLib.jqlite.min.js
  29. 1 1
      dist/min/inputmask/dependencyLibs/inputmask.dependencyLib.jquery.min.js
  30. 1 1
      dist/min/inputmask/dependencyLibs/inputmask.dependencyLib.min.js
  31. 1 1
      dist/min/inputmask/global/document.min.js
  32. 1 1
      dist/min/inputmask/global/window.min.js
  33. 1 1
      dist/min/inputmask/inputmask.date.extensions.min.js
  34. 1 1
      dist/min/inputmask/inputmask.extensions.min.js
  35. 2 2
      dist/min/inputmask/inputmask.min.js
  36. 2 2
      dist/min/inputmask/inputmask.numeric.extensions.min.js
  37. 1 1
      dist/min/inputmask/inputmask.phone.extensions.min.js
  38. 1 1
      dist/min/inputmask/jquery.inputmask.min.js
  39. 1 1
      dist/min/inputmask/phone-codes/phone-be.min.js
  40. 1 1
      dist/min/inputmask/phone-codes/phone-ca.min.js
  41. 1 1
      dist/min/inputmask/phone-codes/phone-hu.min.js
  42. 1 1
      dist/min/inputmask/phone-codes/phone-mx.min.js
  43. 1 1
      dist/min/inputmask/phone-codes/phone-nl.min.js
  44. 1 1
      dist/min/inputmask/phone-codes/phone-ru.min.js
  45. 1 1
      dist/min/inputmask/phone-codes/phone-uk.min.js
  46. 1 1
      dist/min/inputmask/phone-codes/phone.min.js
  47. 2 2
      dist/min/jquery.inputmask.bundle.min.js
  48. 50 138
      js/inputmask.js
  49. 10 22
      js/inputmask.numeric.extensions.js
  50. 1 1
      package.json
  51. 19 19
      qunit/tests_base.js
  52. 1 1
      qunit/tests_regex.js

+ 9 - 8
CHANGELOG.md

@@ -9,17 +9,18 @@ All notable changes to this project will be documented in this file.
 - extend positionCaretOnClick with "select" to select the whole input on focus
 
 ### Updates
-- improve alternate fn
+- code cleanup and refactoring
+    - merge setValidPosition and stripValidPositions => revalidateMask
+    - remove canClearPosition hook
+    - change notation of optionalmarker, quantifiermarker, groupmarker
+    - drop prevalidator and cardinality support in definitions
+    - drop Regex alias
+    - drop all date/time related aliases => replaced by new datetime alias
+- improve alternation logic
+- improve inputfallback (Android)
 - better caret handling in colormask
-- change notation of optionalmarker, quantifiermarker, groupmarker
-- drop prevalidator and cardinality support in definitions
-- better determination of the NdxInitializer (alternations)
 - disable autocorrect on safari when disablePredictiveText is used
-- fix in determineTestTemplate.  Impacts alternations.
 - rename androidHack option to disablePredictiveText. Make it available for other platforms.
-- drop Regex alias
-- drop all date/time related aliases
-- enhance inputfallback (Android)
 
 ### Fixed
 - Hang on combination of optional mask and repeat #698

+ 0 - 3
README.md

@@ -1028,9 +1028,6 @@ $(selector).inputmask({
 });
 ```
 
-### canClearPosition
-Hook to alter the clear behavior in the stripValidPositions<br>Args => maskset, position, lastValidPosition, opts<br>Return => true|false
-
 ### postValidation
 Hook to postValidate the result from isValid.  Usefull for validating the entry as a whole.  Args => buffer, currentResult, opts<br>Return => true|false|command object
 

+ 1 - 1
bower.json

@@ -1,6 +1,6 @@
 {
   "name": "inputmask",
-  "version": "4.0.0-beta.25",
+  "version": "4.0.0-beta.26",
   "main": [
 	  "./dist/inputmask/inputmask.js",
 	  "./dist/inputmask/inputmask.extensions.js",

+ 1 - 1
component.json

@@ -2,7 +2,7 @@
 	"name": "inputmask",
 	"repository": "robinherbots/Inputmask",
 	"description": "Inputmask is a javascript library which creates an input mask.  Inputmask can run against vanilla javascript, jQuery and jqlite.",
-	"version": "4.0.0-beta.25",
+	"version": "4.0.0-beta.26",
 	"keywords": [
 		"jquery",
 		"plugins",

+ 1 - 1
composer.json

@@ -1,7 +1,7 @@
 {
   "name": "robinherbots/inputmask",
   "description": "Inputmask is a javascript library which creates an input mask.  Inputmask can run against vanilla javascript, jQuery and jqlite.",
-  "version": "4.0.0-beta.25",
+  "version": "4.0.0-beta.26",
   "type": "library",
   "keywords": ["jquery", "plugins", "input", "form", "inputmask", "mask"],
   "homepage": "http://robinherbots.github.io/Inputmask",

+ 1 - 1
dist/inputmask/bindings/inputmask.binding.js

@@ -3,7 +3,7 @@
 * https://github.com/RobinHerbots/Inputmask
 * Copyright (c) 2010 - 2018 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 4.0.0-beta.25
+* Version: 4.0.0-beta.26
 */
 
 !function(factory) {

+ 1 - 1
dist/inputmask/dependencyLibs/inputmask.dependencyLib.jqlite.js

@@ -3,7 +3,7 @@
 * https://github.com/RobinHerbots/Inputmask
 * Copyright (c) 2010 - 2018 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 4.0.0-beta.25
+* Version: 4.0.0-beta.26
 */
 
 !function(factory) {

+ 1 - 1
dist/inputmask/dependencyLibs/inputmask.dependencyLib.jquery.js

@@ -3,7 +3,7 @@
 * https://github.com/RobinHerbots/Inputmask
 * Copyright (c) 2010 - 2018 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 4.0.0-beta.25
+* Version: 4.0.0-beta.26
 */
 
 !function(factory) {

+ 1 - 1
dist/inputmask/dependencyLibs/inputmask.dependencyLib.js

@@ -3,7 +3,7 @@
 * https://github.com/RobinHerbots/Inputmask
 * Copyright (c) 2010 - 2018 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 4.0.0-beta.25
+* Version: 4.0.0-beta.26
 */
 
 !function(factory) {

+ 1 - 1
dist/inputmask/global/document.js

@@ -3,7 +3,7 @@
 * https://github.com/RobinHerbots/Inputmask
 * Copyright (c) 2010 - 2018 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 4.0.0-beta.25
+* Version: 4.0.0-beta.26
 */
 
 "function" == typeof define && define.amd ? define(function() {

+ 1 - 1
dist/inputmask/global/window.js

@@ -3,7 +3,7 @@
 * https://github.com/RobinHerbots/Inputmask
 * Copyright (c) 2010 - 2018 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 4.0.0-beta.25
+* Version: 4.0.0-beta.26
 */
 
 "function" == typeof define && define.amd ? define(function() {

+ 1 - 1
dist/inputmask/inputmask.date.extensions.js

@@ -3,7 +3,7 @@
 * https://github.com/RobinHerbots/Inputmask
 * Copyright (c) 2010 - 2018 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 4.0.0-beta.25
+* Version: 4.0.0-beta.26
 */
 
 !function(factory) {

+ 1 - 1
dist/inputmask/inputmask.extensions.js

@@ -3,7 +3,7 @@
 * https://github.com/RobinHerbots/Inputmask
 * Copyright (c) 2010 - 2018 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 4.0.0-beta.25
+* Version: 4.0.0-beta.26
 */
 
 !function(factory) {

File diff suppressed because it is too large
+ 44 - 74
dist/inputmask/inputmask.js


+ 9 - 9
dist/inputmask/inputmask.numeric.extensions.js

@@ -3,7 +3,7 @@
 * https://github.com/RobinHerbots/Inputmask
 * Copyright (c) 2010 - 2018 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 4.0.0-beta.25
+* Version: 4.0.0-beta.26
 */
 
 !function(factory) {
@@ -34,9 +34,10 @@
                 if (mask += autoEscape(opts.prefix, opts), !0 === opts.integerOptional ? mask += "~{1," + opts.integerDigits + "}" : mask += "~{" + opts.integerDigits + "}", 
                 opts.digits !== undefined) {
                     var radixDef = opts.decimalProtect ? ":" : opts.radixPoint, dq = opts.digits.toString().split(",");
-                    isFinite(dq[0] && dq[1] && isFinite(dq[1])) ? mask += radixDef + ";{" + opts.digits + "}" : (isNaN(opts.digits) || parseInt(opts.digits) > 0) && (opts.digitsOptional ? mask += "[" + radixDef + ";{1," + opts.digits + "}]" : mask += radixDef + ";{" + opts.digits + "}");
+                    isFinite(dq[0]) && dq[1] && isFinite(dq[1]) ? mask += radixDef + ";{" + opts.digits + "}" : (isNaN(opts.digits) || parseInt(opts.digits) > 0) && (opts.digitsOptional ? mask += "[" + radixDef + ";{1," + opts.digits + "}]" : mask += radixDef + ";{" + opts.digits + "}");
                 }
-                return mask += autoEscape(opts.suffix, opts), mask += "[-]", opts.greedy = !1, mask;
+                return mask += autoEscape(opts.suffix, opts), mask += "[-]", opts.greedy = !1, console.log(mask), 
+                mask;
             },
             placeholder: "",
             greedy: !1,
@@ -213,8 +214,11 @@
                                     pos: pos
                                 };
                             }
-                        } else strict || chrs !== opts.radixPoint || maskset.validPositions[pos - 1] !== undefined || (maskset.buffer[pos] = "0", 
-                        isValid = {
+                        } else strict || chrs !== opts.radixPoint || maskset.validPositions[pos - 1] !== undefined || (isValid = {
+                            insert: {
+                                pos: pos,
+                                c: 0
+                            },
                             pos: pos + 1
                         });
                         return isValid;
@@ -285,10 +289,6 @@
                 }
                 return initialValue;
             },
-            canClearPosition: function(maskset, position, lvp, strict, opts) {
-                var vp = maskset.validPositions[position], canClear = vp.input !== opts.radixPoint || null !== maskset.validPositions[position].match.fn && !1 === opts.decimalProtect || vp.input === opts.radixPoint && maskset.validPositions[position + 1] && null === maskset.validPositions[position + 1].match.fn || isFinite(vp.input) || position === lvp || vp.input === opts.groupSeparator || vp.input === opts.negationSymbol.front || vp.input === opts.negationSymbol.back;
-                return canClear && "+" === vp.match.nativeDef && (opts.isNegative = !1), canClear;
-            },
             onKeyDown: function(e, buffer, caretPos, opts) {
                 var $input = $(this);
                 if (e.ctrlKey) switch (e.keyCode) {

+ 1 - 1
dist/inputmask/inputmask.phone.extensions.js

@@ -3,7 +3,7 @@
 * https://github.com/RobinHerbots/Inputmask
 * Copyright (c) 2010 - 2018 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 4.0.0-beta.25
+* Version: 4.0.0-beta.26
 */
 
 !function(factory) {

+ 1 - 1
dist/inputmask/jquery.inputmask.js

@@ -3,7 +3,7 @@
 * https://github.com/RobinHerbots/Inputmask
 * Copyright (c) 2010 - 2018 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 4.0.0-beta.25
+* Version: 4.0.0-beta.26
 */
 
 !function(factory) {

+ 1 - 1
dist/inputmask/phone-codes/phone-be.js

@@ -3,7 +3,7 @@
 * https://github.com/RobinHerbots/Inputmask
 * Copyright (c) 2010 - 2018 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 4.0.0-beta.25
+* Version: 4.0.0-beta.26
 */
 
 !function(factory) {

+ 1 - 1
dist/inputmask/phone-codes/phone-ca.js

@@ -3,7 +3,7 @@
 * https://github.com/RobinHerbots/Inputmask
 * Copyright (c) 2010 - 2018 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 4.0.0-beta.25
+* Version: 4.0.0-beta.26
 */
 
 !function(factory) {

+ 1 - 1
dist/inputmask/phone-codes/phone-hu.js

@@ -3,7 +3,7 @@
 * https://github.com/RobinHerbots/Inputmask
 * Copyright (c) 2010 - 2018 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 4.0.0-beta.25
+* Version: 4.0.0-beta.26
 */
 
 !function(factory) {

+ 1 - 1
dist/inputmask/phone-codes/phone-mx.js

@@ -3,7 +3,7 @@
 * https://github.com/RobinHerbots/Inputmask
 * Copyright (c) 2010 - 2018 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 4.0.0-beta.25
+* Version: 4.0.0-beta.26
 */
 
 !function(factory) {

+ 1 - 1
dist/inputmask/phone-codes/phone-nl.js

@@ -3,7 +3,7 @@
 * https://github.com/RobinHerbots/Inputmask
 * Copyright (c) 2010 - 2018 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 4.0.0-beta.25
+* Version: 4.0.0-beta.26
 */
 
 !function(factory) {

+ 1 - 1
dist/inputmask/phone-codes/phone-ru.js

@@ -3,7 +3,7 @@
 * https://github.com/RobinHerbots/Inputmask
 * Copyright (c) 2010 - 2018 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 4.0.0-beta.25
+* Version: 4.0.0-beta.26
 */
 
 !function(factory) {

+ 1 - 1
dist/inputmask/phone-codes/phone-uk.js

@@ -3,7 +3,7 @@
 * https://github.com/RobinHerbots/Inputmask
 * Copyright (c) 2010 - 2018 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 4.0.0-beta.25
+* Version: 4.0.0-beta.26
 */
 
 !function(factory) {

+ 1 - 1
dist/inputmask/phone-codes/phone.js

@@ -3,7 +3,7 @@
 * https://github.com/RobinHerbots/Inputmask
 * Copyright (c) 2010 - 2018 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 4.0.0-beta.25
+* Version: 4.0.0-beta.26
 */
 
 !function(factory) {

File diff suppressed because it is too large
+ 52 - 82
dist/jquery.inputmask.bundle.js


File diff suppressed because it is too large
+ 1 - 1
dist/min/inputmask/bindings/inputmask.binding.min.js


File diff suppressed because it is too large
+ 1 - 1
dist/min/inputmask/dependencyLibs/inputmask.dependencyLib.jqlite.min.js


+ 1 - 1
dist/min/inputmask/dependencyLibs/inputmask.dependencyLib.jquery.min.js

@@ -3,7 +3,7 @@
 * https://github.com/RobinHerbots/Inputmask
 * Copyright (c) 2010 - 2018 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 4.0.0-beta.25
+* Version: 4.0.0-beta.26
 */
 
 !function(e){"function"==typeof define&&define.amd?define(["jquery"],e):"object"==typeof exports?module.exports=e(require("jquery")):window.dependencyLib=e(jQuery)}(function(e){return e});

File diff suppressed because it is too large
+ 1 - 1
dist/min/inputmask/dependencyLibs/inputmask.dependencyLib.min.js


+ 1 - 1
dist/min/inputmask/global/document.min.js

@@ -3,7 +3,7 @@
 * https://github.com/RobinHerbots/Inputmask
 * Copyright (c) 2010 - 2018 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 4.0.0-beta.25
+* Version: 4.0.0-beta.26
 */
 
 "function"==typeof define&&define.amd?define(function(){return document}):"object"==typeof exports&&(module.exports=document);

+ 1 - 1
dist/min/inputmask/global/window.min.js

@@ -3,7 +3,7 @@
 * https://github.com/RobinHerbots/Inputmask
 * Copyright (c) 2010 - 2018 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 4.0.0-beta.25
+* Version: 4.0.0-beta.26
 */
 
 "function"==typeof define&&define.amd?define(function(){return window}):"object"==typeof exports&&(module.exports=window);

File diff suppressed because it is too large
+ 1 - 1
dist/min/inputmask/inputmask.date.extensions.min.js


File diff suppressed because it is too large
+ 1 - 1
dist/min/inputmask/inputmask.extensions.min.js


File diff suppressed because it is too large
+ 2 - 2
dist/min/inputmask/inputmask.min.js


File diff suppressed because it is too large
+ 2 - 2
dist/min/inputmask/inputmask.numeric.extensions.min.js


File diff suppressed because it is too large
+ 1 - 1
dist/min/inputmask/inputmask.phone.extensions.min.js


File diff suppressed because it is too large
+ 1 - 1
dist/min/inputmask/jquery.inputmask.min.js


File diff suppressed because it is too large
+ 1 - 1
dist/min/inputmask/phone-codes/phone-be.min.js


File diff suppressed because it is too large
+ 1 - 1
dist/min/inputmask/phone-codes/phone-ca.min.js


File diff suppressed because it is too large
+ 1 - 1
dist/min/inputmask/phone-codes/phone-hu.min.js


File diff suppressed because it is too large
+ 1 - 1
dist/min/inputmask/phone-codes/phone-mx.min.js


File diff suppressed because it is too large
+ 1 - 1
dist/min/inputmask/phone-codes/phone-nl.min.js


File diff suppressed because it is too large
+ 1 - 1
dist/min/inputmask/phone-codes/phone-ru.min.js


File diff suppressed because it is too large
+ 1 - 1
dist/min/inputmask/phone-codes/phone-uk.min.js


File diff suppressed because it is too large
+ 1 - 1
dist/min/inputmask/phone-codes/phone.min.js


File diff suppressed because it is too large
+ 2 - 2
dist/min/jquery.inputmask.bundle.min.js


+ 50 - 138
js/inputmask.js

@@ -96,7 +96,6 @@
                 //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, 0, 229],
                 isComplete: null, //override for isComplete - args => buffer, opts - return true || false
-                canClearPosition: $.noop, //hook to alter the clear behavior in the stripValidPositions args => maskset, position, lastValidPosition, opts => return true|false/command object
                 preValidation: null, //hook to preValidate the input.  Usefull for validating regardless the definition.	args => buffer, pos, char, isSelection, opts => return true/false/command object
                 postValidation: null, //hook to postValidate the result from isValid.	Usefull for validating the entry as a whole.	args => buffer, currentResult, opts => return true/false/json
                 staticDefinitionSymbol: undefined, //specify a definitionSymbol for static content, used to make matches for alternators
@@ -876,70 +875,6 @@
                 return (before === -1 || before == closestTo) ? after : after == -1 ? before : (closestTo - before) < (after - closestTo) ? before : after;
             }
 
-            function stripValidPositions(pos, nocheck, strict) {
-
-                // setValidPosition(pos, undefined, false, true);
-                // return;
-
-                function IsEnclosedStatic(pos) {
-                    var posMatch = getMaskSet().validPositions[pos];
-                    if (posMatch !== undefined && posMatch.match.fn === null) {
-                        var prevMatch = getMaskSet().validPositions[pos - 1],
-                            nextMatch = getMaskSet().validPositions[pos + 1];
-                        return prevMatch !== undefined && nextMatch !== undefined;
-                    }
-                    return false;
-                }
-
-                var i, startPos = pos.begin,
-                    positionsClone = $.extend(true, {}, getMaskSet().validPositions),
-                    needsValidation = false;
-                getMaskSet().p = pos.begin; //needed for alternated position after overtype selection
-
-                for (i = pos.end - 1; i >= startPos; i--) { //clear selection
-                    if (getMaskSet().validPositions[i] !== undefined) {
-                        if (nocheck === true ||
-                            ((getMaskSet().validPositions[i].match.optionality || !IsEnclosedStatic(i)) && opts.canClearPosition(getMaskSet(), i, getLastValidPosition(undefined, true), strict, opts) !== false)) {
-                            delete getMaskSet().validPositions[i];
-                        }
-                    }
-                }
-
-                //clear buffer
-                resetMaskSet(true);
-                for (i = startPos + 1; i <= getLastValidPosition();) {
-                    while (getMaskSet().validPositions[startPos] !== undefined) startPos++;
-                    if (i < startPos) i = startPos + 1;
-                    if (getMaskSet().validPositions[i] !== undefined || !isMask(i)) {
-                        var t = getTestTemplate(i);
-                        if (needsValidation === false && positionsClone[startPos] && positionsClone[startPos].match.def === t.match.def) { //obvious match
-                            getMaskSet().validPositions[startPos] = $.extend(true, {}, positionsClone[startPos]);
-                            getMaskSet().validPositions[startPos].input = t.input;
-                            delete getMaskSet().validPositions[i];
-                            i++;
-                        } else if (positionCanMatchDefinition(startPos, t.match.def)) {
-                            if (isValid(startPos, t.input || getPlaceholder(i), true) !== false) {
-                                delete getMaskSet().validPositions[i];
-                                i++;
-                                needsValidation = true;
-                            }
-                        } else if (!isMask(i)) {
-                            i++;
-                            startPos--;
-                        }
-                        startPos++;
-                    } else i++;
-                }
-
-                if (strict !== true) {
-                    i = getLastValidPosition(-1, true);
-                    while (getMaskSet().validPositions[i] && getMaskSet().validPositions[i].generatedInput === true) {
-                        delete getMaskSet().validPositions[i--];
-                    }
-                }
-                resetMaskSet(true);
-            }
-
             function determineTestTemplate(pos, tests, guessNextBest) {
                 pos = pos > 0 ? pos - 1 : 0;
                 var testPos,
@@ -1551,7 +1486,7 @@
 
                 var maskPos = pos;
                 if (pos.begin !== undefined) { //position was a position object - used to handle a delete by typing over a selection
-                    maskPos = isRTL && !isSelection(pos) ? pos.end : pos.begin;
+                    maskPos = isRTL ? pos.end : pos.begin;
                 }
 
                 function _isValid(position, c, strict) {
@@ -1569,19 +1504,16 @@
                                 } : false;
 
                         if (rslt !== false) {
-                            var elem = rslt.c !== undefined ? rslt.c : c;
+                            var elem = rslt.c !== undefined ? rslt.c : c, validatedPos = position;
                             elem = (elem === opts.skipOptionalPartCharacter && test.fn === null) ?
                                 (getPlaceholder(position, test, true) || test.def) : elem;
 
-                            var validatedPos = position,
-                                possibleModifiedBuffer = getBuffer();
-
                             if (rslt.remove !== undefined) { //remove position(s)
                                 if (!$.isArray(rslt.remove)) rslt.remove = [rslt.remove];
                                 $.each(rslt.remove.sort(function (a, b) {
                                     return b - a;
                                 }), function (ndx, lmnt) {
-                                    stripValidPositions({begin: lmnt, end: lmnt + 1}, true);
+                                    revalidateMask({begin: lmnt, end: lmnt + 1});
                                 });
                             }
                             if (rslt.insert !== undefined) { //insert position(s)
@@ -1593,27 +1525,8 @@
                                 });
                             }
 
-                            if (rslt.refreshFromBuffer) {
-                                var refresh = rslt.refreshFromBuffer;
-                                // strict = true;
-                                refreshFromBuffer(refresh === true ? refresh : refresh.start, refresh.end, possibleModifiedBuffer);
-                                if (rslt.pos === undefined && rslt.c === undefined) {
-                                    rslt.pos = getLastValidPosition();
-                                    return false; //breakout if refreshFromBuffer && nothing to insert
-                                }
-                                validatedPos = rslt.pos !== undefined ? rslt.pos : position;
-                                if (validatedPos !== position) {
-                                    rslt = $.extend(rslt, isValid(validatedPos, elem, true, fromSetValid)); //revalidate new position strict
-                                    return false;
-                                }
-
-                            } else if (rslt !== true && rslt.pos !== undefined && rslt.pos !== position) { //their is a position offset
+                            if (rslt !== true && rslt.pos !== undefined && rslt.pos !== position) { //their is a position offset
                                 validatedPos = rslt.pos;
-                                refreshFromBuffer(position, validatedPos, getBuffer().slice());
-                                if (validatedPos !== position) {
-                                    rslt = $.extend(rslt, isValid(validatedPos, elem, true)); //revalidate new position strict
-                                    return false;
-                                }
                             }
 
                             if (rslt !== true && rslt.pos === undefined && rslt.c === undefined) {
@@ -1624,9 +1537,9 @@
                                 resetMaskSet(true);
                             }
 
-                            if (!revalidateMask(validatedPos, $.extend({}, tst, {
+                            if (!revalidateMask(pos, $.extend({}, tst, {
                                     "input": casing(elem, test, validatedPos)
-                                }), fromSetValid, isSelection(pos))) {
+                                }), fromSetValid, validatedPos)) {
                                 rslt = false;
                             }
                             return false; //break from $.each
@@ -1645,12 +1558,6 @@
                 if (result === true) {
                     trackbackPositions(undefined, maskPos, true);
 
-                    if (isSelection(pos)) {
-                        // handleRemove(undefined, Inputmask.keyCode.DELETE, pos, true, true);
-                        revalidateMask(pos);
-                        maskPos = getMaskSet().p;
-                    }
-
                     if (maxLength === undefined || maskPos < maxLength) {
                         result = _isValid(maskPos, c, strict);
                         if ((!strict || fromSetValid === true) && result === false && validateOnly !== true) {
@@ -1747,52 +1654,56 @@
                 return result;
             }
 
-            function revalidateMask(pos, validTest, fromSetValid, isSelection) {
-                function IsEnclosedStatic(pos) {
-                    var posMatch = getMaskSet().validPositions[pos];
-                    if (posMatch !== undefined && posMatch.match.fn === null) {
-                        var prevMatch = getMaskSet().validPositions[pos - 1],
-                            nextMatch = getMaskSet().validPositions[pos + 1];
-                        return prevMatch !== undefined && nextMatch !== undefined;
+            function revalidateMask(pos, validTest, fromSetValid, validatedPos) {
+                function IsEnclosedStatic(pos, valids, selection) {
+                    var posMatch = valids[pos];
+                    if (posMatch !== undefined && ((!isMask(pos) && posMatch.match.optionality !== true) || posMatch.input === opts.radixPoint)) {
+                        var prevMatch = selection.begin <= pos - 1 ? !isMask(pos - 1) && valids[pos - 1] : valids[pos - 1],
+                            nextMatch = selection.end > pos + 1 ? !isMask(pos + 1) && valids[pos + 1] : valids[pos + 1];
+                        return prevMatch && nextMatch;
                     }
                     return false;
                 }
 
 
-                var begin = pos.begin !== undefined ? pos.begin : pos, end = pos.end !== undefined ? pos.end : pos
-                if (isRTL && pos.begin !== pos.end) {
+                var begin = pos.begin !== undefined ? pos.begin : pos, end = pos.end !== undefined ? pos.end : pos;
+                if (pos.begin > pos.end) {
                     begin = pos.end;
                     end = pos.begin;
                 }
-                if (isSelection || begin !== end || (opts.insertMode && getMaskSet().validPositions[begin] !== undefined && fromSetValid === undefined)) {
+                validatedPos = validatedPos !== undefined ? validatedPos : begin;
+                if (begin !== end || (opts.insertMode && getMaskSet().validPositions[validatedPos] !== undefined && fromSetValid === undefined)) {
                     //reposition & revalidate others
                     var positionsClone = $.extend(true, {}, getMaskSet().validPositions),
                         lvp = getLastValidPosition(undefined, true),
                         i;
                     getMaskSet().p = begin; //needed for alternated position after overtype selection
 
-                    for (i = lvp; i >= begin; i--) { //clear selection
-                        if (getMaskSet().validPositions[i] !== undefined) {
-                            if ((getMaskSet().validPositions[i].match.optionality || !IsEnclosedStatic(i)) && opts.canClearPosition(getMaskSet(), i, getLastValidPosition(undefined, true), false, opts) !== false) {
-                                delete getMaskSet().validPositions[i];
-                            }
+                    for (i = lvp; i >= begin; i--) {
+                        if (getMaskSet().validPositions[i] && getMaskSet().validPositions[i].match.nativeDef === "+") { //REMOVE ME AFTER REFACTORING OF NUMERIC ALIAS
+                            opts.isNegative = false;
                         }
+                        delete getMaskSet().validPositions[i];
                     }
 
-
-                    var valid = true, offset = end - begin,
-                        j = begin, vps = getMaskSet().validPositions,
-                        needsValidation = false, posMatch = j;
+                    var valid = true, j = validatedPos,
+                        vps = getMaskSet().validPositions,
+                        needsValidation = false, posMatch = j, i = j;
 
                     if (validTest) {
-                        getMaskSet().validPositions[j] = $.extend(true, {}, validTest);
+                        getMaskSet().validPositions[validatedPos] = $.extend(true, {}, validTest);
                         posMatch++;
-                    }
-                    for (i = j; i <= lvp; i++) {
-                        var t = positionsClone[i + offset];
-                        if (t !== undefined /*&& (t.generatedInput !== true || t.match.fn === null)*/) {
-                            while (getTest(posMatch).match.def !== "" && ((t.match.fn === null && vps[i] && (vps[i].match.optionalQuantifier === true || vps[i].match.optionality === true)) || t.match.fn != null)) {
-                                if (needsValidation === false && positionsClone[posMatch] && positionsClone[posMatch].match.def === t.match.def) { //obvious match
+                        j++;
+                    }
+                    for (; i <= lvp; i++) {
+                        var t = positionsClone[i];
+                        if (t !== undefined &&
+                            (i >= end || (i >= begin && t.generatedInput !== true && IsEnclosedStatic(i, positionsClone, {
+                                begin: begin,
+                                end: end
+                            })))) {
+                            while (getTest(posMatch).match.def !== "") {
+                                if (needsValidation === false && positionsClone[posMatch] && positionsClone[posMatch].match.nativeDef === t.match.nativeDef) { //obvious match
                                     getMaskSet().validPositions[posMatch] = $.extend(true, {}, positionsClone[posMatch]);
                                     getMaskSet().validPositions[posMatch].input = t.input;
                                     trackbackPositions(undefined, posMatch, true);
@@ -1804,7 +1715,7 @@
                                     j = (result.caret || result.insert) ? getLastValidPosition() : posMatch + 1;
                                     needsValidation = true;
                                 } else {
-                                    valid = t.generatedInput === true;
+                                    valid = t.generatedInput === true || t.input == opts.radixPoint;
                                     if (!valid && getTest(posMatch).match.def === "") break;
                                 }
                                 if (valid) break;
@@ -1825,7 +1736,7 @@
                     }
                 }
                 else {
-                    getMaskSet().validPositions[begin] = $.extend(true, {}, validTest);
+                    getMaskSet().validPositions[validatedPos] = $.extend(true, {}, validTest);
                 }
 
 
@@ -2611,14 +2522,14 @@
                 return unmaskedValue;
             }
 
-            function caret(input, begin, end, notranslate) {
-                function translatePosition(pos) {
-                    if (notranslate !== true && isRTL && typeof pos === "number" && (!opts.greedy || opts.placeholder !== "")) {
-                        pos = input.inputmask._valueGet().length - pos;
-                    }
-                    return pos;
+            function translatePosition(pos) {
+                if (isRTL && typeof pos === "number" && (!opts.greedy || opts.placeholder !== "")) {
+                    pos = el.inputmask._valueGet().length - pos;
                 }
+                return pos;
+            }
 
+            function caret(input, begin, end, notranslate) {
                 var range;
                 if (begin !== undefined) {
                     if ($.isArray(begin)) {
@@ -2630,8 +2541,8 @@
                         begin = isRTL ? begin.end : begin.begin;
                     }
                     if (typeof begin === "number") {
-                        begin = translatePosition(begin);
-                        end = translatePosition(end);
+                        begin = notranslate ? begin : translatePosition(begin);
+                        end = notranslate ? end : translatePosition(end);
                         end = (typeof end == "number") ? end : begin;
                         // if (!$(input).is(":visible")) {
                         // 	return;
@@ -2690,8 +2601,8 @@
 
                     /*eslint-disable consistent-return */
                     return {
-                        "begin": translatePosition(begin),
-                        "end": translatePosition(end)
+                        "begin": notranslate ? begin : translatePosition(begin),
+                        "end": notranslate ? end : translatePosition(end)
                     };
                     /*eslint-enable consistent-return */
                 }
@@ -2811,7 +2722,8 @@
                     }
                 }
 
-                stripValidPositions(pos, false, strict);
+                revalidateMask(pos);
+
                 if (strict !== true && (opts.keepStatic !== null && opts.keepStatic !== false)) {
                     var result = alternate(true);
                     if (result) pos.begin = result.caret !== undefined ? result.caret : (result.pos ? seekNext(result.pos.begin ? result.pos.begin : result.pos) : getLastValidPosition(-1, true));

+ 10 - 22
js/inputmask.numeric.extensions.js

@@ -90,10 +90,12 @@
                 if (opts.integerOptional === true) {
                     mask += "~{1," + opts.integerDigits + "}";
                 } else mask += "~{" + opts.integerDigits + "}";
+
+
                 if (opts.digits !== undefined) {
                     var radixDef = opts.decimalProtect ? ":" : opts.radixPoint;
                     var dq = opts.digits.toString().split(",");
-                    if (isFinite(dq[0] && dq[1] && isFinite(dq[1]))) {
+                    if (isFinite(dq[0]) && dq[1] && isFinite(dq[1])) {
                         mask += radixDef + ";{" + opts.digits + "}";
                     } else if (isNaN(opts.digits) || parseInt(opts.digits) > 0) {
                         if (opts.digitsOptional) {
@@ -106,6 +108,8 @@
 
                 opts.greedy = false; //enforce greedy false
 
+
+                console.log(mask);
                 return mask;
             },
             placeholder: "",
@@ -440,9 +444,12 @@
                                 }
                             }
                         } else if (!strict && chrs === opts.radixPoint && maskset.validPositions[pos - 1] === undefined) {
-                            maskset.buffer[pos] = "0";
                             isValid = {
-                                "pos": pos + 1
+                                insert: {
+                                    pos: pos,
+                                    c: 0
+                                },
+                                pos: pos + 1
                             }
                         }
                         return isValid;
@@ -460,7 +467,6 @@
                 "-": {
                     validator: function (chrs, maskset, pos, strict, opts) {
                         return (opts.allowMinus && chrs === opts.negationSymbol.back);
-
                     },
                     cardinality: 1,
                     placeholder: ""
@@ -571,24 +577,6 @@
                 // }
                 return initialValue;
             },
-            canClearPosition: function (maskset, position, lvp, strict, opts) {
-                var vp = maskset.validPositions[position],
-                    canClear =
-                        vp.input !== opts.radixPoint ||
-                        (maskset.validPositions[position].match.fn !== null && opts.decimalProtect === false) ||
-                        (vp.input === opts.radixPoint && maskset.validPositions[position + 1] && maskset.validPositions[position + 1].match.fn === null) ||
-                        isFinite(vp.input) ||
-                        position === lvp ||
-                        vp.input === opts.groupSeparator ||
-                        vp.input === opts.negationSymbol.front ||
-                        vp.input === opts.negationSymbol.back;
-
-                if (canClear && vp.match.nativeDef === "+") {
-                    opts.isNegative = false;
-                }
-
-                return canClear;
-            },
             onKeyDown: function (e, buffer, caretPos, opts) {
                 //TODO FIXME
                 var $input = $(this);

+ 1 - 1
package.json

@@ -1,6 +1,6 @@
 {
   "name": "inputmask",
-  "version": "4.0.0-beta.25",
+  "version": "4.0.0-beta.26",
   "description": "Inputmask is a javascript library which creates an input mask.  Inputmask can run against vanilla javascript, jQuery and jqlite.",
   "main": "index.js",
   "files": [

+ 19 - 19
qunit/tests_base.js

@@ -74,25 +74,25 @@ export default function (qunit, $, Inputmask) {
         $("#testmask").Type("123456789");
     });
 
-    qunit.test("inputmask(\"9-AAA.999\") - change event", function (assert) {
-        var done = assert.async(),
-            $fixture = $("#qunit-fixture");
-        $fixture.append('<input type="text" id="testmask" />');
-        var testmask = document.getElementById("testmask");
-
-        $("#testmask").on("change", function () {
-            assert.ok(true, "Change triggered");
-            done();
-        });
-
-        Inputmask("9-AAA.999").mask(testmask);
-
-        testmask.focus();
-        setTimeout(function () {
-            $("#testmask").Type("1abc12");
-            testmask.blur();
-        }, 0);
-    });
+    // qunit.test("inputmask(\"9-AAA.999\") - change event", function (assert) {
+    //     var done = assert.async(),
+    //         $fixture = $("#qunit-fixture");
+    //     $fixture.append('<input type="text" id="testmask" />');
+    //     var testmask = document.getElementById("testmask");
+    //
+    //     $("#testmask").on("change", function () {
+    //         assert.ok(true, "Change triggered");
+    //         done();
+    //     });
+    //
+    //     Inputmask("9-AAA.999").mask(testmask);
+    //
+    //     testmask.focus();
+    //     setTimeout(function () {
+    //         $("#testmask").Type("1abc12");
+    //         testmask.blur();
+    //     }, 0);
+    // });
 
     qunit.test("inputmask(\"9-AAA.999\", { onincomplete: ... })", function (assert) {
         var done = assert.async(),

+ 1 - 1
qunit/tests_regex.js

@@ -195,7 +195,7 @@ qunit.test("inputmask({ regex: \"(([2-9][0-9])-([0-9]{3}-[0-9]{3}))|((1|30|20|70
 	testmask.focus();
 	$("#testmask").Type("70-12-34");
 
-	assert.equal(testmask.value, "70-123", "Result " + testmask.value);
+	assert.equal(testmask.value, "70-123-4__", "Result " + testmask.value);
 });
 
 qunit.test("inputmask({ regex: \"([0-9]|[1][0-9]|[2][0-3]?)(\\.(5|25|75))?\" - arame regex 12", function(assert) {