fx.AbstractDragDrop Extends goog.events.EventTarget
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.

Inheritance

Constructor

goog.fx.AbstractDragDrop()

Instance Methods

Public Protected Private
addDragTarget_(targetitem)
Add possible drop target for current drag operation.
Arguments:
target : goog.fx.AbstractDragDrop
Drag handler.
item : goog.fx.DragDropItem
Item that's being dragged.
code »
addItem(element)
Add item to drag object.
Arguments:
element : Element | string
Dom Node, or string representation of node id, to be used as drag source/drop target.
code »
addScrollableContainer(element)
Makes drag and drop aware of a target container that could scroll mid drag.
Arguments:
element : Element
The scroll container.
code »
addTarget(target)
Associate drop target with drag element.
Arguments:
target : goog.fx.AbstractDragDrop
Target to add.
code »
afterEndDrag(opt_dropTarget)
Called after a drag operation has finished.
Arguments:
opt_dropTarget : goog.fx.DragDropItem=
Target for successful drop.
code »
calculateTargetBox_(box)
Calculate the outer bounds (the region all targets are inside).
Arguments:
box : goog.math.Box
Box describing the position and dimension of a drag target.
code »
cloneNode_(sourceEl) !Element
Use goog.fx.Dragger.cloneNode(). Creates copy of node being dragged.
Arguments:
sourceEl : Element
Element to copy.
Returns: !Element  The clone of sourceEl.
code »
containerScrollHandler_(e)
Event handler for containers scrolling.
Arguments:
e : goog.events.Event
The event.
code »
createDragElement(sourceEl) Element
Creates an element for the item being dragged.
Arguments:
sourceEl : Element
Drag source element.
Returns: Element  The new drag element.
code »
createDragElementInternal(sourceEl) Element
Generates an element to follow the cursor during dragging, given a drag source element. The default behavior is simply to clone the source element, but this may be overridden in subclasses. This method is called by createDragElement() before the drag class is added.
Arguments:
sourceEl : Element
Drag source element.
Returns: Element  The new drag element.
code »
createDraggerFor(sourceElelevent) !goog.fx.Dragger
Creates the Dragger for the drag element.
Arguments:
sourceEl : Element
Drag source element.
el : Element
the element created by createDragElement().
event : goog.events.BrowserEvent
Mouse down event for start of drag.
Returns: !goog.fx.Dragger  The new Dragger.
code »
disposeDrag()
Called once a drag operation has finished. Removes event listeners and elements.
code »
disposeInternal()
No description.
code »
disposeItem(item)
Called when removing an item. Removes event listeners and classes.
Arguments:
item : goog.fx.DragDropItem
Item to dispose.
code »
disposeScrollableContainerListeners_()
Cleans up the scrollable container listeners.
code »
endDrag(event)
Event handler that's used to stop drag. Fires a drop event if over a valid target.
Arguments:
event : goog.fx.DragEvent
Drag event.
code »
getDragElementPosition(eldragElevent) !goog.math.Coordinate
Returns the position for the drag element.
Arguments:
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.
code »
getDragger() goog.fx.Dragger
Returns the dragger object.
Returns: goog.fx.Dragger  The dragger object used by this drag and drop instance.
code »
getElementBox(itemelement) !goog.math.Box
Calculates the position and dimension of a draggable element.
Arguments:
item : goog.fx.DragDropItem
Item that's being dragged.
element : Element
The element to calculate the box.
Returns: !goog.math.Box  Box describing the position and dimension of element.
code »
getEventPosition(event) !goog.math.Coordinate
Get the position of a drag event.
Arguments:
event : goog.fx.DragEvent
Drag event.
Returns: !goog.math.Coordinate  Position of the event.
code »
getScrollPos() !goog.math.Coordinate
Gets the scroll distance as a coordinate object, using the window of the current drag element's dom.
Returns: !goog.math.Coordinate  Object with scroll offsets 'x' and 'y'.
code »
getTargetFromPosition_(position) Object
Returns the target for a given cursor position.
Arguments:
position : goog.math.Coordinate
Cursor position.
Returns: Object  Target for position or null if no target was defined for the given position.
code »
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.
code »
initItem(item)
Initializes a single item.
Arguments:
item : goog.fx.DragDropItem
Item to initialize.
code »
initScrollableContainerListeners_()
Sets up listeners for the scrollable containers that keep track of their scroll positions.
code »
isInitialized() boolean
Whether the control has been initialized.
Returns: boolean  True if it's been initialized.
code »
isInside(xybox) boolean
Use goog.math.Box.contains. Checks whatever a given point is inside a given box.
Arguments:
x : number
Cursor position on the x-axis.
y : number
Cursor position on the y-axis.
box : goog.math.Box
Box to check position against.
Returns: boolean  Whether the given point is inside box.
code »
maybeCreateDummyTargetForPosition_(xy) goog.fx.ActiveDropTarget_
Creates a dummy target for the given cursor position. The assumption is to create as big dummy target box as possible, the only constraints are: - The dummy target box cannot overlap any of real target boxes. - The dummy target has to contain a point with current mouse coordinates. NOTE: For performance reasons the box construction algorithm is kept simple and it is not optimal (see example below). Currently it is O(n) in regard to the number of real drop target boxes, but its result depends on the order of those boxes being processed (the order in which they're added to the targetList_ collection). The algorithm. a) Assumptions - Mouse pointer is in the bounding box of real target boxes. - None of the boxes have negative coordinate values. - Mouse pointer is not contained by any of "real target" boxes. - For targets inside a scrollable container, the box used is the intersection of the scrollable container's box and the target's box. This is because the part of the target that extends outside the scrollable container should not be used in the clipping calculations. b) Outline - Initialize the fake target to the bounding box of real targets. - For each real target box - clip the fake target box so it does not contain that target box, but does contain the mouse pointer. -- Project the real target box, mouse pointer and fake target box onto both axes and calculate the clipping coordinates. -- Only one coordinate is used to clip the fake target box to keep the fake target as big as possible. -- If the projection of the real target box contains the mouse pointer, clipping for a given axis is not possible. -- If both clippings are possible, the clipping more distant from the mouse pointer is selected to keep bigger fake target area. - Save the created fake target only if it has a big enough area. c) Example
       Input:           Algorithm created box:        Maximum box:
+---------------------+ +---------------------+ +---------------------+
| B1      |        B2 | | B1               B2 | | B1               B2 |
|         |           | |   +-------------+   | |+-------------------+|
|---------x-----------| |   |             |   | ||                   ||
|         |           | |   |             |   | ||                   ||
|         |           | |   |             |   | ||                   ||
|         |           | |   |             |   | ||                   ||
|         |           | |   |             |   | ||                   ||
|         |           | |   +-------------+   | |+-------------------+|
| B4      |        B3 | | B4               B3 | | B4               B3 |
+---------------------+ +---------------------+ +---------------------+
Arguments:
x : number
Cursor position on the x-axis.
y : number
Cursor position on the y-axis.
Returns: goog.fx.ActiveDropTarget_  Dummy drop target.
code »
maybeStartDrag(eventitem)
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.
Arguments:
event : goog.events.BrowserEvent
Mouse down event.
item : goog.fx.DragDropItem
Item that's being dragged.
code »
moveDrag_(event)
Event handler for drag events. Determines the active drop target, if any, and fires dragover and dragout events appropriately.
Arguments:
event : goog.fx.DragEvent
Drag event.
code »
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.
code »
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.
code »
removeAllScrollableContainers()
Removes all scrollable containers.
code »
removeItems()
Removes all items.
code »
setDragClass(className)
Set class to add to source elements being dragged.
Arguments:
className : string
Class to be added. Must be a single, valid classname.
code »
setScrollTarget(scrollTarget)
Sets the SCROLL event target to make drag element follow scrolling.
Arguments:
scrollTarget : EventTarget
The element that dispatches SCROLL events.
code »
setSourceClass(className)
Set class to add to source elements.
Arguments:
className : string
Class to be added. Must be a single, valid classname.
code »
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
Arguments:
f : Function
The new subtarget function.
code »
setTargetClass(className)
Set class to add to target elements.
Arguments:
className : string
Class to be added. Must be a single, valid classname.
code »
startDrag(eventitem)
Event handler that's used to start drag.
Arguments:
event : goog.events.BrowserEvent
Mouse move event.
item : goog.fx.DragDropItem
Item that's being dragged.
code »
suppressSelect_(event) boolean
Event handler for suppressing selectstart events. Selecting should be disabled while dragging.
Arguments:
event : goog.events.Event
The selectstart event to suppress.
Returns: boolean  Whether to perform default behavior.
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

activeSubtarget_ :
Last active subtarget.
Code »
constructor :
No description.
Code »
dragClass_ :
Class name to add to source elements being dragged. Set by setDragClass.
Code »
dummyTarget_ : goog.fx.ActiveDropTarget_
Dummy target, .
Code »
initialized_ :
Whether the object has been initialized.
Code »
isSource_ :
Flag indicating if it's a drag source, set by addTarget.
Code »
isTarget_ :
Flag indicating if it's a drop target, set when added as target to another DragDrop object.
Code »
items_ :
List of items that makes up the drag source or drop target.
Code »
scrollTarget_ :
The SCROLL event target used to make drag element follow scrolling.
Code »
scrollableContainers_ :
Scrollable containers to account for during drag
Code »
sourceClass_ :
Class name to add to source elements. Set by setSourceClass.
Code »
subtargetFunction_ :
Subtargeting function accepting args: (goog.fx.DragDropItem, goog.math.Box, number, number)
Code »
targetClass_ :
Class name to add to target elements. Set by setTargetClass.
Code »
targets_ :
List of associated drop targets.
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 Properties

goog.fx.AbstractDragDrop.DUMMY_TARGET_MIN_SIZE_ :
Minimum size (in pixels) for a dummy target. If the box for the target is less than the specified size it's not created.
Code »
goog.fx.AbstractDragDrop.EventType :
Constants for event names
Code »
goog.fx.AbstractDragDrop.initDragDistanceThreshold :
Constant for distance threshold, in pixels, an element has to be moved to initiate a drag operation.
Code »
goog.fx.AbstractDragDrop.superClass_ :
No description.
Code »

Package fx

Package Reference