Browse Source

add context cut + ctrl-x + old fallback if not supported #659

Robin Herbots 11 years ago
parent
commit
2fb06f36a7

+ 3 - 0
README.md

@@ -25,6 +25,7 @@ Highlights:
 - dynamic-mask support
 - dynamic-mask support
 - preprocessing-mask support
 - preprocessing-mask support
 - value formatting / validating without input element
 - value formatting / validating without input element
+- AMD support
 
 
 Demo page see http://robinherbots.github.io/jquery.inputmask
 Demo page see http://robinherbots.github.io/jquery.inputmask
 
 
@@ -35,6 +36,8 @@ Demo page see http://robinherbots.github.io/jquery.inputmask
 
 
 Include the js-files which you can find in the dist-folder. You have the bundled file which contains the main plugin code and also all extensions (date, numerics, other) or if you prefer to only include some parts, use the separate js-files in the dist/min folder.
 Include the js-files which you can find in the dist-folder. You have the bundled file which contains the main plugin code and also all extensions (date, numerics, other) or if you prefer to only include some parts, use the separate js-files in the dist/min folder.
 
 
+If you use a module loader like requireJS, use the js-files in dist/inputmask
+
 The minimum to include is the jquery.inputmask.js
 The minimum to include is the jquery.inputmask.js
 
 
 ```html
 ```html

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

@@ -721,7 +721,7 @@
         function keydownEvent(e) {
         function keydownEvent(e) {
             skipKeyPressEvent = !1;
             skipKeyPressEvent = !1;
             var input = this, $input = $(input), k = e.keyCode, pos = caret(input);
             var input = this, $input = $(input), k = e.keyCode, pos = caret(input);
-            k == $.inputmask.keyCode.BACKSPACE || k == $.inputmask.keyCode.DELETE || iphone && 127 == k || e.ctrlKey && 88 == k ? (e.preventDefault(), 
+            k == $.inputmask.keyCode.BACKSPACE || k == $.inputmask.keyCode.DELETE || iphone && 127 == k || e.ctrlKey && 88 == k && !isInputEventSupported("cut") ? (e.preventDefault(), 
             88 == k && (valueOnFocus = getBuffer().join("")), handleRemove(input, k, pos), writeBuffer(input, getBuffer(), getMaskSet().p), 
             88 == k && (valueOnFocus = getBuffer().join("")), handleRemove(input, k, pos), writeBuffer(input, getBuffer(), getMaskSet().p), 
             input._valueGet() == getBufferTemplate().join("") && $input.trigger("cleared"), 
             input._valueGet() == getBufferTemplate().join("") && $input.trigger("cleared"), 
             opts.showTooltip && $input.prop("title", getMaskSet().mask)) : k == $.inputmask.keyCode.END || k == $.inputmask.keyCode.PAGE_DOWN ? setTimeout(function() {
             opts.showTooltip && $input.prop("title", getMaskSet().mask)) : k == $.inputmask.keyCode.END || k == $.inputmask.keyCode.PAGE_DOWN ? setTimeout(function() {
@@ -885,6 +885,16 @@
                 }).bind(PasteEventType + ".inputmask dragdrop.inputmask drop.inputmask", pasteEvent).bind("setvalue.inputmask", function() {
                 }).bind(PasteEventType + ".inputmask dragdrop.inputmask drop.inputmask", pasteEvent).bind("setvalue.inputmask", function() {
                     var input = this;
                     var input = this;
                     checkVal(input, !0, !1, void 0, !0), valueOnFocus = getBuffer().join(""), (opts.clearMaskOnLostFocus || opts.clearIncomplete) && input._valueGet() == getBufferTemplate().join("") && input._valueSet("");
                     checkVal(input, !0, !1, void 0, !0), valueOnFocus = getBuffer().join(""), (opts.clearMaskOnLostFocus || opts.clearIncomplete) && input._valueGet() == getBufferTemplate().join("") && input._valueSet("");
+                }).bind("cut.inputmask", function(e) {
+                    skipInputEvent = !0;
+                    var input = this, $input = $(input), pos = caret(input);
+                    handleRemove(input, $.inputmask.keyCode.DELETE, pos);
+                    var keypressResult = opts.onKeyPress.call(this, e, getBuffer(), getMaskSet().p, opts);
+                    handleOnKeyResult(input, keypressResult, {
+                        begin: getMaskSet().p,
+                        end: getMaskSet().p
+                    }), input._valueGet() == getBufferTemplate().join("") && $input.trigger("cleared"), 
+                    opts.showTooltip && $input.prop("title", getMaskSet().mask);
                 }).bind("complete.inputmask", opts.oncomplete).bind("incomplete.inputmask", opts.onincomplete).bind("cleared.inputmask", opts.oncleared), 
                 }).bind("complete.inputmask", opts.oncomplete).bind("incomplete.inputmask", opts.onincomplete).bind("cleared.inputmask", opts.oncleared), 
                 $el.bind("keydown.inputmask", keydownEvent).bind("keypress.inputmask", keypressEvent).bind("keyup.inputmask", keyupEvent).bind("compositionupdate.inputmask", compositionupdateEvent), 
                 $el.bind("keydown.inputmask", keydownEvent).bind("keypress.inputmask", keypressEvent).bind("keyup.inputmask", keyupEvent).bind("compositionupdate.inputmask", compositionupdateEvent), 
                 "paste" !== PasteEventType || msie1x || $el.bind("input.inputmask", inputFallBackEvent), 
                 "paste" !== PasteEventType || msie1x || $el.bind("input.inputmask", inputFallBackEvent), 

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

@@ -719,7 +719,7 @@
         function keydownEvent(e) {
         function keydownEvent(e) {
             skipKeyPressEvent = !1;
             skipKeyPressEvent = !1;
             var input = this, $input = $(input), k = e.keyCode, pos = caret(input);
             var input = this, $input = $(input), k = e.keyCode, pos = caret(input);
-            k == $.inputmask.keyCode.BACKSPACE || k == $.inputmask.keyCode.DELETE || iphone && 127 == k || e.ctrlKey && 88 == k ? (e.preventDefault(), 
+            k == $.inputmask.keyCode.BACKSPACE || k == $.inputmask.keyCode.DELETE || iphone && 127 == k || e.ctrlKey && 88 == k && !isInputEventSupported("cut") ? (e.preventDefault(), 
             88 == k && (valueOnFocus = getBuffer().join("")), handleRemove(input, k, pos), writeBuffer(input, getBuffer(), getMaskSet().p), 
             88 == k && (valueOnFocus = getBuffer().join("")), handleRemove(input, k, pos), writeBuffer(input, getBuffer(), getMaskSet().p), 
             input._valueGet() == getBufferTemplate().join("") && $input.trigger("cleared"), 
             input._valueGet() == getBufferTemplate().join("") && $input.trigger("cleared"), 
             opts.showTooltip && $input.prop("title", getMaskSet().mask)) : k == $.inputmask.keyCode.END || k == $.inputmask.keyCode.PAGE_DOWN ? setTimeout(function() {
             opts.showTooltip && $input.prop("title", getMaskSet().mask)) : k == $.inputmask.keyCode.END || k == $.inputmask.keyCode.PAGE_DOWN ? setTimeout(function() {
@@ -883,6 +883,16 @@
                 }).bind(PasteEventType + ".inputmask dragdrop.inputmask drop.inputmask", pasteEvent).bind("setvalue.inputmask", function() {
                 }).bind(PasteEventType + ".inputmask dragdrop.inputmask drop.inputmask", pasteEvent).bind("setvalue.inputmask", function() {
                     var input = this;
                     var input = this;
                     checkVal(input, !0, !1, void 0, !0), valueOnFocus = getBuffer().join(""), (opts.clearMaskOnLostFocus || opts.clearIncomplete) && input._valueGet() == getBufferTemplate().join("") && input._valueSet("");
                     checkVal(input, !0, !1, void 0, !0), valueOnFocus = getBuffer().join(""), (opts.clearMaskOnLostFocus || opts.clearIncomplete) && input._valueGet() == getBufferTemplate().join("") && input._valueSet("");
+                }).bind("cut.inputmask", function(e) {
+                    skipInputEvent = !0;
+                    var input = this, $input = $(input), pos = caret(input);
+                    handleRemove(input, $.inputmask.keyCode.DELETE, pos);
+                    var keypressResult = opts.onKeyPress.call(this, e, getBuffer(), getMaskSet().p, opts);
+                    handleOnKeyResult(input, keypressResult, {
+                        begin: getMaskSet().p,
+                        end: getMaskSet().p
+                    }), input._valueGet() == getBufferTemplate().join("") && $input.trigger("cleared"), 
+                    opts.showTooltip && $input.prop("title", getMaskSet().mask);
                 }).bind("complete.inputmask", opts.oncomplete).bind("incomplete.inputmask", opts.onincomplete).bind("cleared.inputmask", opts.oncleared), 
                 }).bind("complete.inputmask", opts.oncomplete).bind("incomplete.inputmask", opts.onincomplete).bind("cleared.inputmask", opts.oncleared), 
                 $el.bind("keydown.inputmask", keydownEvent).bind("keypress.inputmask", keypressEvent).bind("keyup.inputmask", keyupEvent).bind("compositionupdate.inputmask", compositionupdateEvent), 
                 $el.bind("keydown.inputmask", keydownEvent).bind("keypress.inputmask", keypressEvent).bind("keyup.inputmask", keyupEvent).bind("compositionupdate.inputmask", compositionupdateEvent), 
                 "paste" !== PasteEventType || msie1x || $el.bind("input.inputmask", inputFallBackEvent), 
                 "paste" !== PasteEventType || msie1x || $el.bind("input.inputmask", inputFallBackEvent), 

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


+ 14 - 1
js/jquery.inputmask.js

@@ -1281,7 +1281,7 @@
                 var input = this, $input = $(input), k = e.keyCode, pos = caret(input);
                 var input = this, $input = $(input), k = e.keyCode, pos = caret(input);
 
 
                 //backspace, delete, and escape get special treatment
                 //backspace, delete, and escape get special treatment
-                if (k == $.inputmask.keyCode.BACKSPACE || k == $.inputmask.keyCode.DELETE || (iphone && k == 127) || e.ctrlKey && k == 88) { //backspace/delete
+                if (k == $.inputmask.keyCode.BACKSPACE || k == $.inputmask.keyCode.DELETE || (iphone && k == 127) || (e.ctrlKey && k == 88 && !isInputEventSupported("cut"))) { //backspace/delete
                     e.preventDefault(); //stop default action but allow propagation
                     e.preventDefault(); //stop default action but allow propagation
                     if (k == 88) valueOnFocus = getBuffer().join('');
                     if (k == 88) valueOnFocus = getBuffer().join('');
                     handleRemove(input, k, pos);
                     handleRemove(input, k, pos);
@@ -1652,6 +1652,19 @@
                         valueOnFocus = getBuffer().join('');
                         valueOnFocus = getBuffer().join('');
                         if ((opts.clearMaskOnLostFocus || opts.clearIncomplete) && input._valueGet() == getBufferTemplate().join(''))
                         if ((opts.clearMaskOnLostFocus || opts.clearIncomplete) && input._valueGet() == getBufferTemplate().join(''))
                             input._valueSet('');
                             input._valueSet('');
+                    }).bind('cut.inputmask', function (e) {
+                        skipInputEvent = true; //stop inutFallback
+                        var input = this, $input = $(input), pos = caret(input);
+
+                        handleRemove(input, $.inputmask.keyCode.DELETE, pos);
+                        var keypressResult = opts.onKeyPress.call(this, e, getBuffer(), getMaskSet()["p"], opts);
+                        handleOnKeyResult(input, keypressResult, { begin: getMaskSet()["p"], end: getMaskSet()["p"] });
+                        if (input._valueGet() == getBufferTemplate().join(''))
+                            $input.trigger('cleared');
+
+                        if (opts.showTooltip) { //update tooltip
+                            $input.prop("title", getMaskSet()["mask"]);
+                        }
                     }).bind('complete.inputmask', opts.oncomplete
                     }).bind('complete.inputmask', opts.oncomplete
                     ).bind('incomplete.inputmask', opts.onincomplete
                     ).bind('incomplete.inputmask', opts.onincomplete
                     ).bind('cleared.inputmask', opts.oncleared);
                     ).bind('cleared.inputmask', opts.oncleared);