# TinyMCE

Object
TinyMCE_Control

### Class TinyMCE_Control

Field Summary
TinyMCE_Cleanup | cleanup Cleanup engine reference, handles all XHTML serialization and cleanup.
TinyMCE_Selection | selection Contains methods for handling the current instance selection.
Array | settings Name/Value array containing all instance settings.

Constructor Summary
TinyMCE_Control(<Array> settings) This is the TinyMCE editor control instance class.

Method Summary
void | addPlugin(<string> n, <TinyMCE_Plugin> n) Adds a plugin to the editor instance.
boolean | addShortcut(<string> m, <Object> k, <string> d, <string> cmd, <boolean> ui, <Object> va) Adds a keyboard shortcut to a specific command.
void | autoResetDesignMode() Auto resets the design mode of the document if it gets lost.
void | execCommand(<string> command, <boolean> user_interface, <mixed> value) Executes a command on the current instance.
HTMLElement | getBody() Returns the body element of a editor instance.
DOMDocument | getContainerWin() Returns the container window of a editor instance.
Object | getData(<String> na) Get custom data storage object by name.
DOMDocument | getDoc() Returns the DOM document of a editor instance.
HTMLElement | getFocusElement() Returns the currently selected element.
string | getHTML(<bool> r) Returns the cleaned HTML of the editor control instance.
HTMLElement | getParentBlockElement(<HTMLNode> n) Returns the first block element parent of the specified node.
HTMLElement | getParentElement(<HTMLNode> node, <string> na, <function> f) Returns the parent element of the specified node based on the search criteria.
DOMNode | getParentNode(<DOMNode> n, <function> f) Returns a node by the specified selector function.
DOMRange | getRng() Returns the browsers selections first range instance.
DOMSelection | getSel() Returns the browsers selection instance.
Object | getViewPort() Returns the viewport of the editor instance.
Window | getWin() Returns the window of a editor instance.
boolean | handleShortcut(<DOMEvent> e) Executes shortcuts based on the event information.
boolean | hasPlugin(<string> n) Returns true/false if the instance has the current plugin available.
boolean | isDirty() Returns true/false if the editor instance is dirty or not.
boolean | isHidden() Returns if the instance is hidden or not.
boolean | queryCommandState(<string> c) Returns a command specific state, for example if bold is enabled or not.
mixed | queryCommandValue(<string> c) Returns a command specific value, for example the current font size.
void | repaint() Repaints the editarea in Gecko browsers.
void | resizeToContent() Auto resizes the current editor instance to match the inner document size.
void | select() Selects this instance as the currently selected instance.
void | setBaseHREF(<string> u) Sets the base href url of the current document instance.
void | setHTML(<string> h) Sets the HTML contents of the instance.
void | switchSettings() Switches the global TinyMCE settings to the current instance settings.
void | triggerSave(<boolean> skip_cleanup, <boolean> skip_callback) Moves the contents from the TinyMCE editor control instance to the hidden textarea that got replaced with TinyMCE.

### Field Detail

#### cleanup

TinyMCE_Cleanup cleanup
Cleanup engine reference, handles all XHTML serialization and cleanup.

#### selection

TinyMCE_Selection selection
Contains methods for handling the current instance selection.

#### settings

Array settings
Name/Value array containing all instance settings.

### Constructor Detail

#### TinyMCE_Control

TinyMCE_Control(<Array> settings)
This is the TinyMCE editor control instance class. A instance of this class will is made for each converted text area.

#### Parameters

settings - Name/Value array of instance specific configuration settings.

### Method Detail

#### addPlugin

void addPlugin(<string> n, <TinyMCE_Plugin> n)
Adds a plugin to the editor instance. This will also add it globaly.

#### Parameters

n - Plugin name to check for.
n - TinyMCE plugin instance.

#### addShortcut

boolean addShortcut(<string> m, <Object> k, <string> d, <string> cmd, <boolean> ui, <Object> va)
Adds a keyboard shortcut to a specific command. These shortcuts can for example be added at the initInstance callback of a plugin. The shortcut description can be a language variable name or a string describing the function. If you don't specify a command, the shortcut will simply be a blocker shortcut. This enables you to remove built in shortcuts or remove theme specific shortcuts from a plugin.
Example shortcut inst.addShortcut('ctrl,alt', 'k', 'mceSomeCommand', false, 'somevalue'); Example blocker inst.addShortcut('ctrl,alt', 'k');

#### Parameters

m - List of shortcut modifiers keys, for example "ctrl,alt".
k - Shortcut key char for example "s" or a keycode value "13".
d - Optional Shortcut description, this will be presented in the about dialog.
cmd - Optional Command name to execute, for example mceLink or Bold.
ui - Optional True/false state if a UI (dialog) should be presented or not.
va - Optional command value, this can be anything.

#### Returns

true/false if the shortcut was added or not

#### autoResetDesignMode

void autoResetDesignMode()
Auto resets the design mode of the document if it gets lost. This is a Gecko specific function since it's a workaround for a bug where Gecko browsers loose the designMode state if the editor is hidden and shown in a tab or div.

#### execCommand

void execCommand(<string> command, <boolean> user_interface, <mixed> value)
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.

#### Parameters

command - Command name to execute, for example mceLink or Bold.
user_interface - True/false state if a UI (dialog) should be presented or not.
value - Optional command value, this can be anything.

#### getBody

HTMLElement getBody()
Returns the body element of a editor instance.

#### Returns

Body element of a editor instance.

#### getContainerWin

DOMDocument getContainerWin()
Returns the container window of a editor instance. The container window is the window where the current instance lives in.

#### Returns

container window of a editor instance.

#### getData

Object getData(<String> na)
Get custom data storage object by name. The name should be for example the theme name or plugin name. The custom data storage can be used to store plugin/theme specific information on a editor instance. A empty object will be created automaticly the first time called.

#### Parameters

na - Name of data storate to retrive.

#### Returns

Data storage object

#### getDoc

DOMDocument getDoc()
Returns the DOM document of a editor instance.

#### Returns

DOM document of a editor instance.

#### getFocusElement

HTMLElement getFocusElement()
Returns the currently selected element. This is was added for compatiblity and is deprecated. Please use inst.selection.getFocusElement instead.

#### Returns

Currently selected element.

#### getHTML

string getHTML(<bool> r)
Returns the cleaned HTML of the editor control instance.

#### Parameters

r - Optional raw parameter, if set to true. Cleanup will be skipped.

#### Returns

Cleaned HTML content string.

#### getParentBlockElement

HTMLElement getParentBlockElement(<HTMLNode> n)
Returns the first block element parent of the specified node. This method will not go below the point of the instance body.

#### Parameters

n - Node get parent block element for.

#### Returns

First block element parent of the specified node or null if it wasn't found.

#### getParentElement

HTMLElement getParentElement(<HTMLNode> node, <string> na, <function> f)
Returns the parent element of the specified node based on the search criteria. This method will not go below the point of the instance body.

#### Parameters

node - Node to get parent element of.
na - Comma separated list of element names to get.
f - Optional function to call for each node, if it returns true the node is valid.

#### Returns

HTMLElement or null based on search criteras.

#### getParentNode

DOMNode getParentNode(<DOMNode> n, <function> f)
Returns a node by the specified selector function. This function will loop through all parent nodes and call the specified function for each node. If the function then returns true it will stop the execution and return that node. This function will not go below the instance body element.

#### Parameters

n - HTML node to search parents on.
f - Selection function to execute on each node.

#### Returns

DOMNode or null if it wasn't found.

#### getRng

DOMRange getRng()
Returns the browsers selections first range instance. This is was added for compatiblity and is deprecated. Please use inst.selection.getRng instead.

#### Returns

Browsers selections first range instance.

#### getSel

DOMSelection getSel()
Returns the browsers selection instance. This is was added for compatiblity and is deprecated. Please use inst.selection.getSel instead.

#### Returns

Browser selection instance.

#### getViewPort

Object getViewPort()
Returns the viewport of the editor instance.

#### Returns

Viewport object with fields top, left, width and height.

#### getWin

Window getWin()
Returns the window of a editor instance.

#### Returns

Window of a editor instance.

#### handleShortcut

boolean handleShortcut(<DOMEvent> e)
Executes shortcuts based on the event information.

#### Parameters

e - Keyboard event to handle.

#### Returns

true/false if the shortcut was found and executed or not.

#### hasPlugin

boolean hasPlugin(<string> n)
Returns true/false if the instance has the current plugin available.

#### Parameters

n - Plugin name to check for.

#### Returns

true/false if the instance has the current plugin available.

#### isDirty

boolean isDirty()
Returns true/false if the editor instance is dirty or not. In other words if it has been modified or not.

#### Returns

Editor instance dirty state.

#### isHidden

boolean isHidden()
Returns if the instance is hidden or not. This is a Gecko specific function other browsers will always return false. This function is used to workaround the lost designMode bug in Gecko browsers.

#### Returns

Returns if the instance is hidden or not.

#### queryCommandState

boolean queryCommandState(<string> c)
Returns a command specific state, for example if bold is enabled or not.

#### Parameters

c - Command to query state from.

#### Returns

Command specific state, for example if bold is enabled or not.

#### queryCommandValue

mixed queryCommandValue(<string> c)
Returns a command specific value, for example the current font size.

#### Parameters

c - Command to query value from.

#### Returns

Command specific value, for example the current font size.

#### repaint

void repaint()
Repaints the editarea in Gecko browsers. This method removes ghost resize handlers and other trailing graphics.

#### resizeToContent

void resizeToContent()
Auto resizes the current editor instance to match the inner document size.

#### select

void select()
Selects this instance as the currently selected instance. This will also dispatch a selectInstance call to all themes, plugins and other listeners.

#### setBaseHREF

void setBaseHREF(<string> u)
Sets the base href url of the current document instance. This method is used to temporarly remove the base url during copy/paste and drag/drop operations of relative links from external sites into TinyMCE. MSIE has a bug and converts relative links from external sites to absolute links incorrectly.

#### Parameters

u - URL to set as base URL or null to remove it.

#### setHTML

void setHTML(<string> h)
Sets the HTML contents of the instance.

#### Parameters

h - HTML content string to replace body with.

#### switchSettings

void switchSettings()
Switches the global TinyMCE settings to the current instance settings. This method is used to handle multiple configurations.

#### triggerSave

void triggerSave(<boolean> skip_cleanup, <boolean> skip_callback)
Moves the contents from the TinyMCE editor control instance to the hidden textarea that got replaced with TinyMCE. This is executed automaticly on for example form submit unless you configure otherwice.

#### Parameters

skip_cleanup - Optional Skip cleanup, simply move the contents as fast as possible.
skip_callback - Optional Skip callback, don't call the save_callback function.