editor.Field Extends goog.events.EventTarget
This class encapsulates an editable field. event: load Fires when the field is loaded event: unload Fires when the field is unloaded (made not editable) event: beforechange Fires before the content of the field might change event: delayedchange Fires a short time after field has changed. If multiple change events happen really close to each other only the last one will trigger the delayedchange event. event: beforefocus Fires before the field becomes active event: focus Fires when the field becomes active. Fires after the blur event event: blur Fires when the field becomes inactive TODO: figure out if blur or beforefocus fires first in IE and make FF match

Inheritance

Object
     goog.Disposable
          goog.events.EventTarget
               goog.editor.Field

Constructor

goog.editor.Field(idopt_doc)

Parameters

id :
An identifer for the field. This is used to find the field and the element associated with this field.
opt_doc :
The document that the element with the given id can be found in. If not provided, the default document is used.

Instance Methods

Public Protected Private
addListener(typelisteneropt_captureopt_handler)
Registers a keyboard event listener on the field. This is necessary for Gecko since the fields are contained in an iFrame and there is no way to auto-propagate key events up to the main window.
Arguments:
type :
Event type to listen for or array of event types, for example goog.events.EventType.KEYDOWN.
listener :
Function to be used as the listener.
opt_capture :
Whether to use capture phase (optional, defaults to false).
opt_handler :
Object in whose scope to call the listener.
code »
attachIframe(iframe)
Given the original field element, and the iframe that is destined to become the editable field, styles them appropriately and add the iframe to the dom.
Arguments:
iframe :
HTMLIFrameElement
The iframe element.
code »
attachWrapper(wrapper)
Attach an wrapper to this field, to be thrown out when the field is disposed.
Arguments:
wrapper :
The wrapper to attach.
code »
clearDelayedChange()
No description.
code »
clearFieldLoadListener_()
Clears fieldLoadListener for a field. Must be called even (especially?) if the field is not yet loaded and therefore not in this.fieldMap_
code »
clearListeners_()
Stops all listeners and timers.
code »
debounceEvent(eventType)
Block an event for a short amount of time. Intended for the situation where an event pair fires in quick succession (e.g., mousedown/mouseup, keydown/keyup, focus/blur), and we want the second event in the pair to get "debounced." WARNING: This should never be used to solve race conditions or for mission-critical actions. It should only be used for UI improvements, where it's okay if the behavior is non-deterministic.
Arguments:
eventType :
goog.editor.Field.EventType
type of event to debounce.
code »
dispatchBeforeChange()
No description.
code »
dispatchBeforeFocus_()
Dispatches a before focus event.
code »
dispatchBeforeTab_(e)
This dispatches the beforetab event on the editable field. If this event is cancelled, then the default tab behavior is prevented.
Arguments:
e :
The tab event.
Returns:   The result of dispatchEvent.
code »
dispatchBlur()
Dispatches a blur event.
code »
dispatchChange(opt_noDelay)
Dispatches the appropriate set of change events. This only fires synchronous change events in blended-mode, iframe-using mozilla. It just starts the appropriate timer for goog.editor.Field.EventType.DELAYEDCHANGE. This also starts up change events again if they were stopped.
Arguments:
opt_noDelay :
True if goog.editor.Field.EventType.DELAYEDCHANGE should be fired syncronously.
code »
dispatchCommandValueChange(opt_commands)
Dispatches a command value change event.
Arguments:
opt_commands :
Commands whose state has changed.
code »
dispatchDelayedChange_()
Dispatch a delayed change event.
code »
dispatchFocusAndBeforeFocus_()
Dispatch beforefocus and focus for FF. Note that both of these actually happen in the document's "focus" event. Unfortunately, we don't actually have a way of getting in before the focus event in FF (boo! hiss!). In IE, we use onfocusin for before focus and onfocus for focus.
code »
dispatchFocus_()
Dispatches a focus event.
code »
dispatchLoadEvent_()
Signal that the field is loaded and ready to use. Change events now are in effect.
code »
dispatchSelectionChangeEvent(opt_e)
Dispatch a selection change event, optionally caused by the given browser event.
Arguments:
opt_e :
Optional browser event causing this event.
code »
disposeInternal()
Removes all listeners and destroys the eventhandler object.
code »
execCommand(commandvar_args)
Executes an editing command as per the registered plugins.
Arguments:
command :
The command to execute.
var_args :
Object | undefined
Any additional parameters needed to execute the command.
Returns:   False if the command wasn't handled, otherwise, the result of the command.
code »
focus()
No description.
code »
focusAndPlaceCursorAtStart()
No description.
code »
getAppWindow()
Returns the "application" window, where dialogs and bubbles should be rendered.
Returns:   The window.
code »
getBaseZindex()
Returns the zindex of the base level of the field.
Returns:   The base zindex of the editor.
code »
getCleanContents()
Retrieve the HTML contents of a field. Do NOT just get the innerHTML of a field directly--there's a lot of processing that needs to happen.
Returns:   The scrubbed contents of the field.
code »
getEditableDomHelper()
No description.
Returns:   The dom helper for the editable node.
code »
getEditableIframe()
?HTMLIFrameElement
No description.
Returns: 
?HTMLIFrameElement
  The iframe that's body is editable.
code »
getElement()
Returns the editable DOM element or null if this field is not editable.

On IE or Safari this is the element with contentEditable=true (in whitebox mode, the iFrame body).

On Gecko this is the iFrame body TODO: How do we word this for subclass version?

Returns:   The editable DOM element, defined as above.
code »
getFieldCopy()
Get the copy of the editable field element, which has the innerHTML set correctly.
Returns:   The copy of the editable field.
code »
getFieldFormatInfo(extraStyles)
No description.
Arguments:
extraStyles :
A map of extra styles.
Returns:   The FieldFormatInfo object for this field's configuration.
code »
getHashCode()
Returns a string usable as a hash code for this field. For field's that were created with an id, the hash code is guaranteed to be the id. TODO: I think we can get rid of this. Seems only used from editor.
Returns:   The hash code for this editable field.
code »
getIframeAttributes()
No description.
Returns:   Get the HTML attributes for this field's iframe.
code »
getInjectableContents(contentsstyles)
Returns prepared contents that can be injected into the editable field.
Arguments:
contents :
The contents to prepare.
styles :
A map that will be populated with styles that should be applied to the field element together with the contents.
Returns:   The prepared contents.
code »
getOriginalElement()
Returns original DOM element that is being made editable by Trogedit or null if that element has not yet been found in the appropriate document.
Returns:   The original element.
code »
getPluginByClassId(classId)
Returns the registered plugin with the given classId.
Arguments:
classId :
classId of the plugin.
Returns:   Registered plugin with the given classId.
code »
getRange()
No description.
Returns:   Closure range object wrapping the selection in this field or null if this field is not currently editable.
code »
handleBeforeChangeKeyEvent_(e)
Handle before change key events and fire the beforetab event if appropriate. This needs to happen on keydown in IE and keypress in FF.
Arguments:
e :
The browser event.
Returns:   Whether to still perform the default key action. Only set to true if the actual event has already been canceled.
code »
handleChange()
No description.
code »
handleDomAttrChange(handlere)
Fires a change event only if the attribute change effects the editiable field. We ignore events that are internal browser events (ie scrollbar state change)
Arguments:
handler :
The function to call if this is not an internal browser event.
e :
The browser event.
code »
handleDrop_(e)
Handle drop events. Deal with focus/selection issues and set the document as changed.
Arguments:
e :
The browser event.
code »
handleFieldLoad()
Handle the loading of the field (e.g. once the field is ready to setup). TODO: this should probably just be moved into dispatchLoadEvent_.
code »
handleKeyDown_(e)
Handles keydown on the field.
Arguments:
e :
The browser event.
code »
handleKeyPress_(e)
Handles keypress on the field.
Arguments:
e :
The browser event.
code »
handleKeyUp_(e)
Handles keyup on the field.
Arguments:
e :
The browser event.
code »
handleKeyboardShortcut_(e)
Handles keyboard shortcuts on the field. Note that we bake this into our handleKeyPress/handleKeyDown rather than using goog.events.KeyHandler or goog.ui.KeyboardShortcutHandler for performance reasons. Since these are handled on every key stroke, we do not want to be going out to the event system every time.
Arguments:
e :
The browser event.
code »
handleMouseDown_(e)
Handle mouse down inside the editable field.
Arguments:
e :
The event.
code »
handleMouseUp_(e)
Handle mouse up inside the editable field.
Arguments:
e :
The event.
code »
handleMutationEventGecko_(e)
Handle a mutation event.
Arguments:
e :
The browser event.
code »
iframeFieldLoadHandler(iframeinnerHtmlstyles)
The function to call when the editable iframe loads.
Arguments:
iframe :
HTMLIFrameElement
Iframe that just loaded.
innerHtml :
Html to put inside the body of the iframe.
styles :
Property-value map of CSS styles to install on editable field.
code »
inModalMode()
No description.
Returns:   Whether we're in modal interaction mode. When this returns true, another plugin is interacting with the field contents in a synchronous way, and expects you not to make changes to the field's DOM structure or selection.
code »
injectContents(contentsfield)
Prepare the given contents, then inject them into the editable field.
Arguments:
contents :
The contents to prepare.
field :
The field element.
code »
installStyles()
Installs styles if needed. Only writes styles when they can't be written inline directly into the field.
code »
invokeOp_(opvar_args)
Invoke this operation on all plugins with the given arguments.
Arguments:
op :
goog.editor.Plugin.Op
A plugin op.
var_args :
*
The arguments to the plugin.
code »
invokeShortCircuitingOp_(opvar_args)
Calls all the plugins of the given operation, in sequence, with the given arguments. This is short-circuiting: once one plugin cancels the event, no more plugins will be invoked.
Arguments:
op :
goog.editor.Plugin.Op
A plugin op.
var_args :
*
The arguments to the plugin.
Returns:   True if one of the plugins cancel the event, false otherwise.
code »
isEventStopped(eventType)
Checks if the event of the given type has stopped being dispatched
Arguments:
eventType :
goog.editor.Field.EventType
type of event to check.
Returns:   true if the event has been stopped with stopEvent().
code »
isFixedHeight()
No description.
Returns:   Whether the field should be rendered with a fixed height, or should expand to fit its contents.
code »
isLoaded()
No description.
Returns:   Whether the field has finished loading.
code »
isLoading()
No description.
Returns:   Whether the field is in the process of loading.
code »
isModified(opt_useIsEverModified)
Checks the modified state of the field. Note: Changes that take place while the goog.editor.Field.EventType.CHANGE event is stopped do not effect the modified state.
Arguments:
opt_useIsEverModified :
Set to true to check if the field has ever been modified since it was created, otherwise checks if the field has been modified since the last goog.editor.Field.EventType.DELAYEDCHANGE event was dispatched.
Returns:   Whether the field has been modified.
code »
isSelectionEditable()
No description.
Returns:   Whether the selection is editable.
code »
isUneditable()
No description.
Returns:   Whether the field is uneditable.
code »
makeEditable(opt_iframeSrc)
Makes a field editable.
Arguments:
opt_iframeSrc :
URL to set the iframe src to if necessary.
code »
makeEditableInternal(opt_iframeSrc)
Handles actually making something editable - creating necessary nodes, injecting content, etc.
Arguments:
opt_iframeSrc :
URL to set the iframe src to if necessary.
code »
makeIframeField_(opt_iframeSrc)
Start the editable iframe creation process for Mozilla or IE whitebox. The iframes load asynchronously.
Arguments:
opt_iframeSrc :
URL to set the iframe src to if necessary.
code »
makeUneditable(opt_skipRestore)
Closes the field and cancels all pending change timers. Note that this means that if a change event has not fired yet, it will not fire. Clients should check fieldOj.isModified() if they depend on the final change event. Throws an error if the field is already uneditable.
Arguments:
opt_skipRestore :
True to prevent copying of editable field contents back into the original node.
code »
manipulateDom(funcopt_preventDelayedChangeopt_handler)
Calls a function to manipulate the dom of this field. This method should be used whenever Trogedit clients need to modify the dom of the field, so that delayed change events are handled appropriately. Extra delayed change events will cause undesired states to be added to the undo-redo stack. This method will always fire at most one delayed change event, depending on the value of {@code opt_preventDelayedChange}.
Arguments:
func :
function()
The function to call that will manipulate the dom.
opt_preventDelayedChange :
Whether delayed change should be prevented after calling {@code func}. Defaults to always firing delayed change.
opt_handler :
Object in whose scope to call the listener.
code »
placeCursorAtStart()
No description.
code »
queryCommandValue(commands)
Gets the value of command(s).
Arguments:
commands :
String name(s) of the command.
Returns:   Value of each command. Returns false (or array of falses) if designMode is off or the field is otherwise uneditable, and there are no activeOnUneditable plugins for the command.
code »
queryCommandValueInternal_(commandisEditable)
string | boolean | null
Gets the value of this command.
Arguments:
command :
The command to check.
isEditable :
Whether the field is currently editable.
Returns: 
string | boolean | null
  The state of this command. Null if not handled. False if the field is uneditable and there are no handlers for uneditable commands.
code »
reduceOp_(opargvar_args)
Reduce this argument over all plugins. The result of each plugin invocation will be passed to the next plugin invocation. See goog.array.reduce.
Arguments:
op :
goog.editor.Plugin.Op
A plugin op.
arg :
The argument to reduce. For now, we assume it's a string, but we should widen this later if there are reducing plugins that don't operate on strings.
var_args :
*
Any extra arguments to pass to the plugin. These args will not be reduced.
Returns:   The reduced argument.
code »
registerPlugin(plugin)
Registers the plugin with the editable field.
Arguments:
plugin :
The plugin to register.
code »
removeAllWrappers()
No description.
code »
resetOriginalElemProperties()
No description.
code »
restoreDom()
Restores the dom to how it was before being made editable.
code »
setAppWindow(appWindow)
Sets the application window.
Arguments:
appWindow :
The window where dialogs and bubbles should be rendered.
code »
setBaseZindex(zindex)
Sets the zIndex that the field should be based off of. TODO: Get rid of this completely. Here for Sites. Should this be set directly on UI plugins?
Arguments:
zindex :
The base zIndex of the editor.
code »
setHtml(addParashtmlopt_dontFireDelayedChangeopt_applyLorem)
Sets the contents of the field.
Arguments:
addParas :
Boolean to specify whether to add paragraphs to long fields.
html :
html to insert. If html=null, then this defaults to a nsbp for mozilla and an empty string for IE.
opt_dontFireDelayedChange :
True to make this content change not fire a delayed change event.
opt_applyLorem :
Whether to apply lorem ipsum styles.
code »
setInitialStyle(cssText)
Sets the value that will replace the style attribute of this field's element when the field is made non-editable. This method is called with the current value of the style attribute when the field is made editable.
Arguments:
cssText :
The value of the style attribute.
code »
setInnerHtml_(html)
Sets the inner HTML of the field. Works on both editable and uneditable fields.
Arguments:
html :
The new inner HTML of the field.
code »
setModalMode(inModalMode)
No description.
Arguments:
inModalMode :
Sets whether we're in modal interaction mode.
code »
setupChangeListeners_()
Initialize listeners on the field.
code »
setupFieldObject(field)
Sets up the field object and window util of this field, and enables this editable field with all registered plugins. This is essential to the initialization of the field. It must be called when the field becomes fully loaded and editable.
Arguments:
field :
The field property.
code »
setupMutationEventHandlersGecko()
Mutation events tell us when something has changed for mozilla.
code »
shouldLoadAsynchronously()
Returns true if the field needs to be loaded asynchrnously.
Returns:   True if loads are async.
code »
startChangeEvents(opt_fireChangeopt_fireDelayedChange)
Start change events again and fire once if desired.
Arguments:
opt_fireChange :
Whether to fire the change event immediately.
opt_fireDelayedChange :
Whether to fire the delayed change event immediately.
code »
startEvent(eventType)
Re-starts the event of the given type being dispatched, if it had previously been stopped with stopEvent().
Arguments:
eventType :
goog.editor.Field.EventType
type of event to start.
code »
stopChangeEvents(opt_stopChangeopt_stopDelayedChange)
Temporarily ignore change events. If the time has already been set, it will fire immediately now. Further setting of the timer is stopped and dispatching of events is stopped until startChangeEvents is called.
Arguments:
opt_stopChange :
Whether to ignore base change events.
opt_stopDelayedChange :
Whether to ignore delayed change events.
code »
stopEvent(eventType)
Stops the event of the given type from being dispatched.
Arguments:
eventType :
goog.editor.Field.EventType
type of event to stop.
code »
tearDownFieldObject_()
Help make the field not editable by setting internal data structures to null, and disabling this field with all registered plugins.
code »
turnOnDesignModeGecko()
Attemps to turn on designMode for a document. This function can fail under certain circumstances related to the load event, and will throw an exception.
code »
unregisterPlugin(plugin)
Unregisters the plugin with this field.
Arguments:
plugin :
The plugin to unregister.
code »
usesIframe()
No description.
Returns:   Whether the field is implemented as an iframe.
code »
writeIframeContent(iframeinnerHtmlextraStyles)
Writes the html content into the iframe. Handles writing any aditional styling as well.
Arguments:
iframe :
HTMLIFrameElement
Iframe to write contents into.
innerHtml :
The html content to write into the iframe.
extraStyles :
A map of extra style attributes.
code »
addEventListener(typehandleropt_captureopt_handlerScope)
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. Supported for legacy but use goog.events.listen(src, type, handler) instead.
Arguments:
type :
The type of the event to listen for.
handler :
The function to handle the event. The handler can also be an object that implements the handleEvent method which takes the event object as argument.
opt_capture :
In DOM-compliant browsers, this determines whether the listener is fired during the capture or bubble phase of the event.
opt_handlerScope :
Object in whose scope to call the listener.
code »
dispatchEvent(e)
Dispatches an event (or event like object) and calls all listeners listening for events of this type. The type of the event is decided by the type property on the event object. If any of the listeners returns false OR calls preventDefault then this function will return false. If one of the capture listeners calls stopPropagation, then the bubble listeners won't fire.
Arguments:
e :
Event object.
Returns:   If anyone called preventDefault on the event object (or if any of the handlers returns false this will also return false.
code »
disposeInternal()
Unattach 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, it should be something like this:
MyClass.prototype.disposeInternal = function() {
MyClass.superClass_.disposeInternal.call(this);
// Dispose logic for MyClass
};
code »
getParentEventTarget()
Returns the parent of this event target to use for bubbling.
Returns:   The parent EventTarget or null if there is no parent.
code »
removeEventListener(typehandleropt_captureopt_handlerScope)
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 :
The type of the event to listen for.
handler :
The function to handle the event. The handler can also be an object that implements the handleEvent method which takes the event object as argument.
opt_capture :
In DOM-compliant browsers, this determines whether the listener is fired during the capture or bubble phase of the event.
opt_handlerScope :
Object in whose scope to call the listener.
code »
setParentEventTarget(parent)
Sets the parent of this event target to use for bubbling.
Arguments:
parent :
Parent EventTarget (null if none).
code »
dispose()
No description.
code »
disposeInternal()
Deletes or nulls out any references to COM objects, DOM nodes, or other disposable objects. Classes that extend {@code goog.Disposable} should override this method. For example:
mypackage.MyClass = function() {
goog.Disposable.call(this);
// Constructor logic specific to MyClass.
...
};
goog.inherits(mypackage.MyClass, goog.Disposable);

mypackage.MyClass.prototype.disposeInternal = function() {
mypackage.MyClass.superClass_.disposeInternal.call(this);
// Dispose logic specific to MyClass.
...
};
code »
getDisposed()
No description.
Returns:   Whether the object has been disposed of.
code »
isDisposed()
No description.
Returns:   Whether the object has been disposed of.
code »

Instance Properties

field :
The editable dom node.
Code »
inModalMode_ :
Whether this field is in "modal interaction" mode. This usually means that it's being edited by a dialog.
Code »
Logging object.
Code »
originalElement :
The original node that is being made editable, or null if it has not yet been found.
Code »
customEvent_ :
Used to tell if an event is a real event in goog.events.listen() so we don't get listen() calling addEventListener() and vice-versa.
Code »
parentEventTarget_ :
Parent event target, used during event bubbling.
Code »
disposed_ :
Whether the object has been disposed of.
Code »

Static Methods

goog.editor.Field.cancelLinkClick_(e)
Event handler for clicks in browsers that will follow a link when the user clicks, even if it's editable. We stop the click manually
Arguments:
e :
The event.
code »
goog.editor.Field.getActiveFieldId()
No description.
Returns:   The id of the active field.
code »
goog.editor.Field.isGeneratingKey_(etestAllKeys)
Returns true if the keypress generates a change in contents.
Arguments:
e :
The event.
testAllKeys :
True to test for all types of generating keys. False to test for only the keys found in goog.editor.Field.KEYS_CAUSING_CHANGES_.
Returns:   Whether the keypress generates a change in contents.
code »
goog.editor.Field.isSpecialGeneratingKey_(e)
Returns true if the keypress generates a change in the contents. due to a special key listed in goog.editor.Field.KEYS_CAUSING_CHANGES_
Arguments:
e :
The event.
Returns:   Whether the keypress generated a change in the contents.
code »
goog.editor.Field.setActiveFieldId(fieldId)
Sets the active field id.
Arguments:
fieldId :
The active field id.
code »

Static Properties

goog.editor.Field.CHANGE_FREQUENCY :
Number of milliseconds after a change when the change event should be fired.
Code »
goog.editor.Field.CTRL_KEYS_CAUSING_CHANGES_ :
Map of keyCodes (not charCodes) that when used in conjunction with the Ctrl key cause changes in the field contents. These are the keys that are not handled by basic formatting trogedit plugins.
Code »
goog.editor.Field.CTRL_KEYS_CAUSING_SELECTION_CHANGES_ :
Map of keyCodes (not charCodes) that when used in conjunction with the Ctrl key cause selection changes in the field contents. These are the keys that are not handled by the basic formatting trogedit plugins. Note that combinations like Ctrl-left etc are already handled in SELECTION_CHANGE_KEYCODES_
Code »
goog.editor.Field.DEBOUNCE_TIME_MS_ :
The amount of time that a debounce blocks an event. TODO: As of 9/30/07, this is only used for blocking a keyup event after a keydown. We might need to tweak this for other types of events. Maybe have a per-event debounce time?
Code »
goog.editor.Field.DELAYED_CHANGE_FREQUENCY :
Number of milliseconds between delayed change events.
Code »
goog.editor.Field.KEYS_CAUSING_CHANGES_ :
Map of keyCodes (not charCodes) that cause changes in the field contents.
Code »
goog.editor.Field.MUTATION_EVENTS_GECKO :
List of mutation events in Gecko browsers.
Code »
goog.editor.Field.POTENTIAL_SHORTCUT_KEYCODES_ :
Map of keyCodes (not charCodes) that might need to be handled as a keyboard shortcut (even when ctrl/meta key is not pressed) by some plugin. Currently it is a small list. If it grows too big we can optimize it by using ranges or extending it from SELECTION_CHANGE_KEYCODES_
Code »
goog.editor.Field.SELECTION_CHANGE_FREQUENCY_ :
Frequency to check for selection changes.
Code »
goog.editor.Field.activeFieldId_ :
There is at most one "active" field at a time. By "active" field, we mean a field that has focus and is being used.
Code »

Package editor

Package Reference