TinyMCE:Functions
From Moxiecode Documentation Wiki
JavaScript API Functions
This is for advanced users, TinyMCE has a global instance with some commonly used public functions that can be called from the page.
Consult the generated API documentation for more details.
tinyMCE.triggerSave
Makes a cleanup and moves the contents from the editor to the form field. This method is automatically called by tinyMCE by adding a trigger on the forms submit method.
Syntax
tinyMCE.triggerSave([skip_cleanup], [skip_callback]);
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)
Returns: Nothing
tinyMCE.updateContent
Moves the contents from the form element to the editor. This is the opposite of triggerSave(). This method can be used when you want to change the contents of the editor dynamically.
Syntax
tinyMCE.updateContent(form_element_name);
Parameters
- form_element_name
- The name of the form element to get contents from.
Returns: Nothing
tinyMCE.execInstanceCommand
This method executes a command by name on the editor instance specified by the editor_id parameter.
Syntax
tinyMCE.execInstanceCommand(editor_id, command, [user_interface], [value]);
Parameters
- editor_id
- ID of editor instance or element id/name of the replaced element.
- command
- Command to execute for example "Bold" or "Italic". Consult the command identifiers reference 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
This method executes a command by name on the selected editor instance.
Syntax
tinyMCE.execCommand(command, [user_interface], [value]);
Parameters
- command
- Command to execute for example "Bold" or "Italic". Consult the command identifiers reference for details.
- [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>
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.
Has no parameters.
Returns: Nothing
tinyMCE.getContent
(Depracated in version 3.x see: http://tinymce.moxiecode.com/punbb/viewtopic.php?pid=30787 for more info. "tinyMCE.getContent is deprecated in 3.x. Use tinyMCE.activeEditor.getContent or tinyMCE.get('ed').getContent().")
This method returns the HTML contents of the currently selected editor or null if no editor was selected.
Syntax
tinyMCE.getContent(editor_id);
Parameters
- editor_id
- ID of editor instance or element id/name of the replaced element.
Returns: HTML contents of the currently selected editor or null.
tinyMCE.setContent
This method sets the HTML contents of the currently selected editor.
Syntax
tinyMCE.setContent(html);
Parameters
- html
- HTML Source code to set.
Returns: Nothing.
tinyMCE.getInstanceById
This method returns a editor instance by editor id.
Syntax
tinyMCE.getInstanceById(editor_id);
Parameters
- editor_id
- Editor instance to retrieve. Use name of element, not id.
Returns: TinyMCE Editor instance (TinyMCE_Control).
tinyMCE.importThemeLanguagePack
This method imports/loads theme specific language packs. This may be called from custom themes.
Syntax
tinyMCE.importThemeLanguagePack([theme]);
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: Nothing.
tinyMCE.importPluginLanguagePack
This method imports/loads plugin specific language packs. This may be called from custom plugins.
Syntax
tinyMCE.importPluginLanguagePack(plugin, valid_languages);
Parameters
- plugin
- Name of the current plugin.
- valid_languages
- Comma separated list of supported languagepacks.
Returns: Nothing.
tinyMCE.applyTemplate
This method replaces settings and lang variables in the theme.
Syntax
tinyMCE.applyTemplate(html);
Parameters
- html
- HTML code to apply theme variable substitution on.
Returns: New converted, HTML code.
tinyMCE.openWindow
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.
Syntax
tinyMCE.openWindow(template, [args]);
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.
Named arguments
- 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.
Returns: Nothing.
tinyMCE.getWindowArg
This method returns a window argument defined by name. This function is to be used in theme popup windows to retrive dialog parameters.
Syntax
tinyMCE.getWindowArg(name, [default_value]);
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
This method sets a window argument by name. This can for example be useful if plugin are to call other plugins.
Syntax
tinyMCE.setWindowArg(name, value);
Parameters
- name
- Name of window argument to set.
- value
- Value to set in window argument.
Returns: Window argument value.
tinyMCE.getParam
This method returns a TinyMCE configuration parameter.
Syntax
tinyMCE.getParam(name, [default_value], [strip_whitespace]);
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.
