tinymce.Editor

Namespace tinymce
Class Editor
This class contains the core logic for a TinyMCE editor.
Author(s):Moxiecode

Example

// Add a class to all paragraphs in the editor.
tinyMCE.activeEditor.dom.addClass(tinyMCE.activeEditor.dom.select('p'), 'someclass');

// Gets the current editors selection as text
tinyMCE.activeEditor.selection.getContent({format : 'text'});

// Creates a new editor instance
var ed = new tinymce.Editor('textareaid', {
    some_setting : 1
});

// Select each item the user clicks on
ed.onClick.add(function(ed, e) {
    ed.selection.select(e.target);
});

ed.render();

Public Properties

Property Defined By
URI object to current document that holds the TinyMCE editor instance.
Editor
Control manager instance for the editor.
Editor
URI object to document configured for the TinyMCE instance.
Editor
DOM instance for the editor.
Editor
Formatter instance.
Editor
id : String
Editor instance id, normally the same as the div/textarea that was replaced.
Editor
isNotDirty : Boolean
State to force the editor to return false on a isDirty call.
Editor
plugins : Object
Name/Value object containting plugin instances.
Editor
Schema instance, enables you to validate elements and it's children.
Editor
Selection instance for the editor.
Editor
DOM serializer for the editor.
Editor
settings : Object
Name/value collection with editor settings.
Editor
Reference to the theme instance that was used to generate the UI.
Editor
Undo manager instance, responsible for handling undo levels.
Editor
Window manager reference, use this to open new windows and dialogs.
Editor

Public Methods

Method Defined By
Editor(id:String, s:Object)
Constructs a editor instance by id.
Editor
addButton(n:String, s:Object):void
Adds a button that later gets created by the ControlManager.
Editor
addCommand(n:String, f:function, s:Object):void
Adds a custom command to the editor, you can also override existing commands with this method.
Editor
addQueryStateHandler(n:String, f:function, s:Object):void
Adds a custom query state command to the editor, you can also override existing commands with this method.
Editor
addQueryValueHandler(n:String, f:function, s:Object):void
Adds a custom query value command to the editor, you can also override existing commands with this method.
Editor
addShortcut(pa:String, desc:String, cmd_func:String/Function, sc:Object):Boolean
Adds a keyboard shortcut for some command or function.
Editor
addVisual(e:Element):void
Adds visual aid for tables, anchors etc so they can be more easily edited inside the editor.
Editor
convertURL(u:string, n:string, Tag:string/HTMLElement):string
URL converter function this gets executed each time a user adds an img, a or any other element that has a URL in it.
Editor
destroy(s:Boolean):void
Destroys the editor instance by removing all events, element references or other resources that could leak memory.
Editor
execCallback(n:String):Object
Executes a legacy callback.
Editor
execCommand(cmd:String, ui:Boolean, val:mixed, a:Object):Boolean
Executes a command on the current instance.
Editor
focus(sf:Boolean):void
Focuses/activates the editor.
Editor
getBody():Element
Returns the iframes body element.
Editor
getContainer():Element
Returns the editors container element.
Editor
getContent(o:Object):String
Gets the content from the editor instance, this will cleanup the content before it gets returned using the different cle...
Editor
Returns the editors content area container element.
Editor
getDoc():Document
Returns the iframes document object.
Editor
getElement():Element
Returns the target element/textarea that got replaced with a TinyMCE editor instance.
Editor
getLang(n:String, dv:String):void
Returns a language pack item by name/key.
Editor
getParam(n:String, dv:String, ty:String):String
Returns a configuration parameter by name.
Editor
getWin():Window
Returns the iframes window object.
Editor
hide():void
Hides the editor and shows any textarea/div that the editor is supposed to replace.
Editor
init():void
Initializes the editor this will be called automatically when all plugins/themes and language packs are loaded by the re...
Editor
isDirty():Boolean
Returns true/false if the editor is dirty or not.
Editor
isHidden():Boolean
Returns true/false if the editor is hidden or not.
Editor
load(o:Object):String
Loads contents from the textarea or div element that got converted into an editor instance.
Editor
nodeChanged(o:Object):void
Distpaches out a onNodeChange event to all observers.
Editor
queryCommandState(cmd:string):Boolean
Returns a command specific state, for example if bold is enabled or not.
Editor
queryCommandValue(c:string):Object
Returns a command specific value, for example the current font size.
Editor
remove():void
Removes the editor from the dom and tinymce collection.
Editor
render():void
Renderes the editor/adds it to the page.
Editor
save(o:Object):String
Saves the contents from a editor out to the textarea or div element that got converted into an editor instance.
Editor
setContent(h:String, o:Object):String
Sets the specified content to the editor instance, this will cleanup the content before it gets set using the different ...
Editor
setProgressState(b:Boolean, ti:Number, o:Object):Boolean
Sets the progress state, this will display a throbber/progess for the editor.
Editor
Sets up the contentEditable mode.
Editor
setupIframe():void
This method get called by the init method ones the iframe is loaded.
Editor
show():void
Shows the editor and hides any textarea/div that the editor is supposed to replace.
Editor
translate(s:String):String
Translates the specified string by replacing variables with language pack items it will also check if there is a key mat...
Editor

Public Events

Event Defined By
Fires when the editor is activated.
Editor
Fires before a command gets executed for example "Bold".
Editor
onBeforeGetContent(sender:Editor, evt:Event)
Fires before contents is extracted from the editor using for example getContent.
Editor
Fires before the initialization of the editor.
Editor
Fires before new contents is added to the editor.
Editor
onChange(sender:Editor)
Fires when a new undo level is added to the editor.
Editor
onClick(sender:Editor, evt:Event)
Fires when something in the body of the editor is clicked.
Editor
onContextMenu(sender:Editor, evt:Event)
Fires when a contextmenu event is intercepted inside the editor.
Editor
onDblClick(sender:Editor, evt:Event)
Fires when a dblclick event is intercepted inside the editor.
Editor
Fires when the editor is deactivated.
Editor
onEvent(sender:Editor, evt:Event)
Fires when a registered event is intercepted.
Editor
Fires after a command is executed for example "Bold".
Editor
Fires after the contents has been extracted from the editor using for example getContent.
Editor
onInit(sender:Editor)
Fires after the initialization of the editor is done.
Editor
onKeyDown(sender:Editor, evt:Event)
Fires when a keydown event is intercepted inside the editor.
Editor
onKeyPress(sender:Editor, evt:Event)
Fires when a keypress event is intercepted inside the editor.
Editor
onKeyUp(sender:Editor, evt:Event)
Fires when a keydown event is intercepted inside the editor.
Editor
Fires when the editor gets loaded with contents for example when the load method is executed.
Editor
onMouseDown(sender:Editor, evt:Event)
Fires when a mousedown event is intercepted inside the editor.
Editor
onMouseUp(sender:Editor, evt:Event)
Fires when a mouseup event is intercepted inside the editor.
Editor
Fires when the user changes node location using the mouse or keyboard.
Editor
onPaste(sender:Editor, evt:Event)
Fires when a paste event is intercepted inside the editor.
Editor
onPostProcess(sender:Editor, obj:Object)
Fires when the Serializer does a postProcess on the contents.
Editor
Fires after the rendering has completed.
Editor
onPreInit(sender:Editor)
Fires before the initialization of the editor.
Editor
onPreProcess(sender:Editor, obj:Object)
Fires when the Serializer does a preProcess on the contents.
Editor
onRedo(sender:Editor, evt:Event)
Fires when the contents is redo:ed.
Editor
onRemove(sender:Editor)
Fires when the editor instance is removed from page.
Editor
onReset(sender:Editor, evt:Event)
Fires when a form reset event is intercepted.
Editor
Fires when the editor contents gets saved for example when the save method is executed.
Editor
Fires after the contents has been added to the editor using for example onSetContent.
Editor
Fires when the progress throbber is shown above the editor.
Editor
onSubmit(sender:Editor, evt:Event)
Fires when a form submit event is intercepted.
Editor
onUndo(sender:Editor, evt:Event)
Fires when the contents is undo:ed.
Editor
Fires when visual aids is enabled/disabled.
Editor

Property details

baseURIproperty

public baseURI : URI
URI object to current document that holds the TinyMCE editor instance.

controlManagerproperty

public controlManager : ControlManager
Control manager instance for the editor. Will enables you to create new UI elements and change their states etc.

documentBaseURIproperty

public documentBaseURI : URI
URI object to document configured for the TinyMCE instance.

domproperty

public dom : DOMUtils
DOM instance for the editor.

formatterproperty

public formatter : Formatter
Formatter instance.

idproperty

public id : String
Editor instance id, normally the same as the div/textarea that was replaced.

isNotDirtyproperty

public isNotDirty : Boolean
State to force the editor to return false on a isDirty call.

pluginsproperty

public plugins : Object
Name/Value object containting plugin instances.

schemaproperty

public schema : Schema
Schema instance, enables you to validate elements and it's children.

selectionproperty

public selection : Selection
Selection instance for the editor.

serializerproperty

public serializer : Serializer
DOM serializer for the editor.

settingsproperty

public settings : Object
Name/value collection with editor settings.

themeproperty

public theme : Theme
Reference to the theme instance that was used to generate the UI.

undoManagerproperty

public undoManager : UndoManager
Undo manager instance, responsible for handling undo levels.

windowManagerproperty

public windowManager : WindowManager
Window manager reference, use this to open new windows and dialogs.

Method details

Editorconstructor

public function Editor(id:String, s:Object)
Constructs a editor instance by id.
Author(s):Moxiecode

Parameters

id:String Unique id for the editor.
s:Object Optional settings string for the editor.

addButtonmethod

public function addButton(n:String, s:Object):void
Adds a button that later gets created by the ControlManager. This is a shorter and easier method of adding buttons without the need to deal with the ControlManager directly. But it's also less powerfull if you need more control use the ControlManagers factory methods instead.

Parameters

n:String Button name to add.
s:Object Settings object with title, cmd etc.

addCommandmethod

public function addCommand(n:String, f:function, s:Object):void
Adds a custom command to the editor, you can also override existing commands with this method. The command that you add can be executed with execCommand.

Parameters

n:String Command name to add/override.
f:function Function to execute when the command occurs.
s:Object Optional scope to execute the function in.

addQueryStateHandlermethod

public function addQueryStateHandler(n:String, f:function, s:Object):void
Adds a custom query state command to the editor, you can also override existing commands with this method. The command that you add can be executed with queryCommandState function.

Parameters

n:String Command name to add/override.
f:function Function to execute when the command state retrival occurs.
s:Object Optional scope to execute the function in.

addQueryValueHandlermethod

public function addQueryValueHandler(n:String, f:function, s:Object):void
Adds a custom query value command to the editor, you can also override existing commands with this method. The command that you add can be executed with queryCommandValue function.

Parameters

n:String Command name to add/override.
f:function Function to execute when the command value retrival occurs.
s:Object Optional scope to execute the function in.

addShortcutmethod

public function addShortcut(pa:String, desc:String, cmd_func:String/Function, sc:Object):Boolean
Adds a keyboard shortcut for some command or function.

Parameters

pa:String Shortcut pattern. Like for example: ctrl+alt+o.
desc:String Text description for the command.
cmd_func:String/Function Command name string or function to execute when the key is pressed.
sc:Object Optional scope to execute the function in.

Returns

Boolean - true/false state if the shortcut was added or not.

addVisualmethod

public function addVisual(e:Element):void
Adds visual aid for tables, anchors etc so they can be more easily edited inside the editor.

Parameters

e:Element Optional root element to loop though to find tables etc that needs the visual aid.

convertURLmethod

public function convertURL(u:string, n:string, Tag:string/HTMLElement):string
URL converter function this gets executed each time a user adds an img, a or any other element that has a URL in it. This will be called both by the DOM and HTML manipulation functions.

Parameters

u:string URL to convert.
n:string Attribute name src, href etc.
Tag:string/HTMLElement name or HTML DOM element depending on HTML or DOM insert.

Returns

string - Converted URL string.

destroymethod

public function destroy(s:Boolean):void
Destroys the editor instance by removing all events, element references or other resources that could leak memory. This method will be called automatically when the page is unloaded but you can also call it directly if you know what you are doing.

Parameters

s:Boolean Optional state if the destroy is an automatic destroy or user called one.

execCallbackmethod

public function execCallback(n:String):Object
Executes a legacy callback. This method is useful to call old 2.x option callbacks. There new event model is a better way to add callback so this method might be removed in the future.

Parameters

n:String Name of the callback to execute.

Returns

Object - Return value passed from callback function.

execCommandmethod

public function execCommand(cmd:String, ui:Boolean, val:mixed, a:Object):Boolean
Executes a command on the current instance. These commands can be TinyMCE internal commands prefixed with "mce" or they can be build in browser commands such as "Bold". A compleate list of browser commands is available on MSDN or Mozilla.org. This function will dispatch the execCommand function on each plugin, theme or the execcommand_callback option if none of these return true it will handle the command as a internal browser command.

Parameters

cmd:String Command name to execute, for example mceLink or Bold.
ui:Boolean True/false state if a UI (dialog) should be presented or not.
val:mixed Optional command value, this can be anything.
a:Object Optional arguments object.

Returns

Boolean - True/false if the command was executed or not.

focusmethod

public function focus(sf:Boolean):void
Focuses/activates the editor. This will set this editor as the activeEditor in the tinymce collection it will also place DOM focus inside the editor.

Parameters

sf:Boolean Skip DOM focus. Just set is as the active editor.

getBodymethod

public function getBody():Element
Returns the iframes body element.

Returns

Element - Iframe body element.

getContainermethod

public function getContainer():Element
Returns the editors container element. The container element wrappes in all the elements added to the page for the editor. Such as UI, iframe etc.

Returns

Element - HTML DOM element for the editor container.

getContentmethod

public function getContent(o:Object):String
Gets the content from the editor instance, this will cleanup the content before it gets returned using the different cleanup rules options.

Parameters

o:Object Optional content object, this gets passed around through the whole get process.

Returns

String - Cleaned content string, normally HTML contents.

getContentAreaContainermethod

public function getContentAreaContainer():Element
Returns the editors content area container element. The this element is the one who holds the iframe or the editable element.

Returns

Element - HTML DOM element for the editor area container.

getDocmethod

public function getDoc():Document
Returns the iframes document object.

Returns

Document - Iframe DOM document object.

getElementmethod

public function getElement():Element
Returns the target element/textarea that got replaced with a TinyMCE editor instance.

Returns

Element - HTML DOM element for the replaced element.

getLangmethod

public function getLang(n:String, dv:String):void
Returns a language pack item by name/key.

Parameters

n:String Name/key to get from the language pack.
dv:String Optional default value to retrive.

getParammethod

public function getParam(n:String, dv:String, ty:String):String
Returns a configuration parameter by name.

Parameters

n:String Configruation parameter to retrive.
dv:String Optional default value to return.
ty:String Optional type parameter.

Returns

String - Configuration parameter value or default value.

getWinmethod

public function getWin():Window
Returns the iframes window object.

Returns

Window - Iframe DOM window object.

hidemethod

public function hide():void
Hides the editor and shows any textarea/div that the editor is supposed to replace.

initmethod

public function init():void
Initializes the editor this will be called automatically when all plugins/themes and language packs are loaded by the rendered method. This method will setup the iframe and create the theme and plugin instances.

isDirtymethod

public function isDirty():Boolean
Returns true/false if the editor is dirty or not. It will get dirty if the user has made modifications to the contents.

Returns

Boolean - True/false if the editor is dirty or not. It will get dirty if the user has made modifications to the contents.

isHiddenmethod

public function isHidden():Boolean
Returns true/false if the editor is hidden or not.

Returns

Boolean - True/false if the editor is hidden or not.

loadmethod

public function load(o:Object):String
Loads contents from the textarea or div element that got converted into an editor instance. This method will move the contents from that textarea or div into the editor by using setContent so all events etc that method has will get dispatched as well.

Parameters

o:Object Optional content object, this gets passed around through the whole load process.

Returns

String - HTML string that got set into the editor.

nodeChangedmethod

public function nodeChanged(o:Object):void
Distpaches out a onNodeChange event to all observers. This method should be called when you need to update the UI states or element path etc.

Parameters

o:Object Optional object to pass along for the node changed event.

queryCommandStatemethod

public function queryCommandState(cmd:string):Boolean
Returns a command specific state, for example if bold is enabled or not.

Parameters

cmd:string Command to query state from.

Returns

Boolean - Command specific state, for example if bold is enabled or not.

queryCommandValuemethod

public function queryCommandValue(c:string):Object
Returns a command specific value, for example the current font size.

Parameters

c:string Command to query value from.

Returns

Object - Command specific value, for example the current font size.

removemethod

public function remove():void
Removes the editor from the dom and tinymce collection.

rendermethod

public function render():void
Renderes the editor/adds it to the page.

savemethod

public function save(o:Object):String
Saves the contents from a editor out to the textarea or div element that got converted into an editor instance. This method will move the HTML contents from the editor into that textarea or div by getContent so all events etc that method has will get dispatched as well.

Parameters

o:Object Optional content object, this gets passed around through the whole save process.

Returns

String - HTML string that got set into the textarea/div.

setContentmethod

public function setContent(h:String, o:Object):String
Sets the specified content to the editor instance, this will cleanup the content before it gets set using the different cleanup rules options.

Parameters

h:String Content to set to editor, normally HTML contents but can be other formats as well.
o:Object Optional content object, this gets passed around through the whole set process.

Returns

String - HTML string that got set into the editor.

setProgressStatemethod

public function setProgressState(b:Boolean, ti:Number, o:Object):Boolean
Sets the progress state, this will display a throbber/progess for the editor. This is ideal for asycronous operations like an AJAX save call.

Parameters

b:Boolean Boolean state if the progress should be shown or hidden.
ti:Number Optional time to wait before the progress gets shown.
o:Object Optional object to pass to the progress observers.

Returns

Boolean - Same as the input state.

setupContentEditablemethod

public function setupContentEditable():void
Sets up the contentEditable mode.

setupIframemethod

public function setupIframe():void
This method get called by the init method ones the iframe is loaded. It will fill the iframe with contents, setups DOM and selection objects for the iframe. This method should not be called directly.

showmethod

public function show():void
Shows the editor and hides any textarea/div that the editor is supposed to replace.

translatemethod

public function translate(s:String):String
Translates the specified string by replacing variables with language pack items it will also check if there is a key mathcin the input.

Parameters

s:String String to translate by the language pack data.

Returns

String - Translated string.

Event details

onActivateevent

public event onActivate(sender:Editor)
Fires when the editor is activated.

Parameters

sender:Editor Editor instance.

onBeforeExecCommandevent

public event onBeforeExecCommand(sender:Editor)
Fires before a command gets executed for example "Bold".

Parameters

sender:Editor Editor instance.

onBeforeGetContentevent

public event onBeforeGetContent(sender:Editor, evt:Event)
Fires before contents is extracted from the editor using for example getContent.

Parameters

sender:Editor Editor instance.
evt:Event W3C DOM Event instance.

onBeforeRenderUIevent

public event onBeforeRenderUI(sender:Editor)
Fires before the initialization of the editor.

Parameters

sender:Editor Editor instance.

onBeforeSetContentevent

public event onBeforeSetContent(sender:Editor)
Fires before new contents is added to the editor. Using for example setContent.

Parameters

sender:Editor Editor instance.

onChangeevent

public event onChange(sender:Editor)
Fires when a new undo level is added to the editor.

Parameters

sender:Editor Editor instance.

onClickevent

public event onClick(sender:Editor, evt:Event)
Fires when something in the body of the editor is clicked.

Parameters

sender:Editor Editor instance.
evt:Event W3C DOM Event instance.

onContextMenuevent

public event onContextMenu(sender:Editor, evt:Event)
Fires when a contextmenu event is intercepted inside the editor.

Parameters

sender:Editor Editor instance.
evt:Event W3C DOM Event instance.

onDblClickevent

public event onDblClick(sender:Editor, evt:Event)
Fires when a dblclick event is intercepted inside the editor.

Parameters

sender:Editor Editor instance.
evt:Event W3C DOM Event instance.

onDeactivateevent

public event onDeactivate(sender:Editor)
Fires when the editor is deactivated.

Parameters

sender:Editor Editor instance.

onEventevent

public event onEvent(sender:Editor, evt:Event)
Fires when a registered event is intercepted.

Parameters

sender:Editor Editor instance.
evt:Event W3C DOM Event instance.

onExecCommandevent

public event onExecCommand(sender:Editor)
Fires after a command is executed for example "Bold".

Parameters

sender:Editor Editor instance.

onGetContentevent

public event onGetContent(sender:Editor)
Fires after the contents has been extracted from the editor using for example getContent.

Parameters

sender:Editor Editor instance.

onInitevent

public event onInit(sender:Editor)
Fires after the initialization of the editor is done.

Parameters

sender:Editor Editor instance.

See Also

onKeyDownevent

public event onKeyDown(sender:Editor, evt:Event)
Fires when a keydown event is intercepted inside the editor.

Parameters

sender:Editor Editor instance.
evt:Event W3C DOM Event instance.

onKeyPressevent

public event onKeyPress(sender:Editor, evt:Event)
Fires when a keypress event is intercepted inside the editor.

Parameters

sender:Editor Editor instance.
evt:Event W3C DOM Event instance.

onKeyUpevent

public event onKeyUp(sender:Editor, evt:Event)
Fires when a keydown event is intercepted inside the editor.

Parameters

sender:Editor Editor instance.
evt:Event W3C DOM Event instance.

onLoadContentevent

public event onLoadContent(sender:Editor)
Fires when the editor gets loaded with contents for example when the load method is executed.

Parameters

sender:Editor Editor instance.

onMouseDownevent

public event onMouseDown(sender:Editor, evt:Event)
Fires when a mousedown event is intercepted inside the editor.

Parameters

sender:Editor Editor instance.
evt:Event W3C DOM Event instance.

onMouseUpevent

public event onMouseUp(sender:Editor, evt:Event)
Fires when a mouseup event is intercepted inside the editor.

Parameters

sender:Editor Editor instance.
evt:Event W3C DOM Event instance.

onNodeChangeevent

public event onNodeChange(sender:Editor)
Fires when the user changes node location using the mouse or keyboard.

Parameters

sender:Editor Editor instance.

onPasteevent

public event onPaste(sender:Editor, evt:Event)
Fires when a paste event is intercepted inside the editor.

Parameters

sender:Editor Editor instance.
evt:Event W3C DOM Event instance.

onPostProcessevent

public event onPostProcess(sender:Editor, obj:Object)
Fires when the Serializer does a postProcess on the contents.

Parameters

sender:Editor Editor instance.
obj:Object PreProcess object.

onPostRenderevent

public event onPostRender(sender:Editor)
Fires after the rendering has completed.

Parameters

sender:Editor Editor instance.

onPreInitevent

public event onPreInit(sender:Editor)
Fires before the initialization of the editor.

Parameters

sender:Editor Editor instance.

See Also

onPreProcessevent

public event onPreProcess(sender:Editor, obj:Object)
Fires when the Serializer does a preProcess on the contents.

Parameters

sender:Editor Editor instance.
obj:Object PreProcess object.

onRedoevent

public event onRedo(sender:Editor, evt:Event)
Fires when the contents is redo:ed.

Parameters

sender:Editor Editor instance.
evt:Event W3C DOM Event instance.

onRemoveevent

public event onRemove(sender:Editor)
Fires when the editor instance is removed from page.

Parameters

sender:Editor Editor instance.

onResetevent

public event onReset(sender:Editor, evt:Event)
Fires when a form reset event is intercepted.

Parameters

sender:Editor Editor instance.
evt:Event W3C DOM Event instance.

onSaveContentevent

public event onSaveContent(sender:Editor)
Fires when the editor contents gets saved for example when the save method is executed.

Parameters

sender:Editor Editor instance.

onSetContentevent

public event onSetContent(sender:Editor)
Fires after the contents has been added to the editor using for example onSetContent.

Parameters

sender:Editor Editor instance.

onSetProgressStateevent

public event onSetProgressState(sender:Editor)
Fires when the progress throbber is shown above the editor.

Parameters

sender:Editor Editor instance.

onSubmitevent

public event onSubmit(sender:Editor, evt:Event)
Fires when a form submit event is intercepted.

Parameters

sender:Editor Editor instance.
evt:Event W3C DOM Event instance.

onUndoevent

public event onUndo(sender:Editor, evt:Event)
Fires when the contents is undo:ed.

Parameters

sender:Editor Editor instance.
evt:Event W3C DOM Event instance.

onVisualAidevent

public event onVisualAid(sender:Editor)
Fires when visual aids is enabled/disabled.

Parameters

sender:Editor Editor instance.