Remotely call TinyMCE toolbar commands – List of executable instance commands

There are two types of commands can be called within TinyMCE, the Global Commands and the Instance Commands,

Global commands are independent of any editor instance (focusing a specific editor or adding a new editor to a textarea, for example). Instance commands are for a specific editor instance (making the current selection in a specific editor bold, for example).

http://wiki.moxiecode.com/index.php/TinyMCE:Commands

The wiki page has a good range of instance commands covered, but I was unable to locate those I wanted and some took me a while to find, in this post I’m going to list the typical instance commands, this is particular useful if you are building elements outside the editor, e.g. An external toolbar. The list applies to TinyMCE version 3.

tinyMCE.execCommand(command, user_interface, value)

For example, to execute the command mceSave

tinyMCE.activeEditor.execCommand('mceSave', false, null)

I’m using the activeEditor at the moment but feel free to replace this if you have more than one editor on the same page.

Name Command user_interface, value
Save mceSave false, null
Undo Undo false, null
Redo Redo false, null
Select all SelectAll false, null
Find and Replace mceSearch false, null
Edit HTML mceCodeEditor false, null
Full Screen mceFullScreen false, null
Insert Row Before mceTableInsertRowBefore false, null
Insert Row After mceTableInsertRowAfter false, null
Delete Row mceTableDeleteRow false, null
Insert Column Before mceTableInsertColBefore false, null
Insert Column After mceTableInsertColAfter false, null
Delete Column mceTableDeleteCol false, null
Delete Table mceTableDelete false, null
Align Left JustifyLeft false, null
Align Center JustifyCenter false, null
Align Right JustifyRight false, null
Justified JustifyFull false, null
Paragraph – Normal formatBlock false, ‘p’
Paragraph – Heading 1 formatBlock false, ‘h1′
Paragraph – Heading 2 formatBlock false, ‘h2′
Strikethrough StrikeThrough false, null
Superscript Superscript false, null
Subscript Subscript false, null
Clear Format removeFormat

For any other commands or calling a custom plugin, it’s pretty easy to find, go to the plugins directory – javascript/tinymce/jscrips/tinymce/plugins
And find the editor_plugin_src.js, and in that file find the line

ed.addCommand('mceExample', function() {
..

This line registers the command, so that you can call

tinyMCE.activeEditor.execCommand('mceExample');

to trigger this.

3 Responses to “Remotely call TinyMCE toolbar commands – List of executable instance commands”

Leave a Reply