inputmask
Advanced tools
Comparing version 5.0.9-beta.16 to 5.0.9-beta.17
@@ -159,49 +159,45 @@ import { | ||
}, | ||
pasteEvent: function (e) { | ||
const inputmask = this.inputmask, opts = inputmask.opts; | ||
pasteEvent: async function (e) { | ||
function handlePaste(inputmask, input, inputValue, pastedValue, onBeforePaste) { | ||
var caretPos = caret.call(inputmask, input, undefined, undefined, true); | ||
var input = this, | ||
inputValue = inputmask._valueGet(true), | ||
caretPos = caret.call(inputmask, input), | ||
tempValue; | ||
var valueBeforeCaret = inputValue.substr(0, caretPos.begin), | ||
valueAfterCaret = inputValue.substr(caretPos.end, inputValue.length); | ||
if (inputmask.isRTL) { | ||
tempValue = caretPos.end; | ||
caretPos.end = translatePosition.call(inputmask, caretPos.begin); | ||
caretPos.begin = translatePosition.call(inputmask, tempValue); | ||
} | ||
if (valueBeforeCaret == (inputmask.isRTL ? getBufferTemplate.call(inputmask).slice().reverse() : getBufferTemplate.call(inputmask)).slice(0, caretPos.begin).join("")) valueBeforeCaret = ""; | ||
if (valueAfterCaret == (inputmask.isRTL ? getBufferTemplate.call(inputmask).slice().reverse() : getBufferTemplate.call(inputmask)).slice(caretPos.end).join("")) valueAfterCaret = ""; | ||
var valueBeforeCaret = inputValue.substr(0, caretPos.begin), | ||
valueAfterCaret = inputValue.substr(caretPos.end, inputValue.length); | ||
pastedValue = valueBeforeCaret + pastedValue + valueAfterCaret; | ||
if (inputmask.isRTL && opts.numericInput !== true) { | ||
pastedValue = pastedValue.split(""); | ||
for (let c of getBufferTemplate.call(inputmask)) { | ||
if (pastedValue[0] === c) | ||
pastedValue.shift(); | ||
} | ||
pastedValue = pastedValue.reverse().join(""); | ||
} | ||
if (valueBeforeCaret == (inputmask.isRTL ? getBufferTemplate.call(inputmask).slice().reverse() : getBufferTemplate.call(inputmask)).slice(0, caretPos.begin).join("")) valueBeforeCaret = ""; | ||
if (valueAfterCaret == (inputmask.isRTL ? getBufferTemplate.call(inputmask).slice().reverse() : getBufferTemplate.call(inputmask)).slice(caretPos.end).join("")) valueAfterCaret = ""; | ||
var pasteValue = pastedValue; | ||
if (typeof onBeforePaste === "function") { | ||
pasteValue = onBeforePaste.call(inputmask, pasteValue, opts); | ||
if (pasteValue === false) { | ||
return false; | ||
} | ||
if (!pasteValue) { | ||
pasteValue = inputValue; | ||
} | ||
} | ||
checkVal(input, true, false, pasteValue.toString().split(""), e); | ||
} | ||
if (window.clipboardData && window.clipboardData.getData) { // IE | ||
inputValue = valueBeforeCaret + window.clipboardData.getData("Text") + valueAfterCaret; | ||
} else if (e.clipboardData && e.clipboardData.getData) { | ||
inputValue = valueBeforeCaret + e.clipboardData.getData("text/plain") + valueAfterCaret; | ||
} else { | ||
return true; | ||
} //allow native paste event as fallback ~ masking will continue by inputfallback | ||
const input = this, inputmask = this.inputmask, opts = inputmask.opts; | ||
var inputValue = inputmask._valueGet(true), pastedValue; | ||
var pasteValue = inputValue; | ||
if (inputmask.isRTL) { | ||
pasteValue = pasteValue.split(""); | ||
for (let c of getBufferTemplate.call(inputmask)) { | ||
if (pasteValue[0] === c) | ||
pasteValue.shift(); | ||
} | ||
pasteValue = pasteValue.join(""); | ||
inputmask.skipInputEvent = true; | ||
if (e.clipboardData && e.clipboardData.getData) { | ||
pastedValue = e.clipboardData.getData("text/plain"); | ||
} else if (window.clipboardData && window.clipboardData.getData) { // IE | ||
pastedValue = window.clipboardData.getData("Text"); | ||
} | ||
if (typeof opts.onBeforePaste === "function") { | ||
pasteValue = opts.onBeforePaste.call(inputmask, pasteValue, opts); | ||
if (pasteValue === false) { | ||
return false; | ||
} | ||
if (!pasteValue) { | ||
pasteValue = inputValue; | ||
} | ||
} | ||
checkVal(input, true, false, pasteValue.toString().split(""), e); | ||
handlePaste(inputmask, input, inputValue, pastedValue, opts.onBeforePaste); | ||
e.preventDefault(); | ||
@@ -413,3 +409,4 @@ }, | ||
clipDataText = inputmask.isRTL ? clipData.reverse().join("") : clipData.join(""); | ||
if (window.navigator && window.navigator.clipboard) window.navigator.clipboard.writeText(clipDataText); | ||
if (window.navigator && window.navigator.clipboard) | ||
window.navigator.clipboard.writeText(clipDataText); | ||
else if (window.clipboardData && window.clipboardData.getData) { // IE | ||
@@ -460,4 +457,3 @@ window.clipboardData.setData("Text", clipDataText); | ||
if (inputmask.undoValue !== nptValue) { | ||
if (nptValue != "" || (inputmask.undoValue != getBufferTemplate.call(inputmask).join("") || (inputmask.undoValue == getBufferTemplate.call(inputmask).join("") && inputmask.maskset.validPositions.length > 0))) | ||
{ | ||
if (nptValue != "" || (inputmask.undoValue != getBufferTemplate.call(inputmask).join("") || (inputmask.undoValue == getBufferTemplate.call(inputmask).join("") && inputmask.maskset.validPositions.length > 0))) { | ||
inputmask.undoValue = nptValue; | ||
@@ -464,0 +460,0 @@ $input.trigger("change"); |
{ | ||
"name": "inputmask", | ||
"version": "5.0.9-beta.16", | ||
"version": "5.0.9-beta.17", | ||
"description": "Inputmask is a javascript library which creates an input mask. Inputmask can run against vanilla javascript, jQuery and jqlite.", | ||
@@ -5,0 +5,0 @@ "main": "dist/inputmask.js", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
932488
12357