Skip to content

Latest commit

 

History

History
770 lines (530 loc) · 25 KB

File metadata and controls

770 lines (530 loc) · 25 KB

Commands Available for TinyMCE

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 avaliable commands from the active editor, run the following command from the browser console:

tinymce.activeEditor.editorCommands.commands.exec;

Core Editor commands

The commands on the following table are provided by the {productname} editor and do not require any plugins to be enabled.

Command Description

Bold

Toggles bold formatting to selection.

Italic

Toggles italic formatting to selection.

Underline

Toggles underline formatting to selection.

Strikethrough

Toggles strikethough 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.

Lang

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

Paste

Pastes the current clipboard contents into the editor.

mceInsertLink

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.

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.

JustifyNone

Removes any alignment to the selected text.

ForeColor

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

HiliteColor

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

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.

LineHeight

Sets the line height of the text. The value passed in should be a valid CSS line height. partial$misc/requires_5_5v.adoc

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.

mceRemoveTextcolor

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

RemoveFormat

Removes any formats from the current selection.

mceBlockQuote

Wraps the selected text blocks into a block quote.

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.

mceInsertContent

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

mceReplaceContent

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

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.

ToggleSidebar

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

ToggleToolbarDrawer

Toggles the Toolbar Drawer. For information on toolbars, see: User interface options - Toolbar. partial$misc/requires_5_5v.adoc

Indent

Indents the current selection.

Outdent

Outdents the current selection.

InsertHorizontalRule

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

InsertLineBreak

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

mceInsertNewLine

Adds a new line at the current cursor or selection, such as splitting the current paragraph element.

mceInsertRawHTML

Inserts the RAW HTML passed as a value, overwriting the current selection or at the cursor position. Warning: This command allows dangerous <script> elements to be added to and executed in the editor.

mceToggleVisualAid

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

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.

mceNewDocument

Removes all contents of the editor.

Redo

Redoes the last change to the editor.

Undo

Undoes the last change to the editor.

mceAddUndoLevel

Adds an undo level.

mceEndUndoLevel

Adds an undo level.

mceCleanup

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

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.

mceRemoveNode

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

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. partial$misc/requires_5_9v.adoc

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('mceInsertLink', false, 'https://www.tiny.cloud');
tinymce.activeEditor.execCommand('Unlink');
tinymce.activeEditor.execCommand('JustifyLeft');
tinymce.activeEditor.execCommand('JustifyCenter');
tinymce.activeEditor.execCommand('JustifyRight');
tinymce.activeEditor.execCommand('JustifyFull');
tinymce.activeEditor.execCommand('JustifyNone');
tinymce.activeEditor.execCommand('ForeColor', false, '#FF0000');
tinymce.activeEditor.execCommand('HiliteColor', false, '#FF0000');
tinymce.activeEditor.execCommand('FontName', false, 'courier new');
tinymce.activeEditor.execCommand('FontSize', false, '30px');
tinymce.activeEditor.execCommand('LineHeight', false, '1.4');
tinymce.activeEditor.execCommand('mceApplyTextcolor', 'hilitecolor', '#FF0000');
tinymce.activeEditor.execCommand('mceRemoveTextcolor', 'hilitecolor');
tinymce.activeEditor.execCommand('RemoveFormat');
tinymce.activeEditor.execCommand('mceBlockQuote');
tinymce.activeEditor.execCommand('FormatBlock', false, 'bold');
tinymce.activeEditor.execCommand('mceInsertContent', false, 'My new content');
tinymce.activeEditor.execCommand('mceReplaceContent', false, 'My replacement content');
tinymce.activeEditor.execCommand('mceSetContent', false, 'My content');
tinymce.activeEditor.execCommand('mceToggleFormat', false, 'bold');
tinymce.activeEditor.execCommand('ToggleSidebar');  /* OR */
tinymce.activeEditor.execCommand('ToggleSidebar', false, '<sidebar-name>');
tinymce.activeEditor.execCommand('ToggleToolbarDrawer');
tinymce.activeEditor.execCommand('Indent');
tinymce.activeEditor.execCommand('Outdent');
tinymce.activeEditor.execCommand('InsertHorizontalRule');
tinymce.activeEditor.execCommand('InsertLineBreak');
tinymce.activeEditor.execCommand('mceInsertNewLine');
tinymce.activeEditor.execCommand('mceInsertRawHTML', false, '<p>Hello, World!</p>');
tinymce.activeEditor.execCommand('mceToggleVisualAid');
tinymce.activeEditor.execCommand('SelectAll');
tinymce.activeEditor.execCommand('Delete');
tinymce.activeEditor.execCommand('ForwardDelete');
tinymce.activeEditor.execCommand('mceNewDocument');
tinymce.activeEditor.execCommand('Redo');
tinymce.activeEditor.execCommand('Undo');
tinymce.activeEditor.execCommand('mceAddUndoLevel');
tinymce.activeEditor.execCommand('mceEndUndoLevel');
tinymce.activeEditor.execCommand('mceCleanup');
tinymce.activeEditor.execCommand('mceSelectNode', false, '<DOM_node>');
tinymce.activeEditor.execCommand('mceSelectNodeDepth', false, 2); // For two nodes up.
tinymce.activeEditor.execCommand('mceRemoveNode'); /* OR */
tinymce.activeEditor.execCommand('mceRemoveNode', false, '<DOM_node>');
tinymce.activeEditor.execCommand('mceFocus');

Plugin Commands

Commands are available for the following plugins:

Advanced Code

The following command requires the Advanced Code (advcode) plugin.

Advanced Lists

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

Advanced Tables

The following commands require the Advanced 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.

Emoticons

The following commands require the Emoticons (emoticons) plugin.

Export

The following commands require the Export (export) plugin.

Format Painter

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

Full Screen

The following command requires the Full Screen (fullscreen) plugin.

Help

The following command requires the Help (help) plugin.

Image

The following command requires the Image (image) plugin.

Image Tools

The following commands require the Image Tools (imagetools) 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.

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.

Paste

The following commands require the Paste (paste) 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.

Print

The following command requires the Print (print) 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 Pro

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

Table

The following commands require the Table (table) plugin.

Template

The following command requires the Template (template) plugin.

Table of Contents

The following commands require the Table of Contents (toc) 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, '<editor_id>');
tinymce.execCommand('mceRemoveEditor', false, '<editor_id>');
tinymce.execCommand('mceToggleEditor', false, '<editor_id>');
Command Description

mceAddEditor

Converts the specified HTML or DOM element into an editor instance with the specified ID.

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.

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. partial$misc/requires_5_5v.adoc

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('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 avaliable 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. partial$misc/requires_5_5v.adoc

ToggleSidebar

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

Examples

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

Query command values: Table plugin