TinyMCE:API/tinymce.Editor/onBeforeSetContent

From Moxiecode Documentation Wiki

Jump to: navigation, search

Contents

Event: onBeforeSetContent

Summary

This event gets executed when the setContent method is called but before the contents gets serialized and placed in the editor. This event is useful when you want to change for example BBCode into HTML code before setting it to the document DOM.

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 contents that will be stored.

Examples

// Adds an observer to the onBeforeSetContent event using tinyMCE.init
tinyMCE.init({
   ...
   setup : function(ed) {
      ed.onBeforeSetContent.add(function(ed, o) {
           // Replaces all a characters with b characters
           o.content = o.content.replace(/a/g, 'b');
      });
   }
});

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

ed.onBeforeSetContent.add(function(ed, o) {
   // Replaces all a characters with b characters
   o.content = o.content.replace(/a/g, 'b');
});

ed.render();
Personal tools