3

I've deleted the old post here.

I have a contentEditable div. If you paste e.g. from Word to it, there shouldn't be any formatting. I got this working in Chrome, FF, IE. Does IE not support formatting in ContentEditable div? It looked like that... Would be great. Just tested in IE8.

Basically I'm getting the content of my div onPaste. Remove its content. Then the paste event pastes whatever into my div. Since i just emptied it, i can get the divs content again and got the pasted text. I'm also saving my cursor/selection and at the end I'm putting everything back together. Not that complex.

Safari fails with the first part. If empty() does get triggered or html() or anything else which cleans the div, the paste isn't made.

Here's a demo: http://jsfiddle.net/nK4eJ/9/

Any idea why this isn't working in safari and how i can get it working?

xotix
  • 347
  • 1
  • 11
  • 33
  • Can you reproduce your problem with a [JS Fiddle demo](http://jsfiddle.net/)? – David says reinstate Monica Feb 08 '12 at 14:21
  • is this related: http://stackoverflow.com/questions/6899659/remove-formatting-from-a-contenteditable-div? – JMax Feb 08 '12 at 14:22
  • David Thomas: I tried to, but on JsFiddle it doesn't work. JMax: I've seen that thread, but for some reason i didn't really look closer at it. Anyway, he is alerting the whole thing on onClick. But i want it in my editor, that's what pasting is about. Why does everyone alert this stuff? I'm weird. How do i return it properly so it get's added to my editor? – xotix Feb 08 '12 at 14:35
  • .text() grabs only the text right? So basically it is cleaned up. But how do i return it? – xotix Feb 08 '12 at 14:52
  • See http://stackoverflow.com/a/2177059/96100 – Tim Down Feb 13 '12 at 10:27
  • It is just for ctrl v. I just want it like it is done here, on stackoverflow for the comments. – xotix Feb 20 '12 at 15:26

2 Answers2

0

you can use Niceditor. it's light and easy to use! see contentEditable div demos here.

EmRa228
  • 1,188
  • 10
  • 22
  • I've already added some functionality and i like to built it on my own. Learning and knowing what i got. :) I've done it now with the paste event and detecting ctrl v, should be enough. – xotix Apr 16 '12 at 06:17
0

I got it solved

Uncommented: http://jsfiddle.net/nK4eJ/26/

Commented: http://jsfiddle.net/nK4eJ/27/

Not a perfect solution in IE and Opera, but it does its job. Don't want to write a whole lib for that. :)

xotix
  • 347
  • 1
  • 11
  • 33