Created
May 2, 2020 16:58
-
-
Save tanthammar/cd0b9213e6639deae5e19dc42bf3e547 to your computer and use it in GitHub Desktop.
Capture plain-text on paste JS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Capture the <CTL-V> paste event, only allow plain-text, no images. | |
* | |
* see: https://stackoverflow.com/a/28213320 | |
* | |
* @param {object} evt - array of files | |
* @author Daniel Thompson-Yvetot | |
* @license MIT | |
*/ | |
pasteCapture(evt, ref) { | |
let text, onPasteStripFormattingIEPaste | |
evt.preventDefault() | |
if (evt.originalEvent && evt.originalEvent.clipboardData.getData) { | |
text = evt.originalEvent.clipboardData.getData('text/plain') | |
this.$refs[ref].runCmd('insertText', text) | |
} else if (evt.clipboardData && evt.clipboardData.getData) { | |
text = evt.clipboardData.getData('text/plain') | |
this.$refs[ref].runCmd('insertText', text) | |
} else if (window.clipboardData && window.clipboardData.getData) { | |
if (!onPasteStripFormattingIEPaste) { | |
onPasteStripFormattingIEPaste = true | |
this.$refs[ref].runCmd('ms-pasteTextOnly', text) | |
} | |
onPasteStripFormattingIEPaste = false | |
} | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment