1

Topic: Make Ctrl-V always paste as plaintext

Hello

I've been searching and looking through numerous posts concerning different pasting issues and solutions, but have yet to find a way to provide the very simple: always paste as plaintext, also using Ctrl-V, no matter what kind of strange Word etc. content you have in the clipboard.

Is there an easy way to do this? If not I think there should be, with or without the paste-plugin.

Hope someone can help...

Thanks in advance

Best regards
Silmarillion/Morten

2

Re: Make Ctrl-V always paste as plaintext

ok so interesting question, in FF, by default unless you manually change some security settings in your build of FF, copy/cut/paste don't work but funny enough control-v etc work. 

We need to access the clipboard and manipulate it and then push the data into tinymce. Clipboard is not accessible in FF.

So in FF if you really do not want ppl to paste any html into the editor then you need to capture the control-v key combination and kill the event. In IE you can access the clipboard as text which is essentially what you want.

To implement this you can do it two ways, either amend tiny_mce.js (not recommended) or copy the advanced theme and rename it something else and use it for your editor, and in there you can override some stuff in tiny_mce.js which is what I will demonstrate.

so assuming you want to change the newly created theme or the advanced theme, open up the editor_template.js (the source one and overwrite the compressed one with the source one so you can change it)

in there paste this before the the area which starts with execCommand (so above it)


handleEvent : function(e) {
        var inst = tinyMCE.selectedInstance;
        var focusElm = inst.getFocusElement();
       
       
        switch (e.type) {
           
               
            case "keydown":
           
            if (e.ctrlKey) { var ctrl = 1; }
            if (e.keyCode == 86) { var v = 1; }
           
            if (ctrl && v) {
                 if (tinyMCE.isIE) {
                alert(window.clipboardData.getData("Text")); 
                                                                //or do whatever you want with the data
                }
            return tinyMCE.cancelEvent(e);
                                                // need to cancel the event for FF and after you're done with whatever you want to do with the data to be pasted
            }
                return true;
                break;

               
        }
    },

3

Re: Make Ctrl-V always paste as plaintext

Thank you so much! I'll try this!

best regards
morten

4

Re: Make Ctrl-V always paste as plaintext

so assuming you want to change the newly created theme or the advanced theme, open up the editor_template.js (the source one and overwrite the compressed one with the source one so you can change it)

in there paste this before the the area which starts with execCommand (so above it)

Please can you explain this better? Cant totally understand how to do this part?

Does this mean

Edit jscripts/tiny_mce/themes/advanced/editor_template_src.js with the additional code above then copy over the top of compressed editor_template.js??

Cant see to get this to work.

Also changed getData to clearData since we dont want the copy and paste option??

Anyone?

Last edited by swapshop (2007-05-19 09:41:17)

5

Re: Make Ctrl-V always paste as plaintext

This is just an idea which i havent tested.
Could it be possible to have a hidden form textarea and focus it on ctrl-v event?
That way browsers where you havent got access to the clipdata paste the text into a textarea, then tinyMCE can paste the contents from the textarea in the real editor?

Maybe a dumb idea...

6

Re: Make Ctrl-V always paste as plaintext

Swapshop, paste the code in editor_template_src.js then copy editor_template_src.js to editor_template.js overwriting the old compressed one.

You don't have to use clearData, just cancel the event.

handleEvent : function(e) {
        var inst = tinyMCE.selectedInstance;
        var focusElm = inst.getFocusElement();
       
        switch (e.type) {
           
               
            case "keydown":
           
            if (e.ctrlKey) { var ctrl = 1; }
            if (e.keyCode == 86) { var v = 1; }
           
            if (ctrl && v) {
                   return tinyMCE.cancelEvent(e);
            }
                return true;
                break;   
        }
    },

7

Re: Make Ctrl-V always paste as plaintext

Bomelin,

Thanks very much for your post here - I used it to call a paste from MS Word when ctrl-v is keyed in by the user.

Cheers

Pete...

8

Re: Make Ctrl-V always paste as plaintext

I am having an issue as my editor is on readonly.
I can edit my text as i use contentEditable=true on the div i want to alter.

When it comes to paste then there is problem. i cannot paste from word.
I made the following change in tiny_mce which will allow me to use the shortcuts (therefore use the past plugin too).

tiny_mce.js CHANGE=>
if (s.readonly || !s.readonly)
   t._addEvents();

But then i cannot paste from word.

Does anybody migth know some tricks. I tried the one above but no success.

regards,

Jerome