The goog.fx.AbstractDragDrop Class

goog.fx.AbstractDragDrop
> goog.events.EventTarget
> goog.Disposable

goog.fx.AbstractDragDrop()

Abstract class that provides reusable functionality for implementing drag and drop functionality. This class also allows clients to define their own subtargeting function so that drop areas can have finer granularity then a singe element. This is accomplished by using a client provided function to map from element and coordinates to a subregion id. This class can also be made aware of scrollable containers that contain drop targets by calling addScrollableContainer. This will cause dnd to take changing scroll positions into account while a drag is occuring.

.EventType {Object}

Constants for event names

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

.addItem(element)

Add item to drag object.

element {Element|string}
Dom Node, or string representation of node id, to be used as drag source/drop target.
@throws
Error Thrown if called on instance of abstract class

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

.addScrollableContainer(element)

Makes drag and drop aware of a target container that could scroll mid drag.

element {Element}
The scroll container.

.addTarget(target)

Associate drop target with drag element.

target {goog.fx.AbstractDragDrop}
Target to add.

.createDragElement(sourceEl)

Creates an element for the item being dragged.

sourceEl {Element}
Drag source element.
returns {Element}
The new drag element.

.creationStack {string}

Inherited from goog.Disposable .

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

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

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

.endDrag(event)

Event handler that's used to stop drag. Fires a drop event if over a valid target.

event {goog.fx.DragEvent}
Drag event.

.getDragElementPosition(el, dragEl, event)

Returns the position for the drag element.

el {Element}
Drag source element.
dragEl {Element}
The dragged element created by createDragElement().
event {goog.events.BrowserEvent}
Mouse down event for start of drag.
returns {goog.math.Coordinate}
The position for the drag element.

.getDragger()

Returns the dragger object.

returns {goog.fx.Dragger}
The dragger object used by this drag and drop instance.

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

.init()

Initialize drag and drop functionality for sources/targets already added. Sources/targets added after init has been called will initialize themselves one by one.

.initDragDistanceThreshold {number}

Constant for distance threshold, in pixels, an element has to be moved to initiate a drag operation.

.isDisposed()

Inherited from goog.Disposable .

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

.isInitialized()

Whether the control has been initialized.

returns {boolean}
True if it's been initialized.

.maybeStartDrag(event, item)

Starts a drag event for an item if the mouse button stays pressed and the cursor moves a few pixels. Allows dragging of items without first having to register them with addItem.

event {goog.events.BrowserEvent}
Mouse down event.
item {goog.fx.DragDropItem}
Item that's being dragged.

.recalculateDragTargets()

Recalculates the geometry of this source's drag targets. Call this if the position or visibility of a drag target has changed during a drag, or if targets are added or removed. TODO(user): this is an expensive operation; more efficient APIs may be necessary.

.recalculateScrollableContainers()

Recalculates the current scroll positions of scrollable containers and allocates targets. Call this if the position of a container changed or if targets are added or removed.

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

.removeAllScrollableContainers()

Removes all scrollable containers.

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

.removeItems()

Removes all items.

.setDragClass(className)

Set class to add to source elements being dragged.

className {string}
Class to be added.

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

.setScrollTarget(scrollTarget)

Sets the SCROLL event target to make drag element follow scrolling.

scrollTarget {EventTarget}
The element that dispatches SCROLL events.

.setSourceClass(className)

Set class to add to source elements.

className {string}
Class to be added.

.setSubtargetFunction(f)

Set a function that provides subtargets. A subtargeting function returns an arbitrary identifier for each subtarget of an element. DnD code will generate additional drag over / out events when switching from subtarget to subtarget. This is useful for instance if you are interested if you are on the top half or the bottom half of the element. The provided function will be given the DragDropItem, box, x, y box is the current window coordinates occupied by element x, y is the mouse position in window coordinates

f {Function}
The new subtarget function.

.setTargetClass(className)

Set class to add to target elements.

className {string}
Class to be added.

.startDrag(event, item)

Event handler that's used to start drag.

event {goog.events.BrowserEvent}
Mouse move event.
item {goog.fx.DragDropItem}
Item that's being dragged.