Important changes to Tiny Cloud pricing > Find out more

tinymce.EditorCommands

This class enables you to add custom editor commands and it contains overrides for native browser commands to address various bugs and issues.

This class enables you to add custom editor commands and it contains overrides for native browser co

Properties

name type summary defined by
$ tinymce.dom.DomQuery Dom query instance. tinymce.EditorCommands
activeEditor tinymce.Editor Currently active editor instance. tinymce.EditorCommands
baseURI tinymce.util.URI Absolute baseURI for the installation path of TinyMCE. tinymce.EditorCommands
baseURL String Base URL where the root directory if TinyMCE is located. tinymce.EditorCommands
documentBaseURL String Document base URL where the current document is located. tinymce.EditorCommands
editors Object Collection of editor instances. Deprecated use tinymce.get() instead. tinymce.EditorCommands
i18n Object Collection of language pack data. tinymce.EditorCommands
majorVersion String Major version of TinyMCE build. tinymce.EditorCommands
minorVersion String Minor version of TinyMCE build. tinymce.EditorCommands
releaseDate String Release date of TinyMCE build. tinymce.EditorCommands
suffix String Current suffix to add to each plugin/theme that gets loaded for example ".min". tinymce.EditorCommands

Methods

name summary defined by
add() Adds an editor instance to the editor collection. This will also set it as the active editor. tinymce.EditorCommands
addCommands() Adds commands to the command collection. tinymce.EditorCommands
addI18n() Adds a language pack, this gets called by the loaded language files like en.js. tinymce.EditorCommands
createEditor() Creates an editor instance and adds it to the EditorManager collection. tinymce.EditorCommands
execCommand() Executes a specific command on the currently active editor. tinymce.EditorCommands
get() Returns an editor instance for a given id. tinymce.EditorCommands
init() Initializes a set of editors. This method will create editors based on various settings.

For information on basic usage of init, see: Basic setup.
tinymce.EditorCommands
overrideDefaults() Overrides the default settings for editor instances. tinymce.EditorCommands
queryCommandState() Queries the current state for a command. For example: If the current selection is "bold". tinymce.EditorCommands
queryCommandSupported() Returns true/false if the command is supported or not. tinymce.EditorCommands
queryCommandValue() Queries the command value. For example: The current fontsize. tinymce.EditorCommands
remove() Removes a editor or editors form page. tinymce.EditorCommands
setActive() Sets the active editor instance and fires the deactivate/activate events. tinymce.EditorCommands
translate() Translates the specified string using the language pack items. tinymce.EditorCommands
triggerSave() Calls the save method on all editor instances in the collection. This can be useful when a form is to be submitted. tinymce.EditorCommands

Methods

add

add(editor:tinymce.Editor):tinymce.Editor

Adds an editor instance to the editor collection. This will also set it as the active editor.

Parameters
Return value

addCommands

addCommands(commandList:Object, type:String)

Adds commands to the command collection.

Parameters
  • commandList (Object) - Name/value collection with commands to add, the names can also be comma separated.
  • type (String) - Optional type to add, defaults to exec. Can be value or state as well.

addI18n

addI18n(code:String, items:Object)

Adds a language pack, this gets called by the loaded language files like en.js.

Parameters
  • code (String) - Optional language code.
  • items (Object) - Name/value object with translations.

createEditor

createEditor(id:String, settings:Object):tinymce.Editor

Creates an editor instance and adds it to the EditorManager collection.

Parameters
  • id (String) - Instance id to use for editor.
  • settings (Object) - Editor instance settings.
Return value

execCommand

execCommand(cmd:String, ui:Boolean, value:String):Boolean

Executes a specific command on the currently active editor.

Parameters
  • cmd (String) - Command to perform for example Bold.
  • ui (Boolean) - Optional boolean state if a UI should be presented for the command or not.
  • value (String) - Optional value parameter like for example an URL to a link.
Return value
  • Boolean - true/false if the command was executed or not.

get

get(id:String):tinymce.Editor, Array

Returns an editor instance for a given id.

Examples
// Adds an onclick event to an editor by id
tinymce.get('mytextbox').on('click', function(e) {
   ed.windowManager.alert('Hello world!');
});

// Adds an onclick event to an editor by index
tinymce.get(0).on('click', function(e) {
   ed.windowManager.alert('Hello world!');
});

// Adds an onclick event to an editor by id (longer version)
tinymce.EditorManager.get('mytextbox').on('click', function(e) {
   ed.windowManager.alert('Hello world!');
});
Parameters
  • id (String) - The id or index of the editor instance to return.
Return value
  • tinymce.Editor - Editor instance or an array of editor instances.
  • Array - Editor instance or an array of editor instances.

init

init(settings:Object):Promise

Initializes a set of editors. This method will create editors based on various settings.

For information on basic usage of init, see: Basic setup.

Examples
// Initializes a editor using the longer method
tinymce.EditorManager.init({
   some_settings : 'some value'
});

// Initializes a editor instance using the shorter version and with a promise
tinymce.init({
   some_settings : 'some value'
}).then(function(editors) {
   ...
});
Parameters
  • settings (Object) - Settings object to be passed to each editor instance.
Return value
  • Promise - Promise that gets resolved with an array of editors when all editor instances are initialized.

overrideDefaults

overrideDefaults(defaultSettings:Object)

Overrides the default settings for editor instances.

Parameters
  • defaultSettings (Object) - Defaults settings object.

queryCommandState

queryCommandState(command:String):Boolean

Queries the current state for a command. For example: If the current selection is "bold".

Parameters
  • command (String) - Command to check the state of.
Return value
  • Boolean - true/false - For example: If the selected contents is bold or not.

queryCommandSupported

queryCommandSupported(command:String):Boolean

Returns true/false if the command is supported or not.

Parameters
  • command (String) - Command that we check support for.
Return value
  • Boolean - true/false if the command is supported or not.

queryCommandValue

queryCommandValue(command:String):String

Queries the command value. For example: The current fontsize.

Parameters
  • command (String) - Command to check the value of.
Return value
  • String - Command value or an empty string (`""`) if the query command is not found.

remove

remove(selector:tinymce.Editor):tinymce.Editor

Removes a editor or editors form page.

Examples
// Remove all editors bound to divs
tinymce.remove('div');

// Remove all editors bound to textareas
tinymce.remove('textarea');

// Remove all editors
tinymce.remove();

// Remove specific instance by id
tinymce.remove('#id');
Parameters
Return value
  • tinymce.Editor - The editor that got passed in will be return if it was found otherwise null.

setActive

setActive(editor:tinymce.Editor)

Sets the active editor instance and fires the deactivate/activate events.

Parameters

translate

translate(text:String):String

Translates the specified string using the language pack items.

Parameters
  • text (String) - String to translate
Return value
  • String - Translated string.

triggerSave

triggerSave()

Calls the save method on all editor instances in the collection. This can be useful when a form is to be submitted.

Examples
// Saves all contents
tinyMCE.triggerSave();

Can't find what you're looking for? Let us know.

Except as otherwise noted, the content of this page is licensed under the Creative Commons BY-NC-SA 3.0 License, and code samples are licensed under the Apache 2.0 License.