Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
191
rated 0 times [  196] [ 5]  / answers: 1 / hits: 95736  / 14 Years ago, fri, april 23, 2010, 12:00:00

Googled it thousands of times, No one gives a complete solution of how to make Tinymce paste in plain text by default and strip out any formatting without clicking the paste as text button.



Any Ideas of how to implement that? or how to enable the paste as text button automatically?



Thank you


More From » jquery

 Answers
7

EDIT: this solution is for version 3.x, for 4.x version read the answer from @Paulo Neves



The problem is that Paste plugin automatically resets plain text paste on every paste. So all we need to do - set it back. The following code should help.



tinyMCE.init({
...
oninit : setPlainText,
plugins : paste

....
});


The definition of setPlainText



 function setPlainText() {
var ed = tinyMCE.get('elm1');

ed.pasteAsPlainText = true;

//adding handlers crossbrowser
if (tinymce.isOpera || /Firefox/2/.test(navigator.userAgent)) {
ed.onKeyDown.add(function (ed, e) {
if (((tinymce.isMac ? e.metaKey : e.ctrlKey) && e.keyCode == 86) || (e.shiftKey && e.keyCode == 45))
ed.pasteAsPlainText = true;
});
} else {
ed.onPaste.addToTop(function (ed, e) {
ed.pasteAsPlainText = true;
});
}
}


So now it always will be plain.


[#96999] Tuesday, April 20, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kiyam

Total Points: 448
Total Questions: 96
Total Answers: 92

Location: Philippines
Member since Sat, Jul 11, 2020
4 Years ago
;