pen
pen copied to clipboard
Paste plain text
Should be cool, if we have option like..
var options = { PastePlainText : true }
Just let user paste plain text only (so another DIV inserted or more kidding div)
I know a solution like..
$('[contenteditable]').on('paste', function (e) { e.preventDefault(); document.execCommand('inserttext', false, prompt('Paste something.')); });
But maybe you know better to do
EXTRA : Should be cool if this option listened option from list
like list: ['bold', 'italic', 'underline']
So no H1
H2
LINK
or another allowed
JUST A IDEA :D
yes, it could be a great experiment
Actually it'd be more interesting if it was:
var options = {
pasteFormat: markdown //or plaintext or html
}
And it captured pasted information and engaged it that way. Super useful for eliminating paste styling, but capturing structural information -- i.e. if you want to know your headers and your bolds, but don't want to change the font styling, color etc.
@cjoh Yeahhhhh
$('[contenteditable]').on('paste', function (e) {
e.preventDefault()
var text = (e.originalEvent || e).clipboardData.getData('text/plain')
document.execCommand('insertText', false, text)
})
Works fine for me
@rkusa Did you test for all modern browsers ? Thanks
@rkusa Ok, I tested with Chrome + Firefox , work so fine ! Thanks ! http://jsfiddle.net/UjwfB/
@l2aelba Works in Safari + Opera Next, too. I think for older IEs it has to be window.clipboardData
instead of e.clipboardData
.
@rkusa That should be something like...
$('[contenteditable]').on('paste', function (e) { e.preventDefault(); var text = (e.originalEvent || e).clipboardData.getData('text/plain') || false; if (text) { document.execCommand('insertText', false, text); } else { text = prompt('Paste something..'); text = paste?paste:false; if(text){document.execCommand('inserttext', false, text);} } });
or shorter...
$('[contenteditable]').on('paste', function (e) { e.preventDefault(); var text = (e.originalEvent || e).clipboardData.getData('text/plain') || prompt('Paste something..'); if (text) { document.execCommand('insertText', false, text); } });
Pls, review mine....
$('[contenteditable]').on('paste', function (e) {
e.preventDefault()
var text = (window.clipboardData || (e.originalEvent || e).clipboardData).getData('text/plain')
document.execCommand('insertText', false, text)
})
Could work, too. http://jsfiddle.net/xMZcy/ But I don't have access to my Windows PC in the next couple of days to actually test it for IEs ...
@rkusa good job, thanks :D
thx you @l2aelba @rkusa ,please send a pull-request.
BTW. im preparing for my own start-up and the comming Qcon/Ctrip Conf/W3CTECH Conf, and have no time to update the editor
@rkusa Thanks! :+1: