TinyMCE:API/tinymce.Editor/onPostProcess

From Moxiecode Documentation Wiki

Jump to: navigation, search

Contents

Event: onPostProcess

Summary

This event gets executed after a HTML fragment has been serialized into a HTML string. This event enables you to do modifications to the HTML string like regexp replaces etc. It only gets called when cleanup is set to true.

Syntax

event_callback(<tinymce.Editor> ed, <Object> o)

Parameters

ed
Sender object/Editor instance that is serializing an element.
o
Object containing things like the current contents. Check the option properties below.

Examples

// Adds an observer to the onPostProcess event using tinyMCE.init
tinyMCE.init({
   ...
   setup : function(ed) {
      ed.onPostProcess.add(function(ed, o) {
           // Remove all paragraphs and replace with BR
           o.content = o.content.replace(/<p[^>]+>|<p>/g, '');
           o.content = o.content.replace(/<\/p>/g, '<br />');
      });
   }
});

// Adds an observer to the onPostProcess event using the render method
var ed = new tinymce.Editor('someid', {
   .. Some settings
});

ed.onPostProcess.add(function(ed, o) {
   // Remove all paragraphs and replace with BR
   o.content = o.content.replace(/<p[^>]+>|<p>/g, '');
   o.content = o.content.replace(/<\/p>/g, '<br />');
});

ed.render();

Options properties

The second argument for the onPreProcess event contains a few optional fields that can be useful for the functionality inside your custom event handler function.

get
Is true if contents is extracted from the editor. Normally during a editor.getContent call.
set
Is true if contents is inserted into editor. Normally during a editor.setContent call.
load
Is true if contents is loaded from the textarea into the editor. Normally during a editor.load call.
save
Is true if contents is saved out to the textarea from the editor. Normally during a editor.save call.
format
Output format defaults to "html". But might be for example "bbcode".
content
The output from the serialization process normally an HTML string but might be some other format depending on the format property. You can run regular expressions on this contents to post process away tags etc.
Personal tools