pen icon indicating copy to clipboard operation
pen copied to clipboard

Paste plain text

Open l2aelba opened this issue 10 years ago • 12 comments

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

l2aelba avatar Sep 16 '13 09:09 l2aelba

yes, it could be a great experiment

sofish avatar Sep 17 '13 16:09 sofish

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 avatar Sep 17 '13 16:09 cjoh

@cjoh Yeahhhhh

l2aelba avatar Sep 17 '13 20:09 l2aelba

  $('[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 avatar Oct 06 '13 10:10 rkusa

@rkusa Did you test for all modern browsers ? Thanks

l2aelba avatar Oct 09 '13 09:10 l2aelba

@rkusa Ok, I tested with Chrome + Firefox , work so fine ! Thanks ! http://jsfiddle.net/UjwfB/

l2aelba avatar Oct 09 '13 09:10 l2aelba

@l2aelba Works in Safari + Opera Next, too. I think for older IEs it has to be window.clipboardData instead of e.clipboardData.

rkusa avatar Oct 09 '13 09:10 rkusa

@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....

l2aelba avatar Oct 09 '13 09:10 l2aelba

$('[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 avatar Oct 09 '13 10:10 rkusa

@rkusa good job, thanks :D

l2aelba avatar Oct 09 '13 10:10 l2aelba

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

sofish avatar Oct 11 '13 05:10 sofish

@rkusa Thanks! :+1:

naoyeye avatar Jun 04 '14 13:06 naoyeye