goog.editor.Field
Classgoog.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
}
opt_doc
{Document
=}
.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.
goog.editor.Field.EventType
EnumEvent types that can be stopped/started. … more
.MUTATION_EVENTS_GECKO
[protected] {Array
.<string
>}List of mutation events in Gecko browsers.
.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
}
handler
{Function
|Object
}
opt_capture
{boolean
=}
opt_handlerScope
{Object
=}
.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
>}
listener
{Function
}
opt_capture
{boolean
=}
opt_handler
{Object
=}
.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
}
opt_scope
{Object
=}
.attachIframe(iframe)
[protected]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.
iframe
{HTMLIFrameElement
}
.attachWrapper(wrapper)
Attach an wrapper to this field, to be thrown out when the field is disposed.
wrapper
{goog.Disposable
}
.clearDelayedChange()
Don't wait for the timer and just fire the delayed change event if it's pending.
.clearListeners()
[protected]Stops all listeners and timers.
.creationStack
{string
}Inherited from goog.Disposable
.
If monitoring the goog.Disposable instances is enabled, stores the creation stack trace of the Disposable instance.
.cssStyles
[protected] {string
}Additional styles to install for the editable field.
.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
}
.dispatchBeforeChange()
This dispatches the beforechange event on the editable field
.dispatchBlur()
[protected]Dispatches a blur event.
.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
=}
.dispatchCommandValueChange(opt_commands)
Dispatches a command value change event.
opt_commands
{Array
.<string
>=}
.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
}
boolean
}
.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
=}
opt_target
{Node
=}
.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.
void
}
.disposeInternal()
[protected]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 };
.editableDomHelper
[protected] {goog.dom.DomHelper
}Dom helper for the editable node.
.eventRegister
[protected] {goog.events.EventHandler
}.execCommand(command, var_args)
Executes an editing command as per the registered plugins.
command
{string
}
var_args
{...*}
.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()
string
}
.getAppWindow()
Returns the "application" window, where dialogs and bubbles should be rendered.
Window
}
.getBaseZindex()
Returns the zindex of the base level of the field.
number
}
.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.
string
}
.getDisposed
[deprecated]Deprecated. Use {@link #isDisposed} instead.
Inherited from goog.Disposable
.
boolean
}
.getEditableDomHelper()
goog.dom.DomHelper
?}
.getEditableIframe()
[protected]HTMLIFrameElement
}
.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?
Element
}
.getFieldCopy()
[protected]Get the copy of the editable field element, which has the innerHTML set correctly.
Element
}
.getFieldFormatInfo(extraStyles)
[protected]extraStyles
{Object
}
goog.editor.icontent.FieldFormatInfo
}
.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.
string
}
.getIframeAttributes()
[protected]Object
}
.getInjectableContents(contents, styles)
Returns prepared contents that can be injected into the editable field.
contents
{?string
}
styles
{Object
}
string
}
.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.
Element
}
.getParentEventTarget()
Inherited from goog.events.EventTarget
.
Returns the parent of this event target to use for bubbling.
goog.events.EventTarget
}
.getPluginByClassId(classId)
Returns the registered plugin with the given classId.
classId
{string
}
goog.editor.Plugin
}
.getRange()
goog.dom.AbstractRange
?}
.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.
.handleDomAttrChange(handler, browserEvent)
[protected]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)
handler
{Function
}
browserEvent
{goog.events.BrowserEvent
}
.handleFieldLoad()
[protected]Handle the loading of the field (e.g. once the field is ready to setup). TODO(user): this should probably just be moved into dispatchLoadEvent_.
.id
{string
}The id for this editable field, which must match the id of the element associated with this field.
.iframeFieldLoadHandler(iframe, innerHtml, styles)
[protected]The function to call when the editable iframe loads.
iframe
{HTMLIFrameElement
}
innerHtml
{string
}
styles
{Object
}
.inModalMode()
boolean
}
.injectContents(contents, field)
[protected]Prepare the given contents, then inject them into the editable field.
contents
{?string
}
field
{Element
}
.installStyles()
[protected]Installs styles if needed. Only writes styles when they can't be written inline directly into the field.
.isDisposed()
Inherited from goog.Disposable
.
boolean
}
.isEventStopped(eventType)
[protected]Checks if the event of the given type has stopped being dispatched
eventType
{goog.editor.Field.EventType
}
boolean
}
.isFixedHeight
boolean
}
.isLoaded()
boolean
}
.isLoading()
boolean
}
.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
=}
boolean
}
.isSelectionEditable()
boolean
}
.isUneditable()
boolean
}
.logger
[protected] {goog.debug.Logger
}Logging object.
.makeEditable(opt_iframeSrc)
Makes a field editable.
opt_iframeSrc
{string
=}
.makeEditableInternal(opt_iframeSrc)
[protected]Handles actually making something editable - creating necessary nodes, injecting content, etc.
opt_iframeSrc
{string
=}
.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
=}
.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
()}
opt_preventDelayedChange
{boolean
=}
opt_handler
{Object
=}
.originalDomHelper
[protected] {!goog.dom.DomHelper
}.originalElement
[protected] {Element
}.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
>}
.registerDisposable(disposable)
Inherited from goog.Disposable
.
Associates a disposable object with this object so that they will be disposed together.
disposable
{goog.disposable.IDisposable
}
.registerPlugin(plugin)
Registers the plugin with the editable field.
plugin
{goog.editor.Plugin
}
.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
}
handler
{Function
|Object
}
opt_capture
{boolean
=}
opt_handlerScope
{Object
=}
.resetOriginalElemProperties()
Reset the properties on the original field element to how it was before it was made editable.
.restoreDom()
[protected]Restores the dom to how it was before being made editable.
.setActiveFieldId(fieldId)
Sets the active field id.
fieldId
{?string
}
.setAppWindow(appWindow)
Sets the application window.
appWindow
{!Window
}
.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
}
.setHtml(addParas, html, opt_dontFireDelayedChange, opt_applyLorem)
Sets the contents of the field.
addParas
{boolean
}
html
{?string
}
opt_dontFireDelayedChange
{boolean
=}
opt_applyLorem
{boolean
=}
.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
}
.setModalMode(inModalMode)
inModalMode
{boolean
}
.setParentEventTarget(parent)
Inherited from goog.events.EventTarget
.
Sets the parent of this event target to use for bubbling.
parent
{goog.events.EventTarget
?}
.setupFieldObject(field)
[protected]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.
field
{Element
}
.setupMutationEventHandlersGecko()
[protected]Mutation events tell us when something has changed for mozilla.
.shouldLoadAsynchronously()
[protected]Returns true if the field needs to be loaded asynchrnously.
boolean
}
.shouldRefocusOnInputMobileSafari
boolean
}
.startChangeEvents(opt_fireChange, opt_fireDelayedChange)
Start change events again and fire once if desired.
opt_fireChange
{boolean
=}
opt_fireDelayedChange
{boolean
=}
.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
}
.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
=}
opt_stopDelayedChange
{boolean
=}
.stopEvent(eventType)
Stops the event of the given type from being dispatched.
eventType
{goog.editor.Field.EventType
}
.turnOnDesignModeGecko()
[protected]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.
.unregisterPlugin(plugin)
Unregisters the plugin with this field.
plugin
{goog.editor.Plugin
}
.usesIframe
boolean
}
.writeIframeContent(iframe, innerHtml, extraStyles)
[protected]Writes the html content into the iframe. Handles writing any aditional styling as well.
iframe
{HTMLIFrameElement
}
innerHtml
{string
}
extraStyles
{Object
}