How to automatic resize tinyMCE?

Nowadays, you should use the autoresize plugin that comes with tinyMCE. You will have to call tinyMCE like this (jQuery version): $(‘.tinymce’).tinymce({ theme : ‘advanced’, plugins : ‘autoresize’, width: ‘100%’, height: 400, autoresize_min_height: 400, autoresize_max_height: 800, }); I made the experience, that it may be helpful to manually call the resizing in the init_instance_callback to … Read more

make readonly/disable tinymce textarea

Use the configuration parameter readonly tinyMCE.init({ … theme : “advanced”, readonly : 1 }); Here is a link to a demo. Update: What you can do to prevent users from editing content in your editor is to set the contenteditable attribute of the editors iframe body to false: tinymce.activeEditor.getBody().setAttribute(‘contenteditable’, false);

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

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

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

tech