editor.plugins.BasicTextFormatter Extends goog.editor.Plugin
Functions to style text (e.g. underline, make bold, etc.)

Inheritance

Constructor

goog.editor.plugins.BasicTextFormatter()

Instance Methods

Public Protected Private
applyBgColorManually_(bgColor)
Applies a background color to a selection when the browser can't do the job. NOTE(nicksantos): If you think this is hacky, you should try applying background color in Opera. It made me cry.
Arguments:
bgColor : string
backgroundColor from .formatText to .execCommand.
code »
applyExecCommandGeckoFixes_(command)
Apply pre-execCommand fixes for Gecko.
Arguments:
command : string
The command to execute.
code »
applyExecCommandIEFixes_(command) !Array.<Node>
Apply pre-execCommand fixes for IE.
Arguments:
command : string
The command to execute.
Returns: !Array.<Node>  Array of nodes to be removed after the execCommand. Will never be longer than 2 elements.
code »
applyExecCommandSafariFixes_(command) !Element | undefined
Apply pre-execCommand fixes for Safari.
Arguments:
command : string
The command to execute.
Returns: !Element | undefined  The div added to the field.
code »
applySubscriptSuperscriptWorkarounds_(command)
Makes sure that superscript is removed before applying subscript, and vice versa. Fixes http://buganizer/issue?id=1173491 .
Arguments:
command : goog.editor.plugins.BasicTextFormatter.COMMAND
The command being applied, either SUBSCRIPT or SUPERSCRIPT.
code »
beforeInsertListGecko_() boolean
Work around a Gecko bug that causes inserted lists to forget the current font. This affects WebKit in the same way and Opera in a slightly different way, but this workaround only works in Gecko. WebKit bug: https://bugs.webkit.org/show_bug.cgi?id=19653 Mozilla bug: https://bugzilla.mozilla.org/show_bug.cgi?id=439966 Opera bug: https://bugs.opera.com/show_bug.cgi?id=340392 TODO: work around this issue in WebKit and Opera as well.
Returns: boolean  Whether the workaround was applied.
code »
cleanContentsDom()
No description.
code »
cleanContentsHtml()
No description.
code »
cleanUpSafariHeadings_()
Fix a ridiculous Safari bug: the first letters of new headings somehow retain their original font size and weight if multiple lines are selected during the execCommand that turns them into headings. The solution is to strip these styles which are normally stripped when making things headings anyway.
code »
convertBreaksToDivs_() boolean
Convert BRs in the selection to divs. This is only intended to be used in IE and Opera.
Returns: boolean  Whether any BR's were converted.
code »
createLink_(rangeurlopt_target) ?goog.editor.Link
Create a link out of the current selection. If nothing is selected, insert a new link. Otherwise, enclose the selection in a link.
Arguments:
range : goog.dom.AbstractRange
The closure range object for the current selection.
url : string
The url to link to.
opt_target : string=
Target for the link.
Returns: ?goog.editor.Link  The newly created link, or null if the link couldn't be created.
code »
execCommandHelper_(commandopt_valueopt_preserveDiropt_styleWithCss)
Perform an execCommand on the active document.
Arguments:
command : string
The command to execute.
opt_value : string | number | boolean | null=
Optional value.
opt_preserveDir : boolean=
Set true to make sure that command does not change directionality of the selected text (works only if all selected text has the same directionality, otherwise ignored). Should not be true if bidi plugin is not loaded.
opt_styleWithCss : boolean=
Set to true to ask the browser to use CSS to perform the execCommand.
code »
execCommandInternal(commandvar_args) Object | undefined
Execute a user-initiated command.
Arguments:
command : string
Command to execute.
var_args : ...*
For color commands, this should be the hex color (with the #). For FORMAT_BLOCK, this should be the goog.editor.plugins.BasicTextFormatter.BLOCK_COMMAND. It will be unused for other commands.
Returns: Object | undefined  The result of the command.
code »
fixIELists_()
Changing an OL to a UL (or the other way around) will fail if the list has a type attribute (such as "UL type=disc" becoming "OL type=disc", which is visually identical). Most browsers will remove the type attribute automatically, but IE doesn't. This does it manually.
code »
fixSafariLists_()
Prevent Safari from making each list item be "1" when converting from unordered to ordered lists. (see https://bugs.webkit.org/show_bug.cgi?id=19539, fixed by 2010-04-21)
code »
focusField_()
Focuses on the field.
code »
getDocument_() !Document
No description.
Returns: !Document  The document object associated with the currently active field.
code »
getRange_() goog.dom.AbstractRange
No description.
Returns: goog.dom.AbstractRange  The closure range object that wraps the current user selection.
code »
getTrogClassId()
No description.
code »
handleKeyboardShortcut()
No description.
code »
invalidateInlineCss_()
Workaround for Opera bug CORE-23903. Opera sometimes fails to invalidate serialized CSS or innerHTML for the DOM after certain execCommands when styleWithCSS is on. Toggling an inline style on the elements fixes it.
code »
isJustification_(command) boolean
Returns true if the current justification matches the justification command for the entire selection.
Arguments:
command : string
The justification command to check for.
Returns: boolean  Whether the current justification matches the justification command for the entire selection.
code »
isNodeInState_(nodeName) boolean
Returns true if a selection contained in the node should set the appropriate toolbar state for the given nodeName, e.g. if the node is contained in a strong element and nodeName is "strong", then it will return true.
Arguments:
nodeName : string
The type of node to check for.
Returns: boolean  Whether the user's selection is in the given state.
code »
isSupportedCommand(command) boolean
Whether the string corresponds to a command this plugin handles.
Arguments:
command : string
Command string to check.
Returns: boolean  Whether the string corresponds to a command this plugin handles.
code »
justify_(command)
Justify the text in the selection.
Arguments:
command : string
The type of justification to perform.
code »
prepareContentsHtml()
No description.
code »
queryCommandHelper_(isGetQueryCommandStatequeryObjectcommandopt_styleWithCss) string | boolean | null
Helper function to perform queryCommand(Value|State).
Arguments:
isGetQueryCommandState : boolean
True to use queryCommandState, false to use queryCommandValue.
queryObject : Document | TextRange | Range
The object to query.
command : string
The command to check.
opt_styleWithCss : boolean=
Set to true to enable styleWithCSS before performing the queryCommand(Value|State).
Returns: string | boolean | null  The command value.
code »
queryCommandStateInternal_(queryObjectcommandopt_styleWithCss) boolean
Wrapper for browser's queryCommandState.
Arguments:
queryObject : Document | TextRange | Range
The object to query.
command : string
The command to check.
opt_styleWithCss : boolean=
Set to true to enable styleWithCSS before performing the queryCommandState.
Returns: boolean  The command state.
code »
queryCommandValue(command) string | boolean | null
Gets the command value.
Arguments:
command : string
The command value to get.
Returns: string | boolean | null  The current value of the command in the given selection. NOTE: This return type list is not documented in MSDN or MDC and has been constructed from experience. Please update it if necessary.
code »
queryCommandValueInternal_(queryObjectcommandopt_styleWithCss) string | boolean | null
Wrapper for browser's queryCommandValue.
Arguments:
queryObject : Document | TextRange | Range
The object to query.
command : string
The command to check.
opt_styleWithCss : boolean=
Set to true to enable styleWithCSS before performing the queryCommandValue.
Returns: string | boolean | null  The command value.
code »
removeFontSizeFromStyleAttrs_()
Removes inline font-size styles from elements fully contained in the selection, so the font tags produced by execCommand work properly. See .
code »
toggleLink_(opt_target) ?goog.editor.Link
Toggle link for the current selection: If selection contains a link, unlink it, return null. Otherwise, make selection into a link, return the link.
Arguments:
opt_target : string=
Target for the link.
Returns: ?goog.editor.Link  The resulting link, or null if a link was removed.
code »
activeOnUneditableFields() boolean
No description.
Returns: boolean  If true, field will not disable the command when the field becomes uneditable.
code »
cleanContentsDom(fieldCopy)
Cleans the contents of the node passed to it. The node contents are modified directly, and the modifications will subsequently be used, for operations such as saving the innerHTML of the editor etc. Since the plugins act on the DOM directly, this method can be very expensive. This op is invoked even on disabled plugins.
Arguments:
fieldCopy : !Element
The copy of the editable field which needs to be cleaned up.
code »
cleanContentsHtml(originalHtml) string
Cleans the html contents of Trogedit. Both cleanContentsDom and and cleanContentsHtml will be called on contents extracted from Trogedit. The inverse of prepareContentsHtml. This op is invoked even on disabled plugins.
Arguments:
originalHtml : string
The trogedit HTML.
Returns: string  Cleaned-up HTML.
code »
disable(fieldObject)
Disables this plugin for the specified, registered field object.
Arguments:
fieldObject : goog.editor.Field
The field object.
code »
disposeInternal()
No description.
code »
enable(fieldObject)
Enables this plugin for the specified, registered field object. A field object should only be enabled when it is loaded.
Arguments:
fieldObject : goog.editor.Field
The field object.
code »
execCommand(commandvar_args) *
Handles execCommand. This default implementation handles dispatching BEFORECHANGE, CHANGE, and SELECTIONCHANGE events, and calls execCommandInternal to perform the actual command. Plugins that want to do their own event dispatching should override execCommand, otherwise it is preferred to only override execCommandInternal. This version of execCommand will only work for single field plugins. Multi-field plugins must override execCommand.
Arguments:
command : string
The command to execute.
var_args : ...*
Any additional parameters needed to execute the command.
Returns: *  The result of the execCommand, if any.
code »
execCommandInternal(commandvar_args) *
Handles execCommand. This default implementation does nothing, and is called by execCommand, which handles event dispatching. This method should be overriden by plugins that don't need to do their own event dispatching. If custom event dispatching is needed, execCommand shoul be overriden instead.
Arguments:
command : string
The command to execute.
var_args : ...*
Any additional parameters needed to execute the command.
Returns: *  The result of the execCommand, if any.
code »
getFieldDomHelper() ?goog.dom.DomHelper
No description.
Returns: ?goog.dom.DomHelper  The dom helper object associated with the currently active field.
code »
getFieldObject() goog.editor.Field
Sets the field object for use with this plugin.
Returns: goog.editor.Field  The editable field object.
code »
getTrogClassId() string
No description.
Returns: string  The ID unique to this plugin class. Note that different instances off the plugin share the same classId.
code »
handleKeyDown(e) boolean
Handles keydown. It is run before handleKeyboardShortcut and if it returns true handleKeyboardShortcut will not be called.
Arguments:
e : !goog.events.BrowserEvent
The browser event.
Returns: boolean  Whether the event was handled and thus should *not* be propagated to other plugins or handleKeyboardShortcut.
code »
handleKeyPress(e) boolean
Handles keypress. It is run before handleKeyboardShortcut and if it returns true handleKeyboardShortcut will not be called.
Arguments:
e : !goog.events.BrowserEvent
The browser event.
Returns: boolean  Whether the event was handled and thus should *not* be propagated to other plugins or handleKeyboardShortcut.
code »
handleKeyUp(e) boolean
Handles keyup.
Arguments:
e : !goog.events.BrowserEvent
The browser event.
Returns: boolean  Whether the event was handled and thus should *not* be propagated to other plugins.
code »
handleKeyboardShortcut(ekeyisModifierPressed) boolean
Handles keyboard shortcuts. Preferred to using handleKey* as it will use the proper event based on browser and will be more performant. If handleKeyPress/handleKeyDown returns true, this will not be called. If the plugin handles the shortcut, it is responsible for dispatching appropriate events (change, selection change at the time of this comment). If the plugin calls execCommand on the editable field, then execCommand already takes care of dispatching events. NOTE: For performance reasons this is only called when any key is pressed in conjunction with ctrl/meta keys OR when a small subset of keys (defined in goog.editor.Field.POTENTIAL_SHORTCUT_KEYCODES_) are pressed without ctrl/meta keys. We specifically don't invoke it when altKey is pressed since alt key is used in many i8n UIs to enter certain characters.
Arguments:
e : !goog.events.BrowserEvent
The browser event.
key : string
The key pressed.
isModifierPressed : boolean
Whether the ctrl/meta key was pressed or not.
Returns: boolean  Whether the event was handled and thus should *not* be propagated to other plugins. We also call preventDefault on the event if the return value is true.
code »
handleSelectionChange(opt_eopt_target) boolean
Handles selection change.
Arguments:
opt_e : !goog.events.BrowserEvent=
The browser event.
opt_target : !Node=
The node the selection changed to.
Returns: boolean  Whether the event was handled and thus should *not* be propagated to other plugins.
code »
isAutoDispose() boolean
No description.
Returns: boolean  Whether or not this plugin should automatically be disposed when it's registered field is disposed.
code »
isEnabled(fieldObject) boolean
Returns whether this plugin is enabled for the field object.
Arguments:
fieldObject : goog.editor.Field
The field object.
Returns: boolean  Whether this plugin is enabled for the field object.
code »
isSilentCommand(command) boolean
No description.
Arguments:
command : string
The command to check.
Returns: boolean  If true, field will not dispatch change events for commands of this type. This is useful for "seamless" plugins like dialogs and lorem ipsum.
code »
isSupportedCommand(command) boolean
Whether the string corresponds to a command this plugin handles.
Arguments:
command : string
Command string to check.
Returns: boolean  Whether the plugin handles this type of command.
code »
prepareContentsHtml(originalHtmlstyles) string
Prepares the given HTML for editing. Strips out content that should not appear in an editor, and normalizes content as appropriate. The inverse of cleanContentsHtml. This op is invoked even on disabled plugins.
Arguments:
originalHtml : string
The original HTML.
styles : Object
A map of strings. If the plugin wants to add any styles to the field element, it should add them as key-value pairs to this object.
Returns: string  New HTML that's ok for editing.
code »
queryCommandValue(command) *
Gets the state of this command if this plugin serves that command.
Arguments:
command : string
The command to check.
Returns: *  The value of the command.
code »
registerFieldObject(fieldObject)
Registers the field object for use with this plugin.
Arguments:
fieldObject : goog.editor.Field
The editable field object.
code »
setAutoDispose(autoDispose)
Set if this plugin should automatically be disposed when the registered field is disposed.
Arguments:
autoDispose : boolean
Whether to autoDispose.
code »
setFieldObject(fieldObject)
Sets the field object for use with this plugin.
Arguments:
fieldObject : goog.editor.Field
The editable field object.
code »
unregisterFieldObject(fieldObj)
Unregisters and disables this plugin for the current field object.
Arguments:
fieldObj : goog.editor.Field
The field object. For single-field plugins, this parameter is ignored.
code »
addEventListener(typeopt_captureopt_handlerScope)
Use #listen instead, when possible. Otherwise, use goog.events.listen if you are passing Object (instead of Function) as handler. Adds an event listener to the event target. The same handler can only be added once per the type. Even if you add the same handler multiple times using the same type then it will only be called once when the event is dispatched.
Arguments:
type : string
The type of the event to listen for.
: ?function():? | ?{handleEvent:function():?
No description.
opt_capture : boolean=
In DOM-compliant browsers, this determines whether the listener is fired during the capture or bubble phase of the event.
opt_handlerScope : Object=
Object in whose scope to call the listener.
code »
assertInitialized_()
Asserts that the event target instance is initialized properly.
code »
dispatchEvent()
No description.
code »
disposeInternal()
Removes listeners from this object. Classes that extend EventTarget may need to override this method in order to remove references to DOM Elements and additional listeners.
code »
fireListeners()
No description.
code »
getListener()
No description.
code »
getListeners()
No description.
code »
getParentEventTarget() goog.events.EventTarget
Returns the parent of this event target to use for bubbling.
Returns: goog.events.EventTarget  The parent EventTarget or null if there is no parent.
code »
hasListener()
No description.
code »
listen()
No description.
code »
listenOnce()
No description.
code »
removeAllListeners()
No description.
code »
removeEventListener(typeopt_captureopt_handlerScope)
Use #unlisten instead, when possible. Otherwise, use goog.events.unlisten if you are passing Object (instead of Function) as handler. Removes an event listener from the event target. The handler must be the same object as the one added. If the handler has not been added then nothing is done.
Arguments:
type : string
The type of the event to listen for.
: ?function():? | ?{handleEvent:function():?
No description.
opt_capture : boolean=
In DOM-compliant browsers, this determines whether the listener is fired during the capture or bubble phase of the event.
opt_handlerScope : Object=
Object in whose scope to call the listener.
code »
setParentEventTarget(parent)
Sets the parent of this event target to use for capture/bubble mechanism.
Arguments:
parent : goog.events.EventTarget
Parent listenable (null if none).
code »
setTargetForTesting(target)
Sets the target to be used for event.target when firing event. Mainly used for testing. For example, see goog.testing.events.mixinListenable.
Arguments:
target : !Object
The target.
code »
unlisten()
No description.
code »
unlistenByKey()
No description.
code »
addOnDisposeCallback(callbackopt_scope)
Invokes a callback function when this object is disposed. Callbacks are invoked in the order in which they were added.
Arguments:
callback : function(this:T):?
The callback function.
opt_scope : T=
An optional scope to call the callback in.
code »
dispose() void
Disposes of the object. If the object hasn't already been disposed of, calls #disposeInternal. Classes that extend goog.Disposable should override #disposeInternal in order to delete references to COM objects, DOM nodes, and other disposable objects. Reentrant.
Returns: void  Nothing.
code »
disposeInternal()
Deletes or nulls out any references to COM objects, DOM nodes, or other disposable objects. Classes that extend goog.Disposable should override this method. Not reentrant. To avoid calling it twice, it must only be called from the subclass' disposeInternal method. Everywhere else the public dispose method must be used. For example:
  mypackage.MyClass = function() {
    mypackage.MyClass.base(this, 'constructor');
    // Constructor logic specific to MyClass.
    ...
  };
  goog.inherits(mypackage.MyClass, goog.Disposable);

  mypackage.MyClass.prototype.disposeInternal = function() {
    // Dispose logic specific to MyClass.
    ...
    // Call superclass's disposeInternal at the end of the subclass's, like
    // in C++, to avoid hard-to-catch issues.
    mypackage.MyClass.base(this, 'disposeInternal');
  };
code »
getDisposed() boolean
Use #isDisposed instead. No description.
Returns: boolean  Whether the object has been disposed of.
code »
isDisposed() boolean
No description.
Returns: boolean  Whether the object has been disposed of.
code »
registerDisposable(disposable)
Associates a disposable object with this object so that they will be disposed together.
Arguments:
disposable : goog.disposable.IDisposable
that will be disposed when this object is disposed.
code »

Instance Properties

constructor :
No description.
Code »
Logging object.
Code »
autoDispose_ :
Indicates if this plugin should be automatically disposed when the registered field is disposed. This should be changed to false for plugins used as multi-field plugins.
Code »
constructor :
No description.
Code »
enabled_ :
Whether this plugin is enabled for the registered field object.
Code »
fieldObject : goog.editor.Field
The field object this plugin is attached to.
Code »
The logger for this plugin.
Code »
actualEventTarget_ : goog.events.EventTarget
The object to use for event.target. Useful when mixing in an EventTarget to another object.
Code »
constructor :
No description.
Code »
eventTargetListeners_ : goog.events.ListenerMap
Maps of event type to an array of listeners.
Code »
parentEventTarget_ : goog.events.EventTarget
Parent event target, used during event bubbling. TODO(user): Change this to goog.events.Listenable. This currently breaks people who expect getParentEventTarget to return goog.events.EventTarget.
Code »
creationStack :
If monitoring the goog.Disposable instances is enabled, stores the creation stack trace of the Disposable instance.
Code »
disposed_ :
Whether the object has been disposed of.
Code »
onDisposeCallbacks_ :
Callbacks to invoke when this object is disposed.
Code »

Static Methods

goog.editor.plugins.BasicTextFormatter.convertContainerToTextAlign_(node)
Converts the block element containing the given node to use CSS text-align instead of the align property.
Arguments:
node : Node
The node to convert the container of.
code »
goog.editor.plugins.BasicTextFormatter.convertParagraphToDiv_(paragraphopt_convertBrs)
Convert the given paragraph to being a div. This clobbers the passed-in node! This is only intended to be used in IE and Opera.
Arguments:
paragraph : Node
Paragragh to convert to a div.
opt_convertBrs : boolean=
If true, also convert BRs to divs.
code »
goog.editor.plugins.BasicTextFormatter.convertToRealExecCommand_(command) string
If this is a goog.editor.plugins.BasicTextFormatter.COMMAND, convert it to something that we can pass into execCommand, queryCommandState, etc. TODO(user): Consider doing away with the + and converter completely.
Arguments:
command : goog.editor.plugins.BasicTextFormatter.COMMAND | string
A command key.
Returns: string  The equivalent execCommand command.
code »
goog.editor.plugins.BasicTextFormatter.getNodeJustification_(element) string
Determines the justification for a given block-level element.
Arguments:
element : Element
The node to get justification for.
Returns: string  The justification for a given block-level node.
code »
goog.editor.plugins.BasicTextFormatter.getSelectionBlockState_(range) ?string
Get the toolbar state for the block-level elements in the given range.
Arguments:
range : goog.dom.AbstractRange
The range to get toolbar state for.
Returns: ?string  The selection block state.
code »

Static Properties

goog.editor.plugins.BasicTextFormatter.BR_REGEXP_ :
Regular expression to match BRs in HTML. Saves the BRs' attributes in $1 for use with replace(). In non-IE browsers, does not match BRs adjacent to an opening or closing DIV or P tag, since nonrendered BR elements can occur at the end of block level containers in those browsers' editors.
Code »
goog.editor.plugins.BasicTextFormatter.SUPPORTED_COMMANDS_ :
Inverse map of execCommand strings to goog.editor.plugins.BasicTextFormatter.COMMAND constants. Used to determine whether a string corresponds to a command this plugin handles in O(1) time.
Code »
goog.editor.plugins.BasicTextFormatter.SUPPORTED_JUSTIFICATIONS_ :
Hash of suppoted justifications.
Code »
goog.editor.plugins.BasicTextFormatter.blockquoteHatingCommandsIE_ :
When the following commands are executed while the selection is inside a blockquote, they hose the blockquote tag in weird and unintuitive ways.
Code »
goog.editor.plugins.BasicTextFormatter.brokenExecCommandsIE_ :
The following execCommands are "broken" in some way - in IE they allow the nodes outside the contentEditable region to get modified (see execCommand below for more details).
Code »
goog.editor.plugins.BasicTextFormatter.brokenExecCommandsSafari_ :
In WebKit, the following commands will modify the node with contentEditable=true if there are no block-level elements.
Code »
goog.editor.plugins.BasicTextFormatter.hangingExecCommandWebkit_ :
In WebKit, the following commands can hang the browser if the selection touches the beginning of the field. https://bugs.webkit.org/show_bug.cgi?id=19735
Code »
goog.editor.plugins.BasicTextFormatter.orderedListTypes_ :
Sane "type" attribute values for OL elements
Code »
goog.editor.plugins.BasicTextFormatter.superClass_ :
No description.
Code »
goog.editor.plugins.BasicTextFormatter.unorderedListTypes_ :
Sane "type" attribute values for UL elements
Code »

Enumerations

goog.editor.plugins.BasicTextFormatter.COMMAND :
Commands implemented by this plugin.
Constants:
BACKGROUND_COLOR
No description.
BOLD
No description.
FONT_COLOR
No description.
FONT_FACE
No description.
FONT_SIZE
No description.
FORMAT_BLOCK
No description.
HORIZONTAL_RULE
No description.
INDENT
No description.
ITALIC
No description.
JUSTIFY_CENTER
No description.
JUSTIFY_FULL
No description.
JUSTIFY_LEFT
No description.
JUSTIFY_RIGHT
No description.
LINK
No description.
ORDERED_LIST
No description.
OUTDENT
No description.
STRIKE_THROUGH
No description.
SUBSCRIPT
No description.
SUPERSCRIPT
No description.
UNDERLINE
No description.
UNORDERED_LIST
No description.
Code »

Package editor.plugins

Package Reference