This class contains the core logic for a TinyMCE editor.
// 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
}, tinymce.EditorManager);
ed.render();| Name | Type | Summary | Defined by |
|---|---|---|---|
$ |
Dom query instance with default scope to the editor document and default element is the body of the editor. Deprecated in TinyMCE 5.10 and has been marked for removal in TinyMCE 6.0. |
||
baseURI |
URI object to current document that holds the TinyMCE editor instance. |
||
contentCSS |
|
Array with CSS files to load into the iframe. |
|
contentStyles |
|
Array of CSS styles to add to head of document when the editor loads. |
|
documentBaseURI |
URI object to document configured for the TinyMCE instance. |
||
dom |
DOM instance for the editor. |
||
formatter |
Formatter instance. |
||
id |
|
Editor instance id, normally the same as the div/textarea that was replaced. |
|
initialized |
|
Is set to true after the editor instance has been initialized |
|
mode |
Editor mode API |
||
notificationManager |
Notification manager reference, use this to open new windows and dialogs. |
||
parser |
HTML parser will be used when contents is inserted into the editor. |
||
plugins |
|
Name/Value object containing plugin instances. |
|
schema |
Schema instance, enables you to validate elements and its children. |
||
selection |
Selection instance for the editor. |
||
serializer |
DOM serializer for the editor. Will be used when contents is extracted from the editor. |
||
settings |
|
Name/value collection with editor settings. |
|
theme |
Reference to the theme instance that was used to generate the UI. |
||
ui |
Editor ui components |
||
undoManager |
Undo manager instance, responsible for handling undo levels. |
||
windowManager |
Window manager reference, use this to open new windows and dialogs. |
| Name | Summary | Defined by |
|---|---|---|
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. |
||
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. |
||
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. |
||
Adds a keyboard shortcut for some command or function. |
||
Adds visual aid for tables, anchors etc so they can be more easily edited inside the editor. |
||
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. |
||
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. |
||
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. Deprecated in TinyMCE 5.10 and has been marked for removal in TinyMCE 6.0. |
||
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. |
||
Fires the specified event by name. Consult the event reference for more details on each event. |
||
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. |
||
Returns the root element of the editable area. For a non-inline iframe-based editor, returns the iframe’s body element. |
||
Returns the container element of the editor. The container element includes all the elements added to the page for the editor. Such as UI, iframe, etc. |
||
Gets the content from the editor instance, this will cleanup the content before it gets returned using the different cleanup rules options. |
||
Returns the content area container element of the editor. This element holds the iframe or the editable element. |
||
Returns the iframes document object. |
||
Returns the target element/textarea that got replaced with a TinyMCE editor instance. |
||
Returns a configuration parameter by name. |
||
Returns the iframes window object. |
||
Returns true/false if the object has a event of the specified name. |
||
Returns true/false if the editor has real keyboard focus. |
||
Checks that the plugin is in the editor configuration and can optionally check if the plugin has been loaded. Added in TinyMCE 5.5 |
||
Hides the editor and shows any textarea/div that the editor is supposed to replace. |
||
Inserts content at caret position. |
||
Returns true/false if the editor is dirty or not. It will get dirty if the user has made modifications to the contents. The dirty state is automatically set to |
||
Returns true/false if the editor is hidden or not. |
||
Loads contents from the textarea, input or other element that got converted into an editor instance. This method will move the contents from that textarea, input or other element into the editor by using setContent so all events etc that method has will get dispatched as well. |
||
Dispatches out a onNodeChange event to all observers. This method should be called when you need to update the UI states or element path etc. |
||
Unbinds an event listener to a specific event by name. Consult the event reference for more details on each event. |
||
Binds an event listener to a specific event by name. Consult the event reference for more details on each event. |
||
Bind the event callback and once it fires the callback is removed. Consult the event reference for more details on each event. |
||
Returns a command specific state, for example if bold is enabled or not. |
||
Returns true/false if the command is supported or not. |
||
Returns a command specific value, for example the current font size. |
||
Removes the editor from the dom and tinymce collection. |
||
Renders the editor/adds it to the page. |
||
Resets the editors content, undo/redo history and dirty state. If |
||
Saves the contents from an 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. |
||
Sets the specified content to the editor instance, this will cleanup the content before it gets set using the different cleanup rules options. |
||
Explicitly sets the dirty state. This will fire the dirty event if the editor dirty state is changed from false to true by invoking this method. |
||
Sets the editor mode. For example: "design", "code" or "readonly". Deprecated in TinyMCE 5.0.4 and has been marked for removal in TinyMCE 6.0 - Use |
||
Sets the progress state, this will display a throbber/progess for the editor. This is ideal for asynchronous operations like an AJAX save call. |
||
Shows the editor and hides any textarea/div that the editor is supposed to replace. |
||
Translates the specified string by replacing variables with language pack items it will also check if there is a key matching the input. |
||
Uploads all data uri/blob uri images in the editor contents to server. |
public constructor function Editor(id: String, settings: Object, editorManager: tinymce.EditorManager)Constructs a editor instance by id.
-
id (String)- Unique id for the editor. -
settings (Object)- Settings for the editor. -
editorManager (EditorManager)- EditorManager instance.
addCommand(name: String, callback: addCommandCallback, scope: Object)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.
// Adds a custom command that later can be executed using execCommand
tinymce.init({
...
setup: function(ed) {
// Register example command
ed.addCommand('mycommand', function(ui, v) {
ed.windowManager.alert('Hello world!! Selection: ' + ed.selection.getContent({format: 'text'}));
});
}
});addQueryStateHandler(name: String, callback: addQueryStateHandlerCallback, scope: Object)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.
addQueryValueHandler(name: String, callback: addQueryValueHandlerCallback, scope: Object)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.
addShortcut(pattern: String, desc: String, cmdFunc: String | Function, scope: Object): BooleanAdds a keyboard shortcut for some command or function.
editor.addShortcut('ctrl+a', "description of the shortcut", function() {});
editor.addShortcut('ctrl+alt+a', "description of the shortcut", function() {});
// "meta" maps to Command on Mac and Ctrl on PC
editor.addShortcut('meta+a', "description of the shortcut", function() {});
// "access" maps to Control+Option on Mac and shift+alt on PC
editor.addShortcut('access+a', "description of the shortcut", function() {});
editor.addShortcut(
'meta+access+c', 'Opens the code editor dialog.', function () {
editor.execCommand('mceCodeEditor');
});
editor.addShortcut(
'meta+shift+32', 'Inserts "Hello, World!" for meta+shift+space', function () {
editor.execCommand('mceInsertContent', false, 'Hello, World!');
});-
pattern (String)- Shortcut pattern. Like for example: ctrl+alt+o. -
desc (String)- Text description for the command. -
cmdFunc (String | Function)- Command name string or function to execute when the key is pressed. -
scope (Object)- Optional scope to execute the function in.
addVisual(elm: Element)Adds visual aid for tables, anchors etc so they can be more easily edited inside the editor.
convertURL(url: string, name: string, elm: string | HTMLElement): stringURL 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.
-
url (string)- URL to convert. -
name (string)- Attribute name src, href etc. -
elm (string | HTMLElement)- Tag name or HTML DOM element depending on HTML or DOM insert.
destroy(automatic: Boolean)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.
execCallback(name: String): ObjectExecutes 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.
Deprecated in TinyMCE 5.10 and has been marked for removal in TinyMCE 6.0.
execCommand(cmd: String, ui: Boolean, value: mixed, args: Object)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.
fire(name: String, args: Object?, bubble: Boolean?): ObjectFires the specified event by name. Consult the event reference for more details on each event.
-
name (String)- Name of the event to fire. -
args (Object?)- Event arguments. -
bubble (Boolean?)- True/false if the event is to be bubbled.
focus(skipFocus: Boolean)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.
getBody(): ElementReturns the root element of the editable area. For a non-inline iframe-based editor, returns the iframe’s body element.
getContainer(): ElementReturns the container element of the editor. The container element includes all the elements added to the page for the editor. Such as UI, iframe, etc.
getContent(args: Object): StringGets the content from the editor instance, this will cleanup the content before it gets returned using the different cleanup rules options.
// Get the HTML contents of the currently active editor
console.debug(tinymce.activeEditor.getContent());
// Get the contents of the currently active editor as plain text
tinymce.activeEditor.getContent({format: 'text'});
// Get content of a specific editor:
tinymce.get('content id').getContent()-
args (Object)- Optional content object, this gets passed around through the whole get process.
getContentAreaContainer(): ElementReturns the content area container element of the editor. This element holds the iframe or the editable element.
getDoc(): DocumentReturns the iframes document object.
getElement(): ElementReturns the target element/textarea that got replaced with a TinyMCE editor instance.
getParam(name: String, defaultVal: String, type: String): StringReturns a configuration parameter by name.
// Returns a specific config value from the currently active editor
var someval = tinymce.activeEditor.getParam('myvalue');
// Returns a specific config value from a specific editor instance by id
var someval2 = tinymce.get('my_editor').getParam('myvalue');-
name (String)- Configruation parameter to retrieve. -
defaultVal (String)- Optional default value to return. -
type (String)- Optional type parameter.
getWin(): WindowReturns the iframes window object.
hasEventListeners(name: String): BooleanReturns true/false if the object has a event of the specified name.
hasFocus(): BooleanReturns true/false if the editor has real keyboard focus.
hasPlugin(name: String, loaded: Boolean): BooleanChecks that the plugin is in the editor configuration and can optionally check if the plugin has been loaded.
Added in TinyMCE 5.5
// Returns `true` if the Comments plugin is in the editor configuration and has loaded successfully:
tinymce.activeEditor.hasPlugin('tinycomments', true);
// Returns `true` if the Table plugin is in the editor configuration, regardless of whether or not it loads:
tinymce.activeEditor.hasPlugin('table');-
name (String)- The name of the plugin, as specified for the TinyMCEpluginsoption. -
loaded (Boolean)- Iftrue, will also check that the plugin has been loaded.
insertContent(content: String, args: Object)Inserts content at caret position.
isDirty(): BooleanReturns true/false if the editor is dirty or not. It will get dirty if the user has made modifications to the contents.
The dirty state is automatically set to true when the user modifies editor content after initialization or the
last editor.save() call. This includes changes made using undo or redo.
isHidden()
isHidden(): BooleanReturns true/false if the editor is hidden or not.
load(args: Object): StringLoads contents from the textarea, input or other element that got converted into an editor instance. This method will move the contents from that textarea, input or other element into the editor by using setContent so all events etc that method has will get dispatched as well.
-
args (Object)- Optional content object, this gets passed around through the whole load process.
nodeChanged(args: Object)Dispatches out a onNodeChange event to all observers. This method should be called when you need to update the UI states or element path etc.
off(name: String?, callback: callback?): ObjectUnbinds an event listener to a specific event by name. Consult the event reference for more details on each event.
// Unbind specific callback
instance.off('event', handler);
// Unbind all listeners by name
instance.off('event');
// Unbind all events
instance.off();on(name: String, callback: callback, prepend: Boolean): ObjectBinds an event listener to a specific event by name. Consult the event reference for more details on each event.
-
name (String)- Event name or space separated list of events to bind. -
callback (callback)- Callback to be executed when the event occurs. -
prepend (Boolean)- Optional flag if the event should be prepended. Use this with care.
once(name: String, callback: callback): ObjectBind the event callback and once it fires the callback is removed. Consult the event reference for more details on each event.
-
name (String)- Name of the event to bind. -
callback (callback)- Callback to bind only once.
queryCommandState(cmd: string): BooleanReturns a command specific state, for example if bold is enabled or not.
queryCommandSupported(cmd: String): BooleanReturns true/false if the command is supported or not.
queryCommandValue(cmd: string): ObjectReturns a command specific value, for example the current font size.
resetContent(initialContent: String)Resets the editors content, undo/redo history and dirty state. If initialContent isn’t specified, then
the editor is reset back to the initial start content.
save(args: Object): StringSaves the contents from an 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.
-
args (Object)- Optional content object, this gets passed around through the whole save process.
setContent(content: String, args: Object): StringSets the specified content to the editor instance, this will cleanup the content before it gets set using the different cleanup rules options.
// Sets the HTML contents of the activeEditor editor
tinymce.activeEditor.setContent('<span>some</span> html');
// Sets the content of a specific editor (my_editor in this example)
tinymce.get('my_editor').setContent(data);
// Sets the content of the activeEditor editor using the specified format
tinymce.activeEditor.setContent('<p>Some html</p>', {format: 'html'});-
content (String)- Content to set to editor, normally HTML contents but can be other formats as well. -
args (Object)- Optional content object, this gets passed around through the whole set process.
setDirty(state: Boolean)Explicitly sets the dirty state. This will fire the dirty event if the editor dirty state is changed from false to true by invoking this method.
function ajaxSave() {
var editor = tinymce.get('elm1');
// Save contents using some XHR call
alert(editor.getContent());
editor.setDirty(false); // Force not dirty state
}setMode(mode: String)Sets the editor mode. For example: "design", "code" or "readonly".
Deprecated in TinyMCE 5.0.4 and has been marked for removal in TinyMCE 6.0 - Use editor.mode.set(mode) instead.
setProgressState(state: Boolean, time: Number): BooleanSets the progress state, this will display a throbber/progess for the editor. This is ideal for asynchronous operations like an AJAX save call.
// Show progress for the active editor
tinymce.activeEditor.setProgressState(true);
// Hide progress for the active editor
tinymce.activeEditor.setProgressState(false);
// Show progress after 3 seconds
tinymce.activeEditor.setProgressState(true, 3000);-
state (Boolean)- Boolean state if the progress should be shown or hidden. -
time (Number)- Optional time to wait before the progress gets shown.
translate(text: String): StringTranslates the specified string by replacing variables with language pack items it will also check if there is a key matching the input.