The goog.editor.Field Class

goog.editor.Field
> goog.events.EventTarget
> goog.Disposable

goog.editor.Field(id, opt_doc)

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

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

.CHANGE_FREQUENCY {number}

Number of milliseconds after a change when the change event should be fired.

.DELAYED_CHANGE_FREQUENCY {number}

Number of milliseconds between delayed change events.

The goog.editor.Field.EventType Enum

Event types that can be stopped/started. … more

.addEventListener(type, handler, opt_capture, opt_handlerScope)

Inherited from goog.events.EventTarget .

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.

type {string}
The type of the event to listen for.
handler {Function|Object}
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 {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.

.addListener(type, listener, opt_capture, opt_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.

type {string|Array.<string>}
Event type to listen for or array of event types, for example goog.events.EventType.KEYDOWN.
listener {Function}
Function to be used as the listener.
opt_capture {boolean=}
Whether to use capture phase (optional, defaults to false).
opt_handler {Object=}
Object in whose scope to call the listener.

.addOnDisposeCallback(callback, opt_scope)

Inherited from goog.Disposable .

Invokes a callback function when this object is disposed. Callbacks are invoked in the order in which they were added.

callback {!Function}
The callback function.
opt_scope {Object=}
An optional scope to call the callback in.

.attachWrapper(wrapper)

Attach an wrapper to this field, to be thrown out when the field is disposed.

wrapper {goog.Disposable}
The wrapper to attach.

.clearDelayedChange()

Don't wait for the timer and just fire the delayed change event if it's pending.

.creationStack {string}

Inherited from goog.Disposable .

If monitoring the goog.Disposable instances is enabled, stores the creation stack trace of the Disposable instance.

.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.

eventType {goog.editor.Field.EventType}
type of event to debounce.

.dispatchBeforeChange()

This dispatches the beforechange event on the editable field

.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.

opt_noDelay {boolean=}
True if goog.editor.Field.EventType.DELAYEDCHANGE should be fired syncronously.

.dispatchCommandValueChange(opt_commands)

Dispatches a command value change event.

opt_commands {Array.<string>=}
Commands whose state has changed.

.dispatchEvent(e)

Inherited from goog.events.EventTarget .

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.

e {string|Object|goog.events.Event}
Event object.
returns {boolean}
If anyone called preventDefault on the event object (or if any of the handlers returns false this will also return false.

.dispatchSelectionChangeEvent(opt_e, opt_target)

Dispatch a selection change event, optionally caused by the given browser event or selecting the given target.

opt_e {goog.events.BrowserEvent=}
Optional browser event causing this event.
opt_target {Node=}
The node the selection changed to.

.dispose()

Inherited from goog.Disposable .

Disposes of the object. If the object hasn't already been disposed of, calls {@link #disposeInternal}. Classes that extend {@code goog.Disposable} should override {@link #disposeInternal} in order to delete references to COM objects, DOM nodes, and other disposable objects. Reentrant.

returns {void}
Nothing.

.execCommand(command, var_args)

Executes an editing command as per the registered plugins.

command {string}
The command to execute.
var_args {...*}
Any additional parameters needed to execute the command.
returns {*}
False if the command wasn't handled, otherwise, the result of the command.

.field {Element}

The editable dom node.

.focus()

Gives the field focus.

.focusAndPlaceCursorAtStart()

Gives the field focus and places the cursor at the start of the field.

.getActiveFieldId()

returns {?string}
The id of the active field.

.getAppWindow()

Returns the "application" window, where dialogs and bubbles should be rendered.

returns {!Window}
The window.

.getBaseZindex()

Returns the zindex of the base level of the field.

returns {number}
The base zindex of the editor.

.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 {string}
The scrubbed contents of the field.

.getEditableDomHelper()

returns {goog.dom.DomHelper?}
The dom helper for the editable node.

.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(user): How do we word this for subclass version?

returns {Element}
The editable DOM element, defined as above.

.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(user): I think we can get rid of this. Seems only used from editor.

returns {string}
The hash code for this editable field.

.getInjectableContents(contents, styles)

Returns prepared contents that can be injected into the editable field.

contents {?string}
The contents to prepare.
styles {Object}
A map that will be populated with styles that should be applied to the field element together with the contents.
returns {string}
The prepared contents.

.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 {Element}
The original element.

.getParentEventTarget()

Inherited from 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.

.getPluginByClassId(classId)

Returns the registered plugin with the given classId.

classId {string}
classId of the plugin.
returns {goog.editor.Plugin}
Registered plugin with the given classId.

.getRange()

returns {goog.dom.AbstractRange?}
Closure range object wrapping the selection in this field or null if this field is not currently editable.

.handleChange()

Handle a change in the Editable Field. Marks the field has modified, dispatches the change event on the editable field (moz only), starts the timer for the delayed change event. Note that these actions only occur if the proper events are not stopped.

.id {string}

The id for this editable field, which must match the id of the element associated with this field.

.inModalMode()

returns {boolean}
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.

.isDisposed()

Inherited from goog.Disposable .

returns {boolean}
Whether the object has been disposed of.

.isFixedHeight

returns {boolean}
Whether the field should be rendered with a fixed height, or should expand to fit its contents.

.isLoaded()

returns {boolean}
Whether the field has finished loading.

.isLoading()

returns {boolean}
Whether the field is in the process of loading.

.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.

opt_useIsEverModified {boolean=}
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 {boolean}
Whether the field has been modified.

.isSelectionEditable()

returns {boolean}
Whether the selection is editable.

.isUneditable()

returns {boolean}
Whether the field is uneditable.

.makeEditable(opt_iframeSrc)

Makes a field editable.

opt_iframeSrc {string=}
URL to set the iframe src to if necessary.

.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.

opt_skipRestore {boolean=}
True to prevent copying of editable field contents back into the original node.

.manipulateDom(func, opt_preventDelayedChange, opt_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}.

func {function()}
The function to call that will manipulate the dom.
opt_preventDelayedChange {boolean=}
Whether delayed change should be prevented after calling {@code func}. Defaults to always firing delayed change.
opt_handler {Object=}
Object in whose scope to call the listener.

.placeCursorAtEnd()

Place the cursor at the start of this field. It's recommended that you only use this method (and manipulate the selection in general) when there is not an existing selection in the field.

.placeCursorAtStart()

Place the cursor at the start of this field. It's recommended that you only use this method (and manipulate the selection in general) when there is not an existing selection in the field.

.queryCommandValue(commands)

Gets the value of command(s).

commands {string|Array.<string>}
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.

.registerDisposable(disposable)

Inherited from goog.Disposable .

Associates a disposable object with this object so that they will be disposed together.

disposable {goog.disposable.IDisposable}
that will be disposed when this object is disposed.

.registerPlugin(plugin)

Registers the plugin with the editable field.

plugin {goog.editor.Plugin}
The plugin to register.

.removeAllWrappers()

Removes all wrappers and destroys them.

.removeEventListener(type, handler, opt_capture, opt_handlerScope)

Inherited from goog.events.EventTarget .

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.

type {string}
The type of the event to listen for.
handler {Function|Object}
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 {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.

.resetOriginalElemProperties()

Reset the properties on the original field element to how it was before it was made editable.

.setActiveFieldId(fieldId)

Sets the active field id.

fieldId {?string}
The active field id.

.setAppWindow(appWindow)

Sets the application window.

appWindow {!Window}
The window where dialogs and bubbles should be rendered.

.setBaseZindex(zindex)

Sets the zIndex that the field should be based off of. TODO(user): Get rid of this completely. Here for Sites. Should this be set directly on UI plugins?

zindex {number}
The base zIndex of the editor.

.setHtml(addParas, html, opt_dontFireDelayedChange, opt_applyLorem)

Sets the contents of the field.

addParas {boolean}
Boolean to specify whether to add paragraphs to long fields.
html {?string}
html to insert. If html=null, then this defaults to a nsbp for mozilla and an empty string for IE.
opt_dontFireDelayedChange {boolean=}
True to make this content change not fire a delayed change event.
opt_applyLorem {boolean=}
Whether to apply lorem ipsum styles.

.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.

cssText {string}
The value of the style attribute.

.setModalMode(inModalMode)

inModalMode {boolean}
Sets whether we're in modal interaction mode.

.setParentEventTarget(parent)

Inherited from goog.events.EventTarget .

Sets the parent of this event target to use for bubbling.

parent {goog.events.EventTarget?}
Parent EventTarget (null if none).

.shouldRefocusOnInputMobileSafari

returns {boolean}
Whether the field should be refocused on input. This is a workaround for the iOS bug that text input doesn't work when the main window listens touch events.

.startChangeEvents(opt_fireChange, opt_fireDelayedChange)

Start change events again and fire once if desired.

opt_fireChange {boolean=}
Whether to fire the change event immediately.
opt_fireDelayedChange {boolean=}
Whether to fire the delayed change event immediately.

.startEvent(eventType)

Re-starts the event of the given type being dispatched, if it had previously been stopped with stopEvent().

eventType {goog.editor.Field.EventType}
type of event to start.

.stopChangeEvents(opt_stopChange, opt_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.

opt_stopChange {boolean=}
Whether to ignore base change events.
opt_stopDelayedChange {boolean=}
Whether to ignore delayed change events.

.stopEvent(eventType)

Stops the event of the given type from being dispatched.

eventType {goog.editor.Field.EventType}
type of event to stop.

.unregisterPlugin(plugin)

Unregisters the plugin with this field.

plugin {goog.editor.Plugin}
The plugin to unregister.

.usesIframe

returns {boolean}
Whether the field is implemented as an iframe.