Browse Source

Improve Inputfallback (android)

Robin Herbots 8 years ago
parent
commit
0dce7c1ac1
48 changed files with 5680 additions and 114 deletions
  1. 1 1
      bower.json
  2. 1 1
      component.json
  3. 1 1
      composer.json
  4. 1 1
      dist/inputmask/bindings/inputmask.binding.js
  5. 1 1
      dist/inputmask/dependencyLibs/inputmask.dependencyLib.jqlite.js
  6. 1 1
      dist/inputmask/dependencyLibs/inputmask.dependencyLib.jquery.js
  7. 1 1
      dist/inputmask/dependencyLibs/inputmask.dependencyLib.js
  8. 1 1
      dist/inputmask/global/document.js
  9. 1 1
      dist/inputmask/global/window.js
  10. 1 1
      dist/inputmask/inputmask.date.extensions.js
  11. 1 1
      dist/inputmask/inputmask.extensions.js
  12. 35 20
      dist/inputmask/inputmask.js
  13. 1 1
      dist/inputmask/inputmask.numeric.extensions.js
  14. 1 1
      dist/inputmask/inputmask.phone.extensions.js
  15. 1 1
      dist/inputmask/jquery.inputmask.js
  16. 1 1
      dist/inputmask/phone-codes/phone-be.js
  17. 1 1
      dist/inputmask/phone-codes/phone-nl.js
  18. 1 1
      dist/inputmask/phone-codes/phone-ru.js
  19. 1 1
      dist/inputmask/phone-codes/phone-uk.js
  20. 1 1
      dist/inputmask/phone-codes/phone.js
  21. 35 20
      dist/jquery.inputmask.bundle.js
  22. 1 1
      dist/min/inputmask/bindings/inputmask.binding.min.js
  23. 1 1
      dist/min/inputmask/dependencyLibs/inputmask.dependencyLib.jqlite.min.js
  24. 1 1
      dist/min/inputmask/dependencyLibs/inputmask.dependencyLib.jquery.min.js
  25. 1 1
      dist/min/inputmask/dependencyLibs/inputmask.dependencyLib.min.js
  26. 1 1
      dist/min/inputmask/global/document.min.js
  27. 1 1
      dist/min/inputmask/global/window.min.js
  28. 1 1
      dist/min/inputmask/inputmask.date.extensions.min.js
  29. 1 1
      dist/min/inputmask/inputmask.extensions.min.js
  30. 3 3
      dist/min/inputmask/inputmask.min.js
  31. 1 1
      dist/min/inputmask/inputmask.numeric.extensions.min.js
  32. 1 1
      dist/min/inputmask/inputmask.phone.extensions.min.js
  33. 1 1
      dist/min/inputmask/jquery.inputmask.min.js
  34. 1 1
      dist/min/inputmask/phone-codes/phone-be.min.js
  35. 1 1
      dist/min/inputmask/phone-codes/phone-nl.min.js
  36. 1 1
      dist/min/inputmask/phone-codes/phone-ru.min.js
  37. 1 1
      dist/min/inputmask/phone-codes/phone-uk.min.js
  38. 1 1
      dist/min/inputmask/phone-codes/phone.min.js
  39. 4 4
      dist/min/jquery.inputmask.bundle.min.js
  40. 54 19
      js/inputmask.js
  41. 5485 0
      package-lock.json
  42. 2 3
      package.json
  43. 2 1
      qunit/index.js
  44. 9 4
      qunit/simulator.js
  45. 1 1
      qunit/tests_base.js
  46. 13 0
      qunit/tests_regex.js
  47. 1 2
      qunit/webpack.config.js
  48. 1 2
      webpack.config.js

+ 1 - 1
bower.json

@@ -1,6 +1,6 @@
 {
   "name": "inputmask",
-  "version": "4.0.1-0",
+  "version": "4.0.1-1",
   "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.1-0",
+	"version": "4.0.1-1",
 	"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.1-0",
+  "version": "4.0.1-1",
   "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 - 2017 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 4.0.1-0
+* Version: 4.0.1-1
 */
 
 !function(factory) {

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

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

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

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

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

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

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

@@ -3,7 +3,7 @@
 * https://github.com/RobinHerbots/Inputmask
 * Copyright (c) 2010 - 2017 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 4.0.1-0
+* Version: 4.0.1-1
 */
 
 "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 - 2017 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 4.0.1-0
+* Version: 4.0.1-1
 */
 
 "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 - 2017 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 4.0.1-0
+* Version: 4.0.1-1
 */
 
 !function(factory) {

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

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

+ 35 - 20
dist/inputmask/inputmask.js

@@ -3,7 +3,7 @@
 * https://github.com/RobinHerbots/Inputmask
 * Copyright (c) 2010 - 2017 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 4.0.1-0
+* Version: 4.0.1-1
 */
 
 !function(factory) {
@@ -414,7 +414,7 @@
             var result = !0, positionsClone = $.extend(!0, {}, getMaskSet().validPositions);
             if ($.isFunction(opts.preValidation) && !strict && !0 !== fromSetValid && (result = opts.preValidation(getBuffer(), maskPos, c, isSelection(pos), opts)), 
             !0 === result) {
-                if (fillMissingNonMask(maskPos), isSelection(pos) && (handleRemove(undefined, Inputmask.keyCode.DELETE, pos, !0), 
+                if (fillMissingNonMask(maskPos), isSelection(pos) && (handleRemove(undefined, Inputmask.keyCode.DELETE, pos, !0, !0), 
                 maskPos = getMaskSet().p), maskPos < getMaskSet().maskLength && (maxLength === undefined || maskPos < maxLength) && (result = _isValid(maskPos, c, strict), 
                 (!strict || !0 === fromSetValid) && !1 === result)) {
                     var currentPosValid = getMaskSet().validPositions[maskPos];
@@ -908,26 +908,41 @@
                 var input = this, inputValue = input.inputmask._valueGet();
                 if (getBuffer().join("") !== inputValue) {
                     var caretPos = caret(input);
-                    if ("." === inputValue.charAt(caretPos.begin - 1) && "" !== opts.radixPoint && (inputValue = inputValue.split(""), 
-                    inputValue[caretPos.begin - 1] = opts.radixPoint.charAt(0), inputValue = inputValue.join("")), 
-                    inputValue.charAt(caretPos.begin - 1) === opts.radixPoint && inputValue.length > getBuffer().length) {
-                        var keypress = new $.Event("keypress");
-                        return keypress.which = opts.radixPoint.charCodeAt(0), EventHandlers.keypressEvent.call(input, keypress, !0, !0, !1, caretPos.begin), 
-                        !1;
-                    }
-                    if (inputValue = inputValue.replace(new RegExp("(" + Inputmask.escapeRegex(getBufferTemplate().join("")) + ")*"), ""), 
-                    iemobile) {
-                        var inputChar = inputValue.replace(getBuffer().join(""), "");
-                        if (1 === inputChar.length) {
+                    if (!1 === function(input, inputValue, caretPos) {
+                        if ("." === inputValue.charAt(caretPos.begin - 1) && "" !== opts.radixPoint && (inputValue = inputValue.split(""), 
+                        inputValue[caretPos.begin - 1] = opts.radixPoint.charAt(0), inputValue = inputValue.join("")), 
+                        inputValue.charAt(caretPos.begin - 1) === opts.radixPoint && inputValue.length > getBuffer().length) {
                             var keypress = new $.Event("keypress");
-                            return keypress.which = inputChar.charCodeAt(0), EventHandlers.keypressEvent.call(input, keypress, !0, !0, !1, getMaskSet().validPositions[caretPos.begin - 1] ? caretPos.begin : caretPos.begin - 1), 
+                            return keypress.which = opts.radixPoint.charCodeAt(0), EventHandlers.keypressEvent.call(input, keypress, !0, !0, !1, caretPos.begin), 
                             !1;
                         }
+                    }(input, inputValue, caretPos)) return !1;
+                    if (inputValue = inputValue.replace(new RegExp("(" + Inputmask.escapeRegex(getBufferTemplate().join("")) + ")*"), ""), 
+                    !1 === function(input, inputValue, caretPos) {
+                        if (iemobile) {
+                            var inputChar = inputValue.replace(getBuffer().join(""), "");
+                            if (1 === inputChar.length) {
+                                var keypress = new $.Event("keypress");
+                                return keypress.which = inputChar.charCodeAt(0), EventHandlers.keypressEvent.call(input, keypress, !0, !0, !1, getMaskSet().validPositions[caretPos.begin - 1] ? caretPos.begin : caretPos.begin - 1), 
+                                !1;
+                            }
+                        }
+                    }(input, inputValue, caretPos)) return !1;
+                    caretPos.begin > inputValue.length && (caret(input, inputValue.length), caretPos = caret(input));
+                    var buffer = getBuffer().join(""), frontPart = inputValue.substr(0, caretPos.begin), backPart = inputValue.substr(caretPos.begin), frontBufferPart = buffer.substr(0, caretPos.begin), backBufferPart = buffer.substr(caretPos.begin), selection = {
+                        begin: frontPart.length
+                    }, endOffset = 0;
+                    if (frontPart[frontPart.length - 1] !== frontBufferPart[frontBufferPart.length - 1] && (selection.begin--, 
+                    endOffset++), backPart.length > backBufferPart.length) selection.end = selection.begin; else {
+                        var selectedPart = backBufferPart.replace(new RegExp(Inputmask.escapeRegex(backPart) + "$"), "");
+                        selection.end = selection.begin + selectedPart.length + endOffset;
                     }
-                    if (caretPos.begin > inputValue.length && (caret(input, inputValue.length), caretPos = caret(input)), 
-                    getBuffer().length - inputValue.length != 1 || inputValue.charAt(caretPos.begin) === getBuffer()[caretPos.begin] || inputValue.charAt(caretPos.begin + 1) === getBuffer()[caretPos.begin] || isMask(caretPos.begin)) {
-                        var stickyParts = [], bufferTemplate = getBufferTemplate().join("");
-                        for (stickyParts.push(inputValue.substr(0, caretPos.begin)), stickyParts.push(inputValue.substr(caretPos.begin)); null === inputValue.match(Inputmask.escapeRegex(bufferTemplate) + "$"); ) bufferTemplate = bufferTemplate.slice(1);
+                    if (selection.begin != selection.end || isMask(selection.begin) || (selection.end = caretPos.end), 
+                    "" !== backPart && selection.begin < selection.end) writeBuffer(input, getBuffer(), selection), 
+                    frontPart.charCodeAt(frontPart.length - 1) !== frontBufferPart.charCodeAt(frontBufferPart.length - 1) ? (e.which = frontPart.charCodeAt(frontPart.length - 1), 
+                    EventHandlers.keypressEvent.call(input, e)) : (selection.begin == selection.end - 1 && caret(input, seekPrevious(selection.begin + 1), selection.end), 
+                    e.keyCode = Inputmask.keyCode.DELETE, EventHandlers.keydownEvent.call(input, e)); else {
+                        for (var bufferTemplate = getBufferTemplate().join(""); null === inputValue.match(Inputmask.escapeRegex(bufferTemplate) + "$"); ) bufferTemplate = bufferTemplate.slice(1);
                         inputValue = inputValue.replace(bufferTemplate, ""), $.isFunction(opts.onBeforeMask) && (inputValue = opts.onBeforeMask(inputValue, opts) || inputValue), 
                         checkVal(input, !0, !1, inputValue.split(""), e), function(input, frontPart, backPart) {
                             var targetPos = caret(input).begin, currentValue = input.inputmask._valueGet(), pos = currentValue.indexOf(frontPart), currentPos = targetPos;
@@ -940,8 +955,8 @@
                             android && setTimeout(function() {
                                 caret(input, targetPos);
                             }, 0));
-                        }(input, stickyParts[0], stickyParts[1]), !0 === isComplete(getBuffer()) && $(input).trigger("complete");
-                    } else e.keyCode = Inputmask.keyCode.BACKSPACE, EventHandlers.keydownEvent.call(input, e);
+                        }(input, frontPart, backPart), !0 === isComplete(getBuffer()) && $(input).trigger("complete");
+                    }
                     e.preventDefault();
                 }
             },

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

+ 35 - 20
dist/jquery.inputmask.bundle.js

@@ -3,7 +3,7 @@
 * https://github.com/RobinHerbots/Inputmask
 * Copyright (c) 2010 - 2017 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 4.0.1-0
+* Version: 4.0.1-1
 */
 
 !function(modules) {
@@ -462,7 +462,7 @@
                 var result = !0, positionsClone = $.extend(!0, {}, getMaskSet().validPositions);
                 if ($.isFunction(opts.preValidation) && !strict && !0 !== fromSetValid && (result = opts.preValidation(getBuffer(), maskPos, c, isSelection(pos), opts)), 
                 !0 === result) {
-                    if (fillMissingNonMask(maskPos), isSelection(pos) && (handleRemove(undefined, Inputmask.keyCode.DELETE, pos, !0), 
+                    if (fillMissingNonMask(maskPos), isSelection(pos) && (handleRemove(undefined, Inputmask.keyCode.DELETE, pos, !0, !0), 
                     maskPos = getMaskSet().p), maskPos < getMaskSet().maskLength && (maxLength === undefined || maskPos < maxLength) && (result = _isValid(maskPos, c, strict), 
                     (!strict || !0 === fromSetValid) && !1 === result)) {
                         var currentPosValid = getMaskSet().validPositions[maskPos];
@@ -956,26 +956,41 @@
                     var input = this, inputValue = input.inputmask._valueGet();
                     if (getBuffer().join("") !== inputValue) {
                         var caretPos = caret(input);
-                        if ("." === inputValue.charAt(caretPos.begin - 1) && "" !== opts.radixPoint && (inputValue = inputValue.split(""), 
-                        inputValue[caretPos.begin - 1] = opts.radixPoint.charAt(0), inputValue = inputValue.join("")), 
-                        inputValue.charAt(caretPos.begin - 1) === opts.radixPoint && inputValue.length > getBuffer().length) {
-                            var keypress = new $.Event("keypress");
-                            return keypress.which = opts.radixPoint.charCodeAt(0), EventHandlers.keypressEvent.call(input, keypress, !0, !0, !1, caretPos.begin), 
-                            !1;
-                        }
-                        if (inputValue = inputValue.replace(new RegExp("(" + Inputmask.escapeRegex(getBufferTemplate().join("")) + ")*"), ""), 
-                        iemobile) {
-                            var inputChar = inputValue.replace(getBuffer().join(""), "");
-                            if (1 === inputChar.length) {
+                        if (!1 === function(input, inputValue, caretPos) {
+                            if ("." === inputValue.charAt(caretPos.begin - 1) && "" !== opts.radixPoint && (inputValue = inputValue.split(""), 
+                            inputValue[caretPos.begin - 1] = opts.radixPoint.charAt(0), inputValue = inputValue.join("")), 
+                            inputValue.charAt(caretPos.begin - 1) === opts.radixPoint && inputValue.length > getBuffer().length) {
                                 var keypress = new $.Event("keypress");
-                                return keypress.which = inputChar.charCodeAt(0), EventHandlers.keypressEvent.call(input, keypress, !0, !0, !1, getMaskSet().validPositions[caretPos.begin - 1] ? caretPos.begin : caretPos.begin - 1), 
+                                return keypress.which = opts.radixPoint.charCodeAt(0), EventHandlers.keypressEvent.call(input, keypress, !0, !0, !1, caretPos.begin), 
                                 !1;
                             }
+                        }(input, inputValue, caretPos)) return !1;
+                        if (inputValue = inputValue.replace(new RegExp("(" + Inputmask.escapeRegex(getBufferTemplate().join("")) + ")*"), ""), 
+                        !1 === function(input, inputValue, caretPos) {
+                            if (iemobile) {
+                                var inputChar = inputValue.replace(getBuffer().join(""), "");
+                                if (1 === inputChar.length) {
+                                    var keypress = new $.Event("keypress");
+                                    return keypress.which = inputChar.charCodeAt(0), EventHandlers.keypressEvent.call(input, keypress, !0, !0, !1, getMaskSet().validPositions[caretPos.begin - 1] ? caretPos.begin : caretPos.begin - 1), 
+                                    !1;
+                                }
+                            }
+                        }(input, inputValue, caretPos)) return !1;
+                        caretPos.begin > inputValue.length && (caret(input, inputValue.length), caretPos = caret(input));
+                        var buffer = getBuffer().join(""), frontPart = inputValue.substr(0, caretPos.begin), backPart = inputValue.substr(caretPos.begin), frontBufferPart = buffer.substr(0, caretPos.begin), backBufferPart = buffer.substr(caretPos.begin), selection = {
+                            begin: frontPart.length
+                        }, endOffset = 0;
+                        if (frontPart[frontPart.length - 1] !== frontBufferPart[frontBufferPart.length - 1] && (selection.begin--, 
+                        endOffset++), backPart.length > backBufferPart.length) selection.end = selection.begin; else {
+                            var selectedPart = backBufferPart.replace(new RegExp(Inputmask.escapeRegex(backPart) + "$"), "");
+                            selection.end = selection.begin + selectedPart.length + endOffset;
                         }
-                        if (caretPos.begin > inputValue.length && (caret(input, inputValue.length), caretPos = caret(input)), 
-                        getBuffer().length - inputValue.length != 1 || inputValue.charAt(caretPos.begin) === getBuffer()[caretPos.begin] || inputValue.charAt(caretPos.begin + 1) === getBuffer()[caretPos.begin] || isMask(caretPos.begin)) {
-                            var stickyParts = [], bufferTemplate = getBufferTemplate().join("");
-                            for (stickyParts.push(inputValue.substr(0, caretPos.begin)), stickyParts.push(inputValue.substr(caretPos.begin)); null === inputValue.match(Inputmask.escapeRegex(bufferTemplate) + "$"); ) bufferTemplate = bufferTemplate.slice(1);
+                        if (selection.begin != selection.end || isMask(selection.begin) || (selection.end = caretPos.end), 
+                        "" !== backPart && selection.begin < selection.end) writeBuffer(input, getBuffer(), selection), 
+                        frontPart.charCodeAt(frontPart.length - 1) !== frontBufferPart.charCodeAt(frontBufferPart.length - 1) ? (e.which = frontPart.charCodeAt(frontPart.length - 1), 
+                        EventHandlers.keypressEvent.call(input, e)) : (selection.begin == selection.end - 1 && caret(input, seekPrevious(selection.begin + 1), selection.end), 
+                        e.keyCode = Inputmask.keyCode.DELETE, EventHandlers.keydownEvent.call(input, e)); else {
+                            for (var bufferTemplate = getBufferTemplate().join(""); null === inputValue.match(Inputmask.escapeRegex(bufferTemplate) + "$"); ) bufferTemplate = bufferTemplate.slice(1);
                             inputValue = inputValue.replace(bufferTemplate, ""), $.isFunction(opts.onBeforeMask) && (inputValue = opts.onBeforeMask(inputValue, opts) || inputValue), 
                             checkVal(input, !0, !1, inputValue.split(""), e), function(input, frontPart, backPart) {
                                 var targetPos = caret(input).begin, currentValue = input.inputmask._valueGet(), pos = currentValue.indexOf(frontPart), currentPos = targetPos;
@@ -988,8 +1003,8 @@
                                 android && setTimeout(function() {
                                     caret(input, targetPos);
                                 }, 0));
-                            }(input, stickyParts[0], stickyParts[1]), !0 === isComplete(getBuffer()) && $(input).trigger("complete");
-                        } else e.keyCode = Inputmask.keyCode.BACKSPACE, EventHandlers.keydownEvent.call(input, e);
+                            }(input, frontPart, backPart), !0 === isComplete(getBuffer()) && $(input).trigger("complete");
+                        }
                         e.preventDefault();
                     }
                 },

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 - 2017 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 4.0.1-0
+* Version: 4.0.1-1
 */
 
 !function(a){"function"==typeof define&&define.amd?define(["jquery"],a):"object"==typeof exports?module.exports=a(require("jquery")):window.dependencyLib=a(jQuery)}(function(a){return a});

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 - 2017 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 4.0.1-0
+* Version: 4.0.1-1
 */
 
 "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 - 2017 Robin Herbots
 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)
-* Version: 4.0.1-0
+* Version: 4.0.1-1
 */
 
 "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
+ 3 - 3
dist/min/inputmask/inputmask.min.js


File diff suppressed because it is too large
+ 1 - 1
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-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
+ 4 - 4
dist/min/jquery.inputmask.bundle.min.js


+ 54 - 19
js/inputmask.js

@@ -1762,7 +1762,7 @@
                     fillMissingNonMask(maskPos);
 
                     if (isSelection(pos)) {
-                        handleRemove(undefined, Inputmask.keyCode.DELETE, pos, true);
+                        handleRemove(undefined, Inputmask.keyCode.DELETE, pos, true, true);
                         maskPos = getMaskSet().p;
                     }
 
@@ -2544,11 +2544,7 @@
                         }
                     }
 
-                    var input = this,
-                        inputValue = input.inputmask._valueGet();
-
-                    if (getBuffer().join("") !== inputValue) {
-                        var caretPos = caret(input);
+                    function radixPointHandler(input, inputValue, caretPos) {
                         //radixpoint tweak
                         if (inputValue.charAt(caretPos.begin - 1) === "." && opts.radixPoint !== "") {
                             inputValue = inputValue.split("");
@@ -2563,9 +2559,9 @@
                             return false;
 
                         }
+                    }
 
-                        inputValue = inputValue.replace(new RegExp("(" + Inputmask.escapeRegex(getBufferTemplate().join("")) + ")*"), "");
-
+                    function ieMobileHandler(input, inputValue, caretPos) {
                         if (iemobile) { //iemobile just set the character at the end althought the caret position is correctly set
                             var inputChar = inputValue.replace(getBuffer().join(""), "");
                             if (inputChar.length === 1) {
@@ -2575,34 +2571,72 @@
                                 return false;
                             }
                         }
+                    }
+
+                    var input = this,
+                        inputValue = input.inputmask._valueGet();
+
+                    if (getBuffer().join("") !== inputValue) {
+                        var caretPos = caret(input);
+                        if (radixPointHandler(input, inputValue, caretPos) === false) return false;
+                        inputValue = inputValue.replace(new RegExp("(" + Inputmask.escapeRegex(getBufferTemplate().join("")) + ")*"), "");
+                        if (ieMobileHandler(input, inputValue, caretPos) === false) return false;
 
                         if (caretPos.begin > inputValue.length) {
                             caret(input, inputValue.length);
                             caretPos = caret(input);
                         }
-                        //detect & treat possible backspace before static
-                        if ((getBuffer().length - inputValue.length) === 1 && inputValue.charAt(caretPos.begin) !== getBuffer()[caretPos.begin] && inputValue.charAt(caretPos.begin + 1) !== getBuffer()[caretPos.begin] && !isMask(caretPos.begin)) {
-                            e.keyCode = Inputmask.keyCode.BACKSPACE;
-                            EventHandlers.keydownEvent.call(input, e);
+
+                        var buffer = getBuffer().join(""),
+                            frontPart = inputValue.substr(0, caretPos.begin),
+                            backPart = inputValue.substr(caretPos.begin),
+                            frontBufferPart = buffer.substr(0, caretPos.begin),
+                            backBufferPart = buffer.substr(caretPos.begin);
+
+                        //check if thare was a selection
+                        var selection = {begin: frontPart.length}, endOffset = 0;
+                        if (frontPart[frontPart.length - 1] !== frontBufferPart[frontBufferPart.length - 1]) {
+                            selection.begin--;
+                            endOffset++;
+                        }
+                        if (backPart.length > backBufferPart.length) {
+                            selection.end = selection.begin;
                         } else {
-                            var stickyParts = [],
-                                bufferTemplate = getBufferTemplate().join("");
-                            stickyParts.push(inputValue.substr(0, caretPos.begin));
-                            stickyParts.push(inputValue.substr(caretPos.begin));
+                            var selectedPart = backBufferPart.replace(new RegExp(Inputmask.escapeRegex(backPart) + "$"), "");
+                            selection.end = selection.begin + selectedPart.length + endOffset;
+                        }
+
+                        if (selection.begin == selection.end && !isMask(selection.begin)) {
+                            selection.end = caretPos.end;
+                        }
 
+                        //is selection
+                        if (backPart !== "" && selection.begin < selection.end) {
+                            writeBuffer(input, getBuffer(), selection);
+                            if (frontPart.charCodeAt(frontPart.length - 1) !== frontBufferPart.charCodeAt(frontBufferPart.length - 1)) {
+                                e.which = frontPart.charCodeAt(frontPart.length - 1);
+                                EventHandlers.keypressEvent.call(input, e);
+                            } else {
+                                if (selection.begin == selection.end - 1)
+                                    caret(input, seekPrevious(selection.begin + 1), selection.end);
+                                e.keyCode = Inputmask.keyCode.DELETE;
+                                EventHandlers.keydownEvent.call(input, e);
+                            }
+                        } else {
+                            var bufferTemplate = getBufferTemplate().join("");
                             while (inputValue.match(Inputmask.escapeRegex(bufferTemplate) + "$") === null) {
                                 bufferTemplate = bufferTemplate.slice(1);
                             }
                             inputValue = inputValue.replace(bufferTemplate, "");
                             if ($.isFunction(opts.onBeforeMask)) inputValue = opts.onBeforeMask(inputValue, opts) || inputValue;
-
                             checkVal(input, true, false, inputValue.split(""), e);
-                            repositionCaret(input, stickyParts[0], stickyParts[1]);
+                            repositionCaret(input, frontPart, backPart);
 
                             if (isComplete(getBuffer()) === true) {
                                 $(input).trigger("complete");
                             }
                         }
+
                         e.preventDefault();
                     }
                 },
@@ -2709,8 +2743,9 @@
                                                 tt = getTestTemplate(lastPosition, lvp ? lvp.match.locator : undefined, lvp);
                                             if ((placeholder !== "" && getBuffer()[lastPosition] !== placeholder && tt.match.optionalQuantifier !== true) || (!isMask(lastPosition) && tt.match.def === placeholder)) {
                                                 var newPos = seekNext(lastPosition);
-                                                if (clickPosition >= newPos)
+                                                if (clickPosition >= newPos) {
                                                     lastPosition = newPos;
+                                                }
                                             }
                                             caret(input, lastPosition);
                                         }

File diff suppressed because it is too large
+ 5485 - 0
package-lock.json


+ 2 - 3
package.json

@@ -1,6 +1,6 @@
 {
   "name": "inputmask",
-  "version": "4.0.1-0",
+  "version": "4.0.1-1",
   "description": "Inputmask is a javascript library which creates an input mask.  Inputmask can run against vanilla javascript, jQuery and jqlite.",
   "main": "index.js",
   "files": [
@@ -37,8 +37,7 @@
   "devDependencies": {
     "babel-core": "^6.25.0",
     "babel-loader": "^6.2.4",
-    "babel-preset-es2015": "^6.24.1",
-    "babel-preset-stage-0": "^6.24.1",
+    "babel-preset-env": "^1.5.2",
     "caniuse-db": "^1.0.30000680",
     "css-loader": "^0.28.4",
     "grunt": "^1.0.1",

+ 2 - 1
qunit/index.js

@@ -28,7 +28,8 @@ import simulator from "./simulator.js";
 // Inputmask.extendDefaults({
 //    inputEventOnly: true
 // });
-// window.Inputmask = Inputmask; //inject globally for the simulator to detect inputeventonly
+
+window.Inputmask = Inputmask; //inject globally for the simulator to detect inputeventonly
 
 import tests_alternations from "./tests_alternations";
 import tests_attributes from "./tests_attributes";

+ 9 - 4
qunit/simulator.js

@@ -62,6 +62,8 @@ export default function ($, Inputmask) {
     };
     $.fn = $.fn || $.prototype;
     $.fn.SendKey = function (keyCode, modifier) {
+        var elem = this.nodeName ? this : this[0];
+
         function trigger(elem, evnt) {
             elem.focus();
             if ($ === window.jQuery) {
@@ -95,9 +97,9 @@ export default function ($, Inputmask) {
                     break;
                 }
             default:
-                if (window.Inputmask && window.Inputmask.prototype.defaults.inputEventOnly === true) {
+                if ((window.Inputmask && window.Inputmask.prototype.defaults.inputEventOnly === true) ||
+                    (elem.inputmask && elem.inputmask.opts.inputEventOnly === true)) {
                     var input = new $.Event("input"),
-                        elem = this.nodeName ? this : this[0],
                         currentValue = elem.inputmask.__valueGet ? elem.inputmask.__valueGet.call(elem) : elem.value,
                         caretPos = $.caret(elem);
 
@@ -110,10 +112,13 @@ export default function ($, Inputmask) {
 
                     switch (keyCode) {
                         case Inputmask.keyCode.BACKSPACE:
-                            newValue = front.substr(0, front.length - (caretPos.end - caretPos.begin ) - 1) + back;
+                            if (caretPos.begin === caretPos.end)
+                                front = front.substr(0, front.length - 1)
+                            newValue = front + back;
                             break;
                         case Inputmask.keyCode.DELETE :
-                            back = back.substr(1);
+                            if (caretPos.begin === caretPos.end)
+                                back = back.substr(1);
                             newValue = front + back;
                             break;
                         default:

+ 1 - 1
qunit/tests_base.js

@@ -181,7 +181,7 @@ export default function (qunit, $, Inputmask) {
 
 		$("#testmask").Type("123456789");
 		$.caret(testmask, 3, 7);
-		$("#testmask").SendKey(Inputmask.keyCode.DELETE);
+		$("#testmask").SendKey(Inputmask.keyCode.BACKSPACE);
 
 		assert.equal(testmask.value, "123.789.___", "Result " + testmask.value);
 	});

+ 13 - 0
qunit/tests_regex.js

@@ -314,4 +314,17 @@ qunit.test("inputmask({regex: \"[а-яА-Я\\s]*\"}) - type space - SilentImp",
 	assert.equal(testmask.value, " ", "Result " + testmask.value);
 });
 
+    qunit.test("inputmask({regex: \"\\+7 \\(\d{3}\\) \d{3} \d{4}\"}) - hxss", function(assert) {
+        var $fixture = $("#qunit-fixture");
+        $fixture.append('<input type="text" id="testmask" />');
+        var testmask = document.getElementById("testmask");
+        Inputmask({
+            regex: "\\+7 \\(\d{3}\\) \d{3} \d{4}"
+        }).mask(testmask);
+
+        testmask.focus();
+
+        assert.equal(testmask.inputmask.__valueGet.call(testmask), "+_ (___) ___ ____", "Result " + testmask.inputmask.__valueGet.call(testmask));
+    });
+
 };

+ 1 - 2
qunit/webpack.config.js

@@ -19,8 +19,7 @@ const rules = {
         exclude: /(node_modules)/,
         options: {
             presets: [
-                'es2015',
-                'stage-0',
+                'env'
             ],
             passPerPreset: true,
         },

+ 1 - 2
webpack.config.js

@@ -19,8 +19,7 @@ const rules = {
         exclude: /(node_modules)/,
         options: {
             presets: [
-                'es2015',
-                'stage-0',
+                'env'
             ],
             passPerPreset: true,
         },