goog.fx.AbstractDragDrop
Provided By | |
---|---|
Extends | |
All Implemented Interfaces | |
All Known Direct Subclasses |
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 than a single 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 occurring.
new AbstractDragDrop()
Parameters | None. |
---|
Instance Methods
this.addEventListener( type, handler, opt_capture, opt_handlerScope ) → void
void
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.
warning Deprecated | Use |
---|
Defined by | |||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Parameters |
|
this.addItem( element ) → void
void
Add item to drag object.
Parameters |
| ||||
---|---|---|---|---|---|
Throws |
|
this.addOnDisposeCallback<T>( callback, opt_scope ) → void
void
Invokes a callback function when this object is disposed. Callbacks are invoked in the order in which they were added. If a callback is added to an already disposed Disposable, it will be called immediately.
Defined by | |||||||||
---|---|---|---|---|---|---|---|---|---|
Parameters |
|
this.addScrollableContainer( element ) → void
void
Makes drag and drop aware of a target container that could scroll mid drag.
Parameters |
|
---|
this.addTarget( target ) → void
void
Associate drop target with drag element.
Parameters |
|
---|
this.afterEndDrag( opt_dropTarget ) → void
void
Called after a drag operation has finished.
Parameters |
|
---|
this.createDragElement( sourceEl ) → (Element|null)
(Element|null)
Creates an element for the item being dragged.
Parameters |
| ||||
---|---|---|---|---|---|
Returns |
|
this.createDragElementInternal( sourceEl ) → Element
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.
Parameters |
| ||||
---|---|---|---|---|---|
Returns |
|
this.createDraggerFor( sourceEl, el, event ) → goog.fx.Dragger
goog.fx.Dragger
Creates the Dragger for the drag element.
Parameters |
| ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Returns |
|
this.dispatchEvent( e ) → boolean
boolean
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.
Overrides | |||||
---|---|---|---|---|---|
Specified by | |||||
Parameters |
| ||||
Returns |
|
this.dispose() → ?
?
Disposes of the object and its resources.
Overrides | ||
---|---|---|
Specified by | ||
Parameters | None. | |
Returns |
|
this.disposeDrag() → void
void
Called once a drag operation has finished. Removes event listeners and elements.
this.disposeInternal() → void
void
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.
Overrides | |
---|---|
Parameters | None. |
this.disposeItem( item ) → void
void
Called when removing an item. Removes event listeners and classes.
Parameters |
|
---|
this.endDrag( event ) → void
void
Event handler that's used to stop drag. Fires a drop event if over a valid target.
Parameters |
|
---|
this.fireListeners<EVENTOBJ>( type, capture, eventObject ) → boolean
boolean
Fires all registered listeners in this listenable for the given type and capture mode, passing them the given eventObject. This does not perform actual capture/bubble. Only implementors of the interface should be using this.
Overrides | |||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Specified by | |||||||||||||
Parameters |
| ||||||||||||
Returns |
|
this.getDisposed() → boolean
boolean
warning Deprecated | Use |
---|
Defined by | |||
---|---|---|---|
Parameters | None. | ||
Returns |
|
this.getDragElementPosition( el, dragEl, event ) → goog.math.Coordinate
goog.math.Coordinate
Returns the position for the drag element.
Parameters |
| ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Returns |
|
this.getDragger() → (goog.fx.Dragger|null)
(goog.fx.Dragger|null)
Returns the dragger object.
Parameters | None. | ||
---|---|---|---|
Returns |
|
this.getElementBox( item, element ) → goog.math.Box
goog.math.Box
Calculates the position and dimension of a draggable element.
Parameters |
| ||||||||
---|---|---|---|---|---|---|---|---|---|
Returns |
|
this.getEventPosition( event ) → goog.math.Coordinate
goog.math.Coordinate
Get the position of a drag event.
Parameters |
| ||||
---|---|---|---|---|---|
Returns |
|
this.getListener<SCOPE, EVENTOBJ>( type, listener, capture, opt_listenerScope ) → (goog.events.ListenableKey|null)
(goog.events.ListenableKey|null)
Gets the goog.events.ListenableKey for the event or null if no such listener is in use.
Overrides | |||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Specified by | |||||||||||||||||
Parameters |
| ||||||||||||||||
Returns |
|
this.getListeners<EVENTOBJ>( type, capture ) → Array<goog.events.ListenableKey>
Array<goog.events.ListenableKey>
Gets all listeners in this listenable for the given type and capture mode.
Overrides | |||||||||
---|---|---|---|---|---|---|---|---|---|
Specified by | |||||||||
Parameters |
| ||||||||
Returns |
|
this.getParentEventTarget() → (goog.events.Listenable|null)
(goog.events.Listenable|null)
Returns the parent of this event target to use for capture/bubble mechanism.
NOTE(chrishenry): The name reflects the original implementation of
custom event target (goog.events.EventTarget
). We decided
that changing the name is not worth it.
Overrides | |||
---|---|---|---|
Specified by | |||
Parameters | None. | ||
Returns |
|
this.getScrollPos() → goog.math.Coordinate
goog.math.Coordinate
Gets the scroll distance as a coordinate object, using the window of the current drag element's dom.
Parameters | None. | ||
---|---|---|---|
Returns |
|
this.hasListener<EVENTOBJ>( opt_type, opt_capture ) → boolean
boolean
Whether there is any active listeners matching the specified signature. If either the type or capture parameters are unspecified, the function will match on the remaining criteria.
Overrides | |||||||||
---|---|---|---|---|---|---|---|---|---|
Specified by | |||||||||
Parameters |
| ||||||||
Returns |
|
this.init() → void
void
Initialize drag and drop functionality for sources/targets already added. Sources/targets added after init has been called will initialize themselves one by one.
this.initItem( item ) → void
void
this.isDisposed() → boolean
boolean
Overrides | |||
---|---|---|---|
Specified by | |||
Parameters | None. | ||
Returns |
|
this.isInitialized() → boolean
boolean
Whether the control has been initialized.
Parameters | None. | ||
---|---|---|---|
Returns |
|
this.isInside( x, y, box ) → boolean
boolean
Checks whatever a given point is inside a given box.
warning Deprecated | Use goog.math.Box.contains. |
---|
Parameters |
| ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Returns |
|
this.listen<SCOPE, EVENTOBJ>( type, listener, opt_useCapture, opt_listenerScope ) → goog.events.ListenableKey
goog.events.ListenableKey
Adds an event listener. A listener can only be added once to an object and if it is added again the key for the listener is returned. Note that if the existing listener is a one-off listener (registered via listenOnce), it will no longer be a one-off listener after a call to listen().
Overrides | |||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Specified by | |||||||||||||||||
Parameters |
| ||||||||||||||||
Returns |
|
this.listenOnce<SCOPE, EVENTOBJ>( type, listener, opt_useCapture, opt_listenerScope ) → goog.events.ListenableKey
goog.events.ListenableKey
Adds an event listener that is removed automatically after the listener fired once.
If an existing listener already exists, listenOnce will do nothing. In particular, if the listener was previously registered via listen(), listenOnce() will not turn the listener into a one-off listener. Similarly, if there is already an existing one-off listener, listenOnce does not modify the listeners (it is still a once listener).
Overrides | |||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Specified by | |||||||||||||||||
Parameters |
| ||||||||||||||||
Returns |
|
this.maybeStartDrag( event, item ) → void
void
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.
Parameters |
|
---|
this.recalculateDragTargets() → void
void
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.
this.recalculateScrollableContainers() → void
void
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.
this.registerDisposable( disposable ) → void
void
Associates a disposable object with this object so that they will be disposed together.
Defined by | |||||
---|---|---|---|---|---|
Parameters |
|
this.removeAllListeners( opt_type ) → number
number
Removes all listeners from this listenable. If type is specified, it will only remove listeners of the particular type. otherwise all registered listeners will be removed.
Overrides | |||||
---|---|---|---|---|---|
Specified by | |||||
Parameters |
| ||||
Returns |
|
this.removeAllScrollableContainers() → void
void
Removes all scrollable containers.
this.removeEventListener( type, handler, opt_capture, opt_handlerScope ) → void
void
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.
warning Deprecated | Use |
---|
Defined by | |||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Parameters |
|
this.removeItems() → void
void
Removes all items.
this.removeTarget( target ) → void
void
Removes the specified target from the list of drop targets.
Parameters |
|
---|
this.setDragClass( className ) → void
void
Set class to add to source elements being dragged.
Parameters |
|
---|
this.setParentEventTarget( parent ) → void
void
Sets the parent of this event target to use for capture/bubble mechanism.
Defined by | |||||
---|---|---|---|---|---|
Parameters |
|
this.setScrollTarget( scrollTarget ) → void
void
Sets the SCROLL event target to make drag element follow scrolling.
Parameters |
|
---|
this.setSourceClass( className ) → void
void
Set class to add to source elements.
Parameters |
|
---|
this.setSubtargetFunction( f ) → void
void
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
Parameters |
|
---|
this.setTargetClass( className ) → void
void
Set class to add to target elements.
Parameters |
|
---|
this.setTargetForTesting( target ) → void
void
Sets the target to be used for event.target
when firing
event. Mainly used for testing. For example, see
goog.testing.events.mixinListenable
.
Defined by | |||||
---|---|---|---|---|---|
Parameters |
|
this.startDrag( event, item ) → void
void
Event handler that's used to start drag.
Parameters |
|
---|
this.unlisten<SCOPE, EVENTOBJ>( type, listener, opt_useCapture, opt_listenerScope ) → boolean
boolean
Removes an event listener which was added with listen() or listenOnce().
Overrides | |||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Specified by | |||||||||||||||||
Parameters |
| ||||||||||||||||
Returns |
|
this.unlistenByKey( key ) → boolean
boolean
Removes an event listener which was added with listen() by the key returned by listen().
Overrides | |||||
---|---|---|---|---|---|
Specified by | |||||
Parameters |
| ||||
Returns |
|
Instance Properties
this.creationStack → (string|undefined)
(string|undefined)
If monitoring the goog.Disposable instances is enabled, stores the creation stack trace of the Disposable instance.
this.items_ → (Array<(goog.fx.DragDropItem|null)>|null)
(Array<(goog.fx.DragDropItem|null)>|null)
List of items that makes up the drag source or drop target.
Static Properties
AbstractDragDrop.initDragDistanceThreshold → number
number
Constant for distance threshold, in pixels, an element has to be moved to initiate a drag operation.