Skip to content

Latest commit

 

History

History
686 lines (510 loc) · 29.9 KB

File metadata and controls

686 lines (510 loc) · 29.9 KB

Commands Available for {productname}

Executable commands

The following tables show the existing editor commands. These commands are provided by tinymce and not by the browser’s internal commands. These commands can be executed using the execCommand function.

Listing core and plugin editor commands

To retrieve a list of available commands from the active editor, run the following command from the browser console:

tinymce.activeEditor.editorCommands.commands.exec;

Core Editor commands

Supported browser-native commands

The commands in the following table are provided by the {productname} editor and provide the same or similar functionality to the native browser commands.

Command Description

Bold

Toggles bold formatting to selection.

Italic

Toggles italic formatting to selection.

Underline

Toggles underline formatting to selection.

Strikethrough

Toggles strikethrough formatting to selection.

Superscript

Toggles superscript formatting to selection.

Subscript

Toggles subscript formatting to selection.

Cut

Cuts the selected contents and puts in into users clipboard.

Copy

Copies the selected contents and puts in into users clipboard.

Paste

Pastes the current clipboard contents into the editor.

ForeColor

Changes the text color of the text. The value passed in should be the color.

BackColor

Changes the background color of the text. The value passed in should be the color.

JustifyLeft

Left aligns the current text block/image.

JustifyCenter

Center aligns the current text block/image.

JustifyRight

Right aligns the current text block/image.

JustifyFull

Full aligns the current text block/image.

FontName

Font name to apply to the text. The value passed in should be the font family name.

FontSize

Font size of the text. The value passed in should be a valid CSS font size.

FormatBlock

Toggles the format of the current selection. The value passed in should be the format name. If no format is specified, the paragraph (<p>) format will be toggled. For a list of options, see: Content formatting options - Built-in formats.

RemoveFormat

Removes any formats from the current selection.

Indent

Indents the current selection.

Outdent

Outdents the current selection.

CreateLink

Inserts a link at the current selection. The value is the URL to add to the link(s).

Unlink

Removes any links from the current selection.

InsertHorizontalRule

Inserts a horizontal rule at the cursor location or inplace of the current selection.

InsertParagraph

Inserts a new paragraph or new line at the current cursor or selection.

InsertText

Inserts the passed value as plain text at the current cursor or selection.

InsertHTML

Inserts the passed value as HTML at the current cursor or selection.

InsertImage

Adds an image <img src="..."> at the current cursor or selection.

SelectAll

Selects all content in the editor.

Delete

Deletes the current selection from the editor.

ForwardDelete

Deletes the current selection or the character to the right of the cursor for a collapsed selection.

Redo

Redoes the last change to the editor.

Undo

Undoes the last change to the editor.

Examples
tinymce.activeEditor.execCommand('Bold');
tinymce.activeEditor.execCommand('Italic');
tinymce.activeEditor.execCommand('Underline');
tinymce.activeEditor.execCommand('Strikethrough');
tinymce.activeEditor.execCommand('Superscript');
tinymce.activeEditor.execCommand('Subscript');
tinymce.activeEditor.execCommand('Cut');
tinymce.activeEditor.execCommand('Copy');
tinymce.activeEditor.execCommand('Paste');
tinymce.activeEditor.execCommand('JustifyLeft');
tinymce.activeEditor.execCommand('JustifyCenter');
tinymce.activeEditor.execCommand('JustifyRight');
tinymce.activeEditor.execCommand('JustifyFull');
tinymce.activeEditor.execCommand('ForeColor', false, '#FF0000');
tinymce.activeEditor.execCommand('BackColor', false, '#FF0000');
tinymce.activeEditor.execCommand('FontName', false, 'courier new');
tinymce.activeEditor.execCommand('FontSize', false, '30px');
tinymce.activeEditor.execCommand('FormatBlock', false, 'bold');
tinymce.activeEditor.execCommand('RemoveFormat');
tinymce.activeEditor.execCommand('Indent');
tinymce.activeEditor.execCommand('Outdent');
tinymce.activeEditor.execCommand('CreateLink', false, 'https://www.tiny.cloud');
tinymce.activeEditor.execCommand('Unlink');
tinymce.activeEditor.execCommand('InsertHorizontalRule');
tinymce.activeEditor.execCommand('InsertParagraph');
tinymce.activeEditor.execCommand('InsertText', false, 'My text content');
tinymce.activeEditor.execCommand('InsertHTML', false, 'My HTML content');
tinymce.activeEditor.execCommand('InsertImage', false, 'https://www.example.com/image.png');
tinymce.activeEditor.execCommand('SelectAll');
tinymce.activeEditor.execCommand('Delete');
tinymce.activeEditor.execCommand('ForwardDelete');
tinymce.activeEditor.execCommand('Redo');
tinymce.activeEditor.execCommand('Undo');

Miscellaneous Core Commands

The commands in the following table are provided by the {productname} editor and provide additional functionality that does not require any plugins to be enabled.

Command Description

HiliteColor

Changes the background color of the text. The value passed in should be the color. NOTE: This is an alias for the BackColor command.

InsertLineBreak

Adds a line break <br> at the current cursor or selection.

InsertNewBlockAfter

inserts an empty block at the root level of the current {productname} document immediately after the block containing the current selection.

InsertNewBlockBefore

inserts an empty block at the root level of the current {productname} document immediately before the block containing the current selection.

JustifyNone

Removes any alignment to the selected text.

Lang

Sets the language of the current selection. The value passed in should be a language spec described in Content appearance options - content_langs.

LineHeight

Sets the line height of the text. The value passed in should be a valid CSS line height.

mceAddUndoLevel

Adds an undo level.

mceApplyTextcolor

Applies text color or background color to the current selection. Requires an argument of either 'hilitecolor' or 'forecolor', and the value of the color.

mceAutocompleterClose

Closes any active autocompleter menu.

mceAutocompleterReload

Reloads the autocompleter menu with new items. For the data to provide, see the Autocompleter reload API.

mceBlockQuote

Wraps the selected text blocks into a block quote.

mceCleanup

Copies the current editor content and sets the content using the copy.

mceEndUndoLevel

Adds an undo level.

mceFocus

Focuses and activates the editor. Places DOM focus inside the editor and also sets the editor as the active editor instance on the page.

mceInsertClipboardContent

Triggers a paste event at the cursor location or over the current selection. The command requires an object with: html containing the HTML content, or text containing plain text.

mceInsertContent

Inserts contents at the current selection. The value passed in should be the contents to be inserted.

mceInsertLink

Inserts a link at the current selection. The value is the URL to add to the link(s). NOTE: This is an alias for the CreateLink command.

mceInsertNewLine

Adds a new line at the current cursor or selection, such as splitting the current paragraph element. The behavior of this setting can be controlled with the newline_behavior option.

mceNewDocument

Removes all contents of the editor.

mcePrint

Opens the browser’s print dialog for the current page.

mceRemoveNode

Removes the current node or the target node passed as the value (<DOM_node>).

mceRemoveTextcolor

Removes the text color or background color from the current selection. Requires an argument of either 'hilitecolor' or 'forecolor'.

mceReplaceContent

Replaces the current selection. The value passed in should be the new content.

mceSelectNode

Selects a node in the editor. The target node is passed as the value (<DOM_node>).

mceSelectNodeDepth

Selects the parent DOM node 'n' levels above the current node.

mceSetContent

Sets the contents of the editor. The value is the contents to set as the editor contents.

mceToggleFormat

Toggles a specified format by name. The value is the name of the format to toggle. For a list of options, see: Content formatting options - Built-in formats.

mceTogglePlainTextPaste

Toggles paste as plain text.

mceToggleVisualAid

Toggles the visual aids for: tables without borders and anchors.

ToggleSidebar

Closes the current sidebar, or toggles the sidebar if the sidebar name is provided as a value (<sidebar-name>).

ToggleToolbarDrawer

Toggles the Toolbar Drawer. Can be used with the skip_focus option to prevent focusing the editor. For information on toolbars, see: User interface options - Toolbar.

Examples
tinymce.activeEditor.execCommand('HiliteColor', false, '#FF0000');
tinymce.activeEditor.execCommand('InsertLineBreak');
tinymce.activeEditor.execCommand('InsertNewBlockAfter')
tinymce.activeEditor.execCommand('InsertNewBlockBefore')
tinymce.activeEditor.execCommand('JustifyNone');
tinymce.activeEditor.execCommand('Lang', false, { code: 'en_US' });  /* OR */
tinymce.activeEditor.execCommand('Lang', false, { code: 'en_US', customCode: 'en-us-medical' });
tinymce.activeEditor.execCommand('LineHeight', false, '1.4');
tinymce.activeEditor.execCommand('mceAddUndoLevel');
tinymce.activeEditor.execCommand('mceApplyTextcolor', 'hilitecolor', '#FF0000');
tinymce.activeEditor.execCommand('mceAutocompleterClose');
tinymce.activeEditor.execCommand('mceAutocompleterReload', false, {
  fetchOptions: {}
});
tinymce.activeEditor.execCommand('mceBlockQuote');
tinymce.activeEditor.execCommand('mceCleanup');
tinymce.activeEditor.execCommand('mceEndUndoLevel');
tinymce.activeEditor.execCommand('mceFocus');
tinymce.activeEditor.execCommand('mceInsertClipboardContent', false, {
  html: '<p>Hello, World!</p>'
});
tinymce.activeEditor.execCommand('mceInsertContent', false, 'My new content');
tinymce.activeEditor.execCommand('mceInsertLink', false, 'https://www.tiny.cloud');
tinymce.activeEditor.execCommand('mceInsertNewLine');
tinymce.activeEditor.execCommand('mceNewDocument');
tinymce.activeEditor.execCommand('mcePrint');
tinymce.activeEditor.execCommand('mceRemoveNode'); /* OR */
tinymce.activeEditor.execCommand('mceRemoveNode', false, '<DOM_node>');
tinymce.activeEditor.execCommand('mceSelectNode', false, '<DOM_node>');
tinymce.activeEditor.execCommand('mceSelectNodeDepth', false, 2); // For two nodes up.
tinymce.activeEditor.execCommand('mceSetContent', false, 'My content');
tinymce.activeEditor.execCommand('mceRemoveTextcolor', 'hilitecolor');
tinymce.activeEditor.execCommand('mceReplaceContent', false, 'My replacement content');
tinymce.activeEditor.execCommand('mceToggleFormat', false, 'bold');
tinymce.activeEditor.execCommand('mceTogglePlainTextPaste');
tinymce.activeEditor.execCommand('mceToggleVisualAid');
tinymce.activeEditor.execCommand('ToggleSidebar');  /* OR */
tinymce.activeEditor.execCommand('ToggleSidebar', false, '<sidebar-name>');
tinymce.activeEditor.execCommand('ToggleToolbarDrawer', false, null, { skip_focus: true });

Plugin Commands

Commands are available for the following plugins:

Advanced Lists

The following commands require the Advanced Lists (advlist) plugin.

[[Enhanced Tables]] ==== Enhanced Tables

The following commands require the Enhanced Tables (advtable) plugin.

Anchor

The following command requires the Anchor (anchor) plugin.

Autoresize

The following command requires the Autoresize (autoresize) plugin.

Case Change

The following commands require the Case Change (casechange) plugin.

Character Map

The following command requires the Character Map (charmap) plugin.

Code

The following command requires the Code (code) plugin.

Code Sample

The following command requires the Code Sample (codesample) plugin.

Comments

The following commands require the Comments (tinycomments) plugin.

Directionality

The following commands require the Directionality (directionality) plugin.

Enhanced Code Editor

The following command requires the Enhanced Code Editor (advcode) plugin.

Emoticons

The following commands require the Emoticons (emoticons) plugin.

Export to PDF

The following commands require the Export to PDF (exportpdf) plugin.

Export to Word

The following commands require the Export to Word (exportword) plugin.

Footnotes

The following commands require the Footnotes (footnotes) plugin.

Format Painter

The following commands require the Format Painter (formatpainter) plugin.

Full Screen

The following command requires the Full Screen (fullscreen) plugin and is only applicable when the editor is in classic mode.

Help

The following command requires the Help (help) plugin.

Image

The following command requires the Image (image) plugin.

Import from Word

The following command requires the Import from Word (importword) plugin.

Image Editing

The following commands require the Image Editing (editimage) plugin.

Insert Date/Time

The following commands require the Insert Date/Time (insertdatetime) plugin.

The following command requires the Link (link) plugin.

Lists

The following commands require the Lists (lists) plugin.

List Styles

The following commands require the List Styles (advlist) plugin.

Math

The following commands require the Math (math) plugin.

Media

The following command requires the Media (media) plugin.

Nonbreaking Space

The following command requires the Nonbreaking Space (nonbreaking) plugin.

Page Break

The following command requires the Page Break (pagebreak) plugin.

Permanent Pen

The following commands require the Permanent Pen (permanentpen) plugin.

PowerPaste

The following command requires the PowerPaste (powerpaste) plugin.

Preview

The following command requires the Preview (preview) plugin.

Revision History

The following commands require the Revision History (revisionhistory) plugin.

Save

The following commands require the Save (save) plugin.

Search and Replace

The following command requires the Search and Replace (searchreplace) plugin.

Spell Checker

The following commands require the Spell Checker (tinymcespellchecker) plugin.

Table

For additional commands that are provided by the core table functionality, see Core Table Commands.

The following commands require the Table (table) plugin.

Table of Contents

The following commands require the Table of Contents (tableofcontents) plugin.

Templates

The following commands require the Templates (advtemplate) plugin.

Visual Blocks

The following command requires the Visual Blocks (visualblocks) plugin.

Visual Characters

The following command requires the Visual Characters (visualchars) plugin.

Word Count

The following command requires the Word Count (wordcount) plugin.

Editor Management Commands

The following commands are used to manage editor instances.

For example:

tinymce.execCommand('mceAddEditor', false, { id: '<editor_id>', options: {} });
tinymce.execCommand('mceRemoveEditor', false, '<editor_id>');
tinymce.execCommand('mceToggleEditor', false, { id: '<editor_id>' });
tinymce.execCommand('mceToggleEditor', false, { index: '<editor_index>' });
Command Description

mceAddEditor

Converts an HTML or DOM element with the specified ID into an editor instance that uses the specified editor configuration options. For information on configuring the editor, see: Basic Setup.

mceRemoveEditor

Removes an editor instance with the specified ID.

mceToggleEditor

Runs mceAddEditor if an editor is not detected for the specified ID, otherwise it runs either hide if the editor is visible or show if it is not visible.

Query command states

{productname} provides the queryCommandState API to allow developers to determine the current state of selected content. The query will return true if the content is formatted using the same CSS styles and elements used by the corresponding command.

Listing core and plugin query command states

To retrieve a list of avaliable queryable states from the active editor, run the following command from the browser console:

tinymce.activeEditor.editorCommands.commands.state;

Available query command states

The following command states can be queried using the queryCommandState API.

Command Description

Bold

Returns true if the content is formatted using the same markup as the {productname} Bold command.

InsertDefinitionList

Returns true if the content is formatted using the same markup as the {productname} InsertDefinitionList command.

InsertOrderedList

Returns true if the content is formatted using the same markup as the {productname} InsertOrderedList command.

InsertUnorderedList

Returns true if the content is formatted using the same markup as the {productname} InsertUnorderedList command.

Italic

Returns true if the content is formatted using the same markup as the {productname} Italic command.

JustifyCenter

Returns true if the content is formatted using the same markup as the {productname} JustifyCenter command.

JustifyFull

Returns true if the content is formatted using the same markup as the {productname} JustifyFull command.

JustifyLeft

Returns true if the content is formatted using the same markup as the {productname} JustifyLeft command.

JustifyRight

Returns true if the content is formatted using the same markup as the {productname} JustifyRight command.

mceBlockQuote

Returns true if the content is formatted using the same markup as the {productname} mceBlockQuote command.

mceTogglePlainTextPaste

Returns true if the {productname} mceTogglePlainTextPaste command is active.

Outdent

Returns true if the content is formatted using the same markup as the {productname} Outdent command.

Strikethrough

Returns true if the content is formatted using the same markup as the {productname} Strikethrough command.

Subscript

Returns true if the content is formatted using the same markup as the {productname} Subscript command.

Superscript

Returns true if the content is formatted using the same markup as the {productname} Superscript command.

ToggleToolbarDrawer

Returns true if the Toolbar Drawer is open. The state can be controlled by the {productname} ToggleToolbarDrawer command. When controlling the state, use the skip_focus option (recommended) instead of the deprecated skipFocus option.

Underline

Returns true if the content is formatted using the same markup as the {productname} Underline command.

Examples
tinymce.activeEditor.queryCommandState('Bold');
tinymce.activeEditor.queryCommandState('InsertDefinitionList');
tinymce.activeEditor.queryCommandState('InsertOrderedList');
tinymce.activeEditor.queryCommandState('InsertUnorderedList');
tinymce.activeEditor.queryCommandState('Italic');
tinymce.activeEditor.queryCommandState('JustifyCenter');
tinymce.activeEditor.queryCommandState('JustifyFull');
tinymce.activeEditor.queryCommandState('JustifyLeft');
tinymce.activeEditor.queryCommandState('JustifyRight');
tinymce.activeEditor.queryCommandState('mceBlockQuote');
tinymce.activeEditor.queryCommandState('mceTogglePlainTextPaste');
tinymce.activeEditor.queryCommandState('Outdent');
tinymce.activeEditor.queryCommandState('Strikethrough');
tinymce.activeEditor.queryCommandState('Subscript');
tinymce.activeEditor.queryCommandState('Superscript');
tinymce.activeEditor.queryCommandState('ToggleToolbarDrawer');
tinymce.activeEditor.queryCommandState('Underline');

Query command values

{productname} provides the queryCommandValue API to allow developers to determine the current state of selected content. The query will return an object containing the relevant value.

Listing core and plugin query command values

To retrieve a list of available queryable command values from the active editor, run the following command from the browser console:

tinymce.activeEditor.editorCommands.commands.value;

Available query command values

The following command values can be queried using the queryCommandValue API.

Command Description

FontName

Returns the font name of the current selection.

FontSize

Returns the font size of the current selection.

LineHeight

Returns the line height of the current selection.

ToggleSidebar

Returns the current state of sidebar (open or closed).

ToggleView

Returns the current state of the view, for example: "code", or "revision".

Examples
tinymce.activeEditor.queryCommandValue('FontName');
tinymce.activeEditor.queryCommandValue('FontSize');
tinymce.activeEditor.queryCommandValue('LineHeight');
tinymce.activeEditor.queryCommandValue('ToggleSidebar');
tinymce.activeEditor.queryCommandValue('ToggleView');

Query command values for tables