Make Paste as Text Default

1,238 views
Skip to first unread message

Topher

unread,
Sep 9, 2011, 3:08:12 PM9/9/11
to cleditor
Hey everyone,

We recently upgraded a bunch of our textareas to CLEditor and have
been very happy so far. The newish "Paste as Text" feature looks great
for our clients, but, I was wondering if there was a way to make that
the default action when somebody actually pastes content into the
editor. Right now, they paste from Word and everything looks fine, but
it adds a bunch of extra tags that mess things up when viewing it
later.

Has anyone already worked on a solution for this? I am thinking of
taking a stab at it by watching for changes of greater than 1
character and then manually running the "Paste as Text" command and
replacing the existing text. Any insight as to whether or not this
solution would work?

Thanks!

Helen

unread,
Sep 14, 2011, 5:13:37 AM9/14/11
to cleditor
Hi, I have been looking for the same solution for ages. The problem is
that I don t know much about codes. If you fix it later, can you share
the solution with me? Thanks.

Jay

unread,
Sep 22, 2011, 4:00:24 PM9/22/11
to cleditor
I have the same problem here. I am using CLEditor for a CMS. I tried
to tell clients to use the "paste as text" function, but they won't
(clients from hell). So I definately need a solution to strip all
formatting tags directly while the text is pasted (from word e.g.).
If there is no solution, I will have to use another WYSIWYG editor :-(
I googled a lot, but I did not find any usable solution for CLEditor.

Can anyone help?

Thanx!

Alexander Liljengård

unread,
Sep 22, 2011, 4:08:37 PM9/22/11
to cled...@googlegroups.com
Hi!

This is no direct solution, but it seems like you could utilize the paste event for this.
http://www.quirksmode.org/dom/events/cutcopypaste.html

It is not supported by all browsers, and you still have to get the text that is in the clipboard into the cleditor.
There is a few related topics on this on Stackoverflow:

http://stackoverflow.com/questions/686995/jquery-catch-paste-input

/ Alex



2011/9/22 Jay <jonatha...@gmail.com>

Jonathan Albert

unread,
Sep 22, 2011, 6:17:14 PM9/22/11
to cled...@googlegroups.com
Thanks for your answer, Alex. I found that post on Stack overflow on my Research, but i do Not Know how to integrate that into cl Editor, because the user pastes the Text into an iframe and Not into a textbox :-/

mh3

unread,
Sep 25, 2011, 9:06:40 PM9/25/11
to cleditor
Hey there,

just remove the "paste" button from the buttons list in
$.cleditor.defaultOptions.controls.
Instead of "... | cut copy paste pastetext | ..." just "... | cut copy
pastetext | ..."

They can only click on what's there :)

On 9 Sep., 21:08, Topher <fangiotop...@gmail.com> wrote:

Jake Barlow

unread,
Sep 26, 2011, 12:47:08 PM9/26/11
to cleditor
The removal of the button that pastes would be a solution only if we
could capture the ctrl button combination paste and the right button
click paste. Is there a way to bind an event to the actual editor?

Topher Fangio

unread,
Sep 26, 2011, 12:51:31 PM9/26/11
to cled...@googlegroups.com
I did a bit of testing, but couldn't seem to use jQuery to bind to the "paste" event. If anyone knows how, this would be ideal, but from what I gather, this event isn't supported on all platforms.

--
Topher Fangio

System Architect
Pharos Resources

office: 325.216.2908
mobile: 325.660.7141

Jake Barlow

unread,
Sep 26, 2011, 4:00:04 PM9/26/11
to cleditor
I can get it to work on the major browsers except for Opera. I cannot
however get it to bind to the iframe element in the cleditor

Jake Barlow

unread,
Sep 27, 2011, 6:17:48 AM9/27/11
to cleditor
I added the code below on about line 886 of

$doc.bind("paste", function(e) {
e.preventDefault();
alert('You must use the paste button in the toolbar to paste
information into the html editor.');
return false;
});
In most browsers it captures the paste and throws an alert that forces
users to use the built in paste function. This combined with the
solution above will help keep the nasty ms word code out of you
systems. I would like to know if Chris or one of the other jquery
genii out there if there is a way to make this change through a
plugin.

griko k

unread,
Oct 15, 2011, 2:33:43 PM10/15/11
to cleditor
I'm searching for the answer too. If there would be such a kind of
plugin it would really help me out. Otherwise, working with the
cleditor will be possible only with well-checked clients, who don't do
any bad stuff. For now, it is possible to insert not only MS Word text
with the mess tags around it, but also full HTML sites copied by Ctrl
+A Ctrl+C...

Jay

unread,
Nov 11, 2011, 9:58:26 AM11/11/11
to cleditor
A plugin would be great. I really need a solution for that, because
our clients using cleditor won't stop pasting word text via ctrl+v and
that messes up their websites.
any usable solutions for that, yet?

thanks!

Bangar Reddy

unread,
Feb 4, 2013, 7:47:18 AM2/4/13
to cled...@googlegroups.com, ja...@barlowshomes.com
Thank You Jake. Your code works for me.

Sviluppo DBMedica

unread,
May 4, 2016, 9:32:14 AM5/4/16
to cleditor, ja...@barlowshomes.com
I improved the code to automatically paste the text as plain text.
Add this code after "$doc.click(hidePopups)"


    $doc
.bind("paste", function(e) {
        e
.preventDefault();

       
       
// Changes the unformatted text replacing new lines with break tags
       
var text = e.originalEvent.clipboardData.getData('Text').replace(/\n/g, "<br />");
       
if (text !== "") {
            execCommand
(editor, 'inserthtml', text, null);
            focus
(editor);
       
}
   
       
return false;
   
});

Tested only on firefox and chrome
Reply all
Reply to author
Forward
0 new messages