TinyMCE:API/tinymce.Editor/onPreProcess

From Moxiecode Documentation Wiki

Jump to: navigation, search

Contents

Event: onPreProcess

Summary

This event gets executed before a HTML fragment gets serialized into a HTML string. This event enables you to do modifications to the DOM before the serialization occurs. It's important to know that the element that is getting serialized is cloned so it's not inside a document.

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 node. This object has a couple of properties listed below.

Examples

// Adds an observer to the onPreProcess event using tinyMCE.init
tinyMCE.init({
   ...
   setup : function(ed) {
      ed.onPreProcess.add(function(ed, o) {
           // Add a class to each paragraph in the editor
           ed.dom.addClass(ed.dom.select('p', o.node), 'myclass');
      });
   }
});

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

ed.onPreProcess.add(function(ed, o) {
   // Add a class to each paragraph in the editor
   ed.dom.addClass(ed.dom.select('p', o.node), 'myclass');
});

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".
node
The root DOM node for the contents that will get serialized to an HTML string. This node is a clone of the node that is set for serialization so any changes to this node will not affect the contents of the editor unless it's on a set operation. Check the set state above.
Personal tools