tinymce.Formatter

Namespace tinymce
Class Formatter
Text formatter engine class. This class is used to apply formats like bold, italic, font size etc to the current selection or specific nodes. This engine was build to replace the browsers default formatting logic for execCommand due to it's inconsistant and buggy behavior.

Example

Public Methods

Method Defined By
apply(name:String, vars:Object, node:Node):void
Applies the specified format to the current selection or specified node.
Formatter
canApply(name:String):boolean
Returns true/false if the specified format can be applied to the current selection or not.
Formatter
formatChanged(formats:String, callback:function, similar:Boolean):void
Executes the specified callback when the current selection matches the formats or not.
Formatter
get(name:String):Array/Object
Returns the format by name or all formats if no name is specified.
Formatter
match(name:String, vars:Object, node:Node):boolean
Matches the current selection or specified node against the specified format name.
Formatter
matchAll(names:Array, vars:Object):Array
Matches the current selection against the array of formats and returns a new array with matching formats.
Formatter
matchNode(node:Node, name:String, vars:Object, similar:Boolean):Object
Return true/false if the specified node has the specified format.
Formatter
register(name:Object/String, format:Object/Array):void
Registers a specific format by name.
Formatter
remove(name:String, vars:Object, node:Node/Range):void
Removes the specified format from the current selection or specified node.
Formatter
toggle(name:String, vars:Object, node:Node):void
Toggles the specified format on/off.
Formatter

Method details

applymethod

public function apply(name:String, vars:Object, node:Node):void
Applies the specified format to the current selection or specified node.

Parameters

name:String Name of format to apply.
vars:Object Optional list of variables to replace within format before applying it.
node:Node Optional node to apply the format to defaults to current selection.

canApplymethod

public function canApply(name:String):boolean
Returns true/false if the specified format can be applied to the current selection or not. It will currently only check the state for selector formats, it returns true on all other format types.

Parameters

name:String Name of format to check.

Returns

boolean - true/false if the specified format can be applied to the current selection/node.

formatChangedmethod

public function formatChanged(formats:String, callback:function, similar:Boolean):void
Executes the specified callback when the current selection matches the formats or not.

Parameters

formats:String Comma separated list of formats to check for.
callback:function Callback with state and args when the format is changed/toggled on/off.
similar:Boolean True/false state if the match should handle similar or exact formats.

getmethod

public function get(name:String):Array/Object
Returns the format by name or all formats if no name is specified.

Parameters

name:String Optional name to retrive by.

Returns

Array/Object - Array/Object with all registred formats or a specific format.

matchmethod

public function match(name:String, vars:Object, node:Node):boolean
Matches the current selection or specified node against the specified format name.

Parameters

name:String Name of format to match.
vars:Object Optional list of variables to replace before checking it.
node:Node Optional node to check.

Returns

boolean - true/false if the specified selection/node matches the format.

matchAllmethod

public function matchAll(names:Array, vars:Object):Array
Matches the current selection against the array of formats and returns a new array with matching formats.

Parameters

names:Array Name of format to match.
vars:Object Optional list of variables to replace before checking it.

Returns

Array - Array with matched formats.

matchNodemethod

public function matchNode(node:Node, name:String, vars:Object, similar:Boolean):Object
Return true/false if the specified node has the specified format.

Parameters

node:Node Node to check the format on.
name:String Format name to check.
vars:Object Optional list of variables to replace before checking it.
similar:Boolean Match format that has similar properties.

Returns

Object - Returns the format object it matches or undefined if it doesn't match.

registermethod

public function register(name:Object/String, format:Object/Array):void
Registers a specific format by name.

Parameters

name:Object/String Name of the format for example "bold".
format:Object/Array Optional format object or array of format variants can only be omitted if the first arg is an object.

removemethod

public function remove(name:String, vars:Object, node:Node/Range):void
Removes the specified format from the current selection or specified node.

Parameters

name:String Name of format to remove.
vars:Object Optional list of variables to replace within format before removing it.
node:Node/Range Optional node or DOM range to remove the format from defaults to current selection.

togglemethod

public function toggle(name:String, vars:Object, node:Node):void
Toggles the specified format on/off.

Parameters

name:String Name of format to apply/remove.
vars:Object Optional list of variables to replace within format before applying/removing it.
node:Node Optional node to apply the format to or remove from. Defaults to current selection.