editor.plugins.TagOnEnterHandler Extends goog.editor.plugins.EnterHandler
Plugin to handle enter keys. This subclass normalizes all browsers to use the given block tag on enter.

Inheritance

Constructor

goog.editor.plugins.TagOnEnterHandler(tag)

Parameters

tag : goog.dom.TagName
The type of tag to add on enter.

Instance Methods

Public Protected Private
activeOnUneditableFields() boolean
This plugin is active on uneditable fields so it can provide a value for queryCommandValue calls asking for goog.editor.Command.BLOCKQUOTE.
Returns: boolean  True.
code »
breakOutOfEmptyListItemGecko_(li) !Element
If The cursor is in an empty LI then break out of the list like in IE
Arguments:
li : Node
LI to break out of.
Returns: !Element  Element to put the cursor after.
code »
ensureNodeIsWrappedW3c_(nodecontainer) Element
Ensures the current node is wrapped in the tag.
Arguments:
node : Node
The node to ensure gets wrapped.
container : Element
Element containing the selection.
Returns: Element  Element containing the selection, after the wrapping.
code »
getNonCollapsingBlankHtml()
No description.
code »
getTrogClassId()
No description.
code »
handleBackspaceInternal()
No description.
code »
handleDeleteGecko()
No description.
code »
handleEnterAtCursorGeckoInternal()
No description.
code »
handleEnterWebkitInternal()
No description.
code »
handleKeyUpInternal()
No description.
code »
handleRegularEnterGecko_() Element
Called in response to a normal enter keystroke. It has the action of splitting elements.
Returns: Element  The node that the cursor should be before.
code »
isSupportedCommand()
No description.
code »
markBrToNotBeRemoved_(rangeisBackspace)
When we delete an element, FF inserts a BR. We want to strip that BR after the fact, but in the case where your cursor is at a character right before a BR and you delete that character, we don't want to strip it. So we detect this case on keydown and mark the BR as not needing removal.
Arguments:
range : goog.dom.AbstractRange
The closure range object.
isBackspace : boolean
Whether this is handling the backspace key.
code »
processParagraphTagsInternal()
No description.
code »
queryCommandValue()
No description.
code »
removeBrIfNecessary_(isBackSpace)
If we hit delete/backspace to merge elements, FF inserts a BR. We want to strip that BR. In markBrToNotBeRemoved, we detect if there was already a BR there before the delete/backspace so that we don't accidentally remove a user-inserted BR.
Arguments:
isBackSpace : boolean
Whether this is handling the backspace key.
code »
scrollCursorIntoViewGecko_(element)
Scroll the cursor into view, resulting from splitting the paragraph/adding a br. It behaves differently than scrollIntoView
Arguments:
element : Element
The element immediately following the cursor. Will be used to determine how to scroll in order to make the cursor visible. CANNOT be a BR, as they do not have offsetHeight/offsetTop.
code »
deleteBrGecko(e)
Deletes the element at the cursor if it is a BR node, and if it does, calls e.preventDefault to stop the browser from deleting. Only necessary in Gecko as a workaround for mozilla bug 205350 where deleting a BR that is followed by a block element doesn't work (the BR gets immediately replaced). We also need to account for an ill-formed cursor which occurs from us trying to stop the browser from deleting.
Arguments:
e : goog.events.Event
The DELETE keypress event.
code »
deleteCursorSelectionIE_() !Node
Delete the selection at the current cursor position, then returns a temporary node at the current position.
Returns: !Node  A temporary node marking the current cursor position. This node should eventually be removed from the DOM.
code »
deleteCursorSelectionW3C_() !goog.editor.range.Point
Delete the selection at the current cursor position, then returns the node at the current position.
Returns: !goog.editor.range.Point  The current cursor position. Note that unlike simulateEnterIE_, this should not be removed from the DOM.
code »
deleteCursorSelection_() !Node | !Object
Deletes the content at the current cursor position.
Returns: !Node | !Object  Something representing the current cursor position. See deleteCursorSelectionIE_ and deleteCursorSelectionW3C_ for details. Should be passed to releasePositionObject_ when no longer in use.
code »
enable()
No description.
code »
ensureBlockIeOpera(tagopt_keyUp)
Ensures all text in IE and Opera to be in the given tag in order to control Enter spacing. Call this when Enter is pressed if desired. We want to make sure the user is always inside of a block (or other nodes listed in goog.editor.plugins.EnterHandler.IGNORE_ENSURE_BLOCK_NODES_). We listen to keypress to force nodes that the user is leaving to turn into blocks, but we also need to listen to keyup to force nodes that the user is entering to turn into blocks. Example: html is: "

foo[cursor]

", and the user hits enter. We don't want to format the h2, but we do want to format the P that is created on enter. The P node is not available until keyup.
Arguments:
tag : goog.dom.TagName
The tag name to convert to.
opt_keyUp : boolean=
Whether the function is being called on key up. When called on key up, the cursor is in the newly created node, so the semantics for when to change it to a block are different. Specifically, if the resulting node contains only a BR, it is converted to .
code »
getNonCollapsingBlankHtml() string
Gets HTML with no contents that won't collapse, for browsers that collapse the empty string.
Returns: string  Blank html.
code »
getTrogClassId()
No description.
code »
handleBackspaceInternal(erange)
Internal backspace handler.
Arguments:
e : goog.events.Event
The keypress event.
range : goog.dom.AbstractRange
The closure range object.
code »
handleDeleteGecko(e)
Internal delete key handler.
Arguments:
e : goog.events.Event
The keypress event.
code »
handleEnterAtCursorGeckoInternal(ewasCollapsedrange)
Handle an enter key press on collapsed selection. handleEnterGecko_ ensures the selection is collapsed by deleting its contents if it is not. The default implementation does nothing.
Arguments:
e : goog.events.BrowserEvent
The key press event.
wasCollapsed : boolean
Whether the selection was collapsed before the key press. If it was not, code before this function has already cleared the contents of the selection.
range : goog.dom.AbstractRange
Object representing the selection.
code »
handleEnterGecko_(e)
Handles an enter keypress event on fields in Gecko.
Arguments:
e : goog.events.BrowserEvent
The key event.
code »
handleEnterWebkitInternal(e)
Handle an enter key press in WebKit.
Arguments:
e : goog.events.BrowserEvent
The key press event.
code »
handleKeyPress()
No description.
code »
handleKeyUp()
No description.
code »
handleKeyUpInternal(e)
Internal handler for keyup events.
Arguments:
e : goog.events.Event
The key event.
code »
prepareContentsHtml(html) string
If the contents are empty, return the 'default' html for the field. The 'default' contents depend on the enter handling mode, so it makes the most sense in this plugin.
Arguments:
html : string
The html to prepare.
Returns: string  The original HTML, or default contents if that html is empty.
code »
processParagraphTagsInternal(esplit)
Fix paragraphs to be the correct type of node.
Arguments:
e : goog.events.Event
The key event.
split : boolean
Whether we already split up a blockquote by manually inserting elements.
code »
releasePositionObject_(position)
Releases the object returned by deleteCursorSelection_.
Arguments:
position : Node | Object
The object returned by deleteCursorSelection_.
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 »
constructor :
No description.
Code »
tag :
The type of block level tag to add on enter, for browsers that support specifying the default block-level tag. Can be overriden by subclasses; must be either DIV or P.
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.TagOnEnterHandler.findAnchorInTraversal_(nodeopt_useFirstChild) Node
Finds the first A element in a traversal from the input node. The input node itself is not included in the search.
Arguments:
node : Node
The node to start searching from.
opt_useFirstChild : boolean=
Whether to traverse along the first child (true) or last child (false).
Returns: Node  The first anchor node found in the search, or null if none was found.
code »
goog.editor.plugins.TagOnEnterHandler.joinTextNodes_(nodemoveForward) Node
Joins node and its adjacent text nodes together.
Arguments:
node : Node
The node to start joining.
moveForward : boolean
Determines whether to join left siblings (false) or right siblings (true).
Returns: Node  The joined text node.
code »
goog.editor.plugins.TagOnEnterHandler.replaceWhiteSpaceWithNbsp_(textNodefromStartisLeaveEmpty)
Replaces leading or trailing spaces of a text node to a single Nbsp.
Arguments:
textNode : Node
The text node to search and replace white spaces.
fromStart : boolean
Set to true to replace leading spaces, false to replace trailing spaces.
isLeaveEmpty : boolean
Set to true to leave the node empty if the text node was empty in the first place, otherwise put a Nbsp into the text node.
code »
goog.editor.plugins.TagOnEnterHandler.splitDomAndAppend_(positionNodepositionOffsetnode) !Node
Splits the DOM tree around the given node and returns the node containing second half of the tree, which is appended after the old node. The first half of the tree is modified, but not removed from the DOM.
Arguments:
positionNode : Node
Node to split at.
positionOffset : number
Offset into positionNode to split at. If positionNode is a text node, this offset is an offset in to the text content of that node. Otherwise, positionOffset is an offset in to the childNodes array. All elements with child index of positionOffset or greater will be moved to the second half. If positionNode is an empty element, the dom will be split at that element, with positionNode ending up in the second half. positionOffset must be 0 in this case.
node : Node
Node to split.
Returns: !Node  The node containing the second half of the tree.
code »
goog.editor.plugins.TagOnEnterHandler.splitDom_(positionNodepositionOffsetopt_root) !Node
Splits the DOM tree around the given node and returns the node containing the second half of the tree. The first half of the tree is modified, but not removed from the DOM.
Arguments:
positionNode : Node
Node to split at.
positionOffset : number
Offset into positionNode to split at. If positionNode is a text node, this offset is an offset in to the text content of that node. Otherwise, positionOffset is an offset in to the childNodes array. All elements with child index of positionOffset or greater will be moved to the second half. If positionNode is an empty element, the dom will be split at that element, with positionNode ending up in the second half. positionOffset must be 0 in this case.
opt_root : Node=
Node at which to stop splitting the dom (the root is also split).
Returns: !Node  The node containing the second half of the tree.
code »
goog.editor.plugins.TagOnEnterHandler.trimTabsAndLineBreaks_(string) string
Trim the tabs and line breaks from a string.
Arguments:
string : string
String to trim.
Returns: string  Trimmed string.
code »
goog.editor.plugins.TagOnEnterHandler.wrapInContainerW3c_(nodeNamepositioncontainer) !Element
Wrap the text indicated by "position" in an HTML container of type "nodeName".
Arguments:
nodeName : string
Type of container, e.g. "p" (paragraph).
position : Object
The W3C cursor position object (from getCursorPositionW3c).
container : Node
The field containing position.
Returns: !Element  The container element that holds the contents from position.
code »

Static Properties

goog.editor.plugins.TagOnEnterHandler.BrOrNbspSurroundedWithWhiteSpace_ :
String that matches a single BR tag or NBSP surrounded by non-breaking whitespace
Code »
goog.editor.plugins.TagOnEnterHandler.emptyLiRegExp_ :
String that matches a single BR tag or NBSP surrounded by non-breaking whitespace
Code »
goog.editor.plugins.TagOnEnterHandler.superClass_ :
No description.
Code »

Package editor.plugins

Package Reference