How do I remove tinyMCE and then re-add it?

To cleanly remove an editor instance and avoid any errors use: tinymce.EditorManager.execCommand(‘mceRemoveControl’,true, editor_id); To reinitialize the instance use: tinymce.EditorManager.execCommand(‘mceAddControl’,true, editor_id); Be aware that when moving TinyMCE editors in the DOM you need to removeControl and addControl too, otherwise it results in JS errors. As of TinyMCE 4 the methods to remove and reinitialize an instance … Read more

TinyMCE Paste As Plain Text

This is what i do to get paste plain text. 1. paste_preprocess setting (in tinymce init) paste_preprocess : function(pl, o) { //example: keep bold,italic,underline and paragraphs //o.content = strip_tags( o.content,'<b><u><i><p>’ ); // remove all tags => plain text o.content = strip_tags( o.content,” ); }, 2. function strip_tags (on the main document) // Strips HTML and … Read more

Remove style attribute from HTML tags

The pragmatic regex (<[^>]+) style=”.*?” will solve this problem in all reasonable cases. The part of the match that is not the first captured group should be removed, like this: $output = preg_replace(‘/(<[^>]+) style=”.*?”/i’, ‘$1’, $input); Match a < followed by one or more “not >” until we come to space and the style=”…” part. … Read more

JQuery to load Javascript file dynamically

Yes, use getScript instead of document.write – it will even allow for a callback once the file loads. You might want to check if TinyMCE is defined, though, before including it (for subsequent calls to ‘Add Comment’) so the code might look something like this: $(‘#add_comment’).click(function() { if(typeof TinyMCE == “undefined”) { $.getScript(‘tinymce.js’, function() { … Read more