tinymce.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 built to replace the browser's default formatting logic for execCommand due to its inconsistent and buggy behavior.

Examples

tinymce.activeEditor.formatter.register('mycustomformat', {
   inline: 'span',
   styles: {color: '#ff0000'}
 });

 tinymce.activeEditor.formatter.apply('mycustomformat');

Constructors

name summary defined by
Formatter() Constructs a new formatter instance. tinymce.Formatter

Methods

name summary defined by
apply() Applies the specified format to the current selection or specified node. tinymce.Formatter
canApply() 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. tinymce.Formatter
formatChanged() Executes the specified callback when the current selection matches the formats or not. tinymce.Formatter
get() Returns the format by name or all formats if no name is specified. tinymce.Formatter
getCssText() Returns a preview css text for the specified format. tinymce.Formatter
match() Matches the current selection or specified node against the specified format name. tinymce.Formatter
matchAll() Matches the current selection against the array of formats and returns a new array with matching formats. tinymce.Formatter
matchNode() Return true/false if the specified node has the specified format. tinymce.Formatter
register() Registers a specific format by name. tinymce.Formatter
remove() Removes the specified format from the current selection or specified node. tinymce.Formatter
toggle() Toggles the specified format on/off. tinymce.Formatter
unregister() Unregister a specific format by name. tinymce.Formatter

Constructors

Formatter

public constructor function Formatter(ed:tinymce.Editor)

Constructs a new formatter instance.

Parameters

Methods

apply

apply(name:String, vars:Object, node:Node)

Applies the specified format to the current selection or specified node.

Parameters

canApply

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
Return value

formatChanged

formatChanged(formats:String, callback:function, similar:Boolean)

Executes the specified callback when the current selection matches the formats or not.

Parameters

get

get(name:String):Array, Object

Returns the format by name or all formats if no name is specified.

Parameters
Return value

getCssText

getCssText(format:String):String

Returns a preview css text for the specified format.

Examples
var cssText1 = editor.formatter.getCssText('bold');
var cssText2 = editor.formatter.getCssText({inline: 'b'});
Parameters
Return value

match

match(name:String, vars:Object, node:Node):boolean

Matches the current selection or specified node against the specified format name.

Parameters
Return value

matchAll

matchAll(names:Array, vars:Object):Array

Matches the current selection against the array of formats and returns a new array with matching formats.

Parameters
Return value

matchNode

matchNode(node:Node, name:String, vars:Object, similar:Boolean):Object

Return true/false if the specified node has the specified format.

Parameters
Return value

register

register(name:Object, format:Object)

Registers a specific format by name.

Parameters

remove

remove(name:String, vars:Object, node:Node)

Removes the specified format from the current selection or specified node.

Parameters

toggle

toggle(name:String, vars:Object, node:Node)

Toggles the specified format on/off.

Parameters

unregister

unregister(name:String)

Unregister a specific format by name.

Parameters

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.