0 results found

tinymce.Formatter

Contribute to this page
Namespacetinymce
ClassFormatter

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

MethodDefined 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

apply

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

Parameters

ParamDetail
name:StringName of format to apply.
vars:ObjectOptional list of variables to replace within format before applying it.
node:NodeOptional node to apply the format to defaults to current selection.

canApply

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

ParamDetail
name:StringName of format to check.

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

formatChanged

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

Parameters

ParamDetail
formats:StringComma separated list of formats to check for.
callback:functionCallback with state and args when the format is changed/toggled on/off.
similar:BooleanTrue/false state if the match should handle similar or exact formats.

get

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

Parameters

ParamDetail
name:StringOptional name to retrive by.

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

match

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

Parameters

ParamDetail
name:StringName of format to match.
vars:ObjectOptional list of variables to replace before checking it.
node:NodeOptional node to check.

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

matchAll

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

ParamDetail
names:ArrayName of format to match.
vars:ObjectOptional list of variables to replace before checking it.

Returns
Array - Array with matched formats.

matchNode

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

Parameters

ParamDetail
node:NodeNode to check the format on.
name:StringFormat name to check.
vars:ObjectOptional list of variables to replace before checking it.
similar:BooleanMatch format that has similar properties.

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

register

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

Parameters

ParamDetail
name:Object/StringName of the format for example "bold".
format:Object/ArrayOptional format object or array of format variants can only be omitted if the first arg is an object.

remove

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

Parameters

ParamDetail
name:StringName of format to remove.
vars:ObjectOptional list of variables to replace within format before removing it.
node:Node/RangeOptional node or DOM range to remove the format from defaults to current selection.

toggle

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

Parameters

ParamDetail
name:StringName of format to apply/remove.
vars:ObjectOptional list of variables to replace within format before applying/removing it.
node:NodeOptional node to apply the format to or remove from. Defaults to current selection.

Except as otherwise noted, the content of this page is licensed under the Creative Commons BY-NC-SA 3.0 License, and code samples are licensed under the Apache 2.0 License.