Javascript Functions

This is for advanced users, TinyMCE has a global instance with some public functions that can be called from the page.

tinyMCE.triggerSave([skip_cleanup], [skip_callback]);

Makes a cleanup and moves the contents from the editor to the form field. This method is automaticly called by tinyMCE by adding a trigger on the forms submit method.

Parameters
[skip_cleanup] Disables the cleanup process of trigger save. Defaults to false. (Optional)
[skip_callback] Disables the execution of the save_callback function. Defaults to false. (Optional)
skip_callback

Returns: Nothing

tinyMCE.updateContent(form_element_name);

Moves the contents from the form element to the editor, this does the opposite of triggerSave(). This method can be used when you want to change the contents of the editor dynamicly.

Parameters
form_element_name The name of the form element to get contents from.

Returns: Nothing

tinyMCE.execInstanceCommand(editor_id, command, [user_interface], [value]);

This method executes a command by name on the editor instance specified by the editor_id parameter.

Parameters
editor_id ID of editor instance or element id/name of the replaced element.
command Command to execute check the execCommand function for details.
[user_interface] Is a user interface to be used or not.
[value] Value to pass with command for example a URL..

Returns: Nothing

tinyMCE.execCommand(command, [user_interface], [value]);

This method executes a command by name on the selected editor instance.

Parameters
command Command to execute for example "Bold" or "Italic". These are defined by Mozilla Midas specification or Microsoft specification. But there are a some TinyMCE specific commands many other commands are available within plugins and themes.

mceLink Opens the insert link dialog and inserts a link.
mceImage Opens the insert image dialog and inserts a image.
mceCleanup Removed unwanted elements and attributes from the HTML code.
mceHelp Opens the manual pages.
mceAddControl Adds a editor control to the element id/name specified as value.
mceRemoveControl Removes a specific control by editor_id name. The value is the editor_id to remove, editor ids are in the following format: "mce_editor_<index>". DOM element ids and form element names can allso be used.
mceFocus Focuses the editor by the id placed in value. Editor id's are in the format "mce_editor_". DOM element ids and form element names can allso be used.
mceSetCSSClass Sets the CSS class attribute or creates a new span of the selection. The value is the css class name to assign to selected element or new span element.
mceInsertContent Inserts contents of value parameter to current cursor position.
mceReplaceContent Replaces the current selection with the HTML code in value. The {$selection} variable gets replaced with the currently selected text contents.
mceSetAttribute Sets a attribute of the currenly selected element. The value of this command should be a name/value array with the following parameters.

name - Attribute name to set.
value - Attrbute value to set.
[targets] - Target elements to add attribute on. Default: p,img,span,div,td,h1,h2,h3,h4,h5,h6,pre,address.

Example of usage:
tinyMCE.execCommand('mceSetAttribute',false,{name:'align',value:'right'});
mceToggleVisualAid Toggles visual aid/guidelines mode on/off.
mceAnchor Inserts a named anchor element, the value is the name of the anchor.
mceResetDesignMode Resets the designMode state of all editor instances, this command is useful on Firefox if the editor is placed in tabs or shown/hidden with style.display="none/block". Call this command after the editor displayed again.
mceSelectNode Selects the node/element passed as value. This command will also scroll to the elements location within the editor.
mceSelectNodeDepth Selects the node/element by depth relative from the current node. So a value of 0 will select the currently focused node. This command will also scroll to the elements location within the editor.
mceRemoveNode Removes the specified node and places the contents of the node in the same location. Specify the node reference to remove in the value parameter or null if the currently selected node is to be removed.
[user_interface] Tells if the command is to display a user interface or not. True/False option.
[value] Value to pass for the command for example to insertLink it's the URL of the link.

Returns: Nothing

Example:

<a href="javascript:tinymce.execCommand('Bold');">[Do bold]</a>

(Deprecated) tinyMCE.insertLink(href, target);

This method is deprecated and removed as of 2.0.3. Use tinyMCE.execCommand('mceInsertContent',false,'custom html'); instead and tinyMCE.getInstanceById('<inst>').selection.getFocusElement() to retrive/update the selected element.

But if you realy need the old function it's marked internal but is available in the advanced theme and you can call it by using tinyMCE.themes['advanced']._insertLink(href, target);. But the recommended way is to modify your code to use the logic above.

This method inserts a link a the cursor position of the selected editor instance or updates the selected link with new data. This method should be called upon "ok" in the insertLink popup when you create custom themes.

Parameters
href HREF/URL of the link.
target Target of the link.

Returns: Nothing

(Deprecated) tinyMCE.insertImage(src, alt, border, hspace, vspace, width, height, align, title, onmouseover, onmouseout);

This method is deprecated and removed as of 2.0.3. Use tinyMCE.execCommand('mceInsertContent',false,'custom html'); instead or if you realy need the old function it's marked internal but is available in the advanced theme and you can call it by using tinyMCE.themes['advanced']._insertImage(src, alt, border, hspace, vspace, width, height, align, title, onmouseover, onmouseout);. But the recommended way is to modify your code to use the logic above.

This method inserts a image a the cursor position of the selected editor instance or updates the selected image with new data. This method should be called upon "ok" in the insertImage popup when you create custom themes.

Parameters
src Image src url.
alt Alternative text of img element.
border Border of image element.
hspace Horizontal spacing of image element.
vspace Vertical spacing of image element.
width Width of image element.
height Height of image element.
align Alignment of image element.
title Link title of image element.
onmouseover On mouse over event handler of image element.
onmouseout On mouse out event handler of image element.

Returns: Nothing

tinyMCE.triggerNodeChange();

This method is to be called when external changes is made to the editor. This method will then call the "handleNodeChangeCallback" callback in the theme.

Parameters:

None

Returns: Nothing

tinyMCE.getContent();

This method returns the HTML contents of the currently selected editor or null if no editor was selected.

Parameters:

None

Returns: HTML contents of the currently selected editor or null.

Syntax: tinyMCE.setContent(html);

This method sets the HTML contents of the currently selected editor.

Parameters
html HTML Source code to set.

Returns: None.

tinyMCE.getInstanceById(editor_id);

This method returns a editor instance by editor id.

Parameters
editor_id Editor instance to retrive.

Returns: TinyMCE Editor instance (TinyMCE_Control).

tinyMCE.importThemeLanguagePack([theme]);

This method imports/loads theme specific language packs. This may be called from custom themes.

Parameters
[theme] Name of the current theme. This is a optional parameter it defaults to the global "theme" setting. This parameter is useful within theme plugins.

Returns: None.

tinyMCE.importPluginLanguagePack(plugin, valid_languages);

This method imports/loads plugin specific language packs. This may be called from custom plugins.

Parameters
plugin Name of the current plugin.
valid_languages Comma separated list of supported languagepacks.

Returns: None.

tinyMCE.applyTemplate(html);

This method replaces settings and lang variables in the theme.

Parameters
html HTML code to apply theme variable substitution on.

Returns: New converted, HTML code.

tinyMCE.openWindow(template, [args]);

This method opens a new window by the template data assigned, it will get the width, height and html data from template parameters. The args array contains variable names to be substituted.

There are some custom window arguments:

Parameters
mce_replacevariables Enables/Disables the language/variable replacement of the document HTML. Enabled by default.
mce_windowresize Enables/Disables the auto resize feature of popupwindows. Enabled by default.

Parameters
template Name/Value array with width, height, html and file keys in it.
[args] Name/Value array with variable names to replace. Variables in the template file key value (URL) gets replaced with the argument list.

Returns: None.

tinyMCE.getWindowArg(name, [default_value]);

This method returns a window argument defined by name. This function is to be used in theme popup windows to retrive dialog parameters.

Parameters
name Name of window argument to get.
[default_value] Default value to be returned if window argument is missing.

Returns: Window argument value.

tinyMCE.setWindowArg(name, value);

This method sets a window argument by name. This can for example be useful if plugin are to call other plugins.

Parameters
name Name of window argument to set.
value Value to set in window argument.

Returns: Window argument value.

tinyMCE.getParam(name, [default_value], [strip_whitespace]);

This method returns a TinyMCE configuration parameter.

Parameters:
name Name of window argument to get.
[default_value] Default value to be returned if window argument is missing.
[strip_whitespace] If true all whitespace will be removed from return value, default: false.

Returns: TinyMCE configuration parameter.