Yahoo! UI Library

Drag and Drop  2.5.0

Yahoo! UI Library > dragdrop > YAHOO.util.DragDropMgr

Show Private Show Protected

static Class YAHOO.util.DragDropMgr

DragDropMgr is a singleton that tracks the element interaction for all DragDrop items in the window. Generally, you will not call this class directly, but it does have helper methods that could be useful in your DragDrop implementations.

Properties

_timeoutCount - private static object

Internal counter

clickPixelThresh - static int

The number of pixels that the mouse needs to move after the mousedown before the drag is initiated. Default=3;

clickTimeout - private static Object

Timeout used for the click time threshold

clickTimeThresh - static int

The number of milliseconds after the mousedown event to initiate the drag if we don't get a mouseup event. Default=1000

deltaX - private static int

the X distance between the cursor and the object being dragged

deltaY - private static int

the Y distance between the cursor and the object being dragged

dragCurrent - private static DragDrop

the DragDrop object that is currently being dragged

dragOvers - private static Array

the DragDrop object(s) that are being hovered over

dragThreshMet - private static boolean

Flag that indicates that either the drag pixel threshold or the mousdown time threshold has been met

elementCache - private static object

A cache of DOM elements
Deprecated: elements are not cached now

fromTimeout - private static boolean

Flag to determine if the drag event was fired from the click timeout and not the mouse move threshold.

handleIds - private static {string: string}

Array of element ids defined as drag handles. Used to determine if the element that generated the mousedown event is actually the handle and not the html element itself.

ids - private static {string: string}

Two dimensional Array of registered DragDrop objects. The first dimension is the DragDrop item group, the second the DragDrop object.

initialized - private static object

Internal flag that is set to true when drag and drop has been initialized

interactionInfo - static object

Provides additional information about the the current set of interactions. Can be accessed from the event handlers. It contains the following properties: out: onDragOut interactions enter: onDragEnter interactions over: onDragOver interactions drop: onDragDrop interactions point: The location of the cursor draggedRegion: The location of dragged element at the time of the interaction sourceRegion: The location of the source elemtn at the time of the interaction validDrop: boolean

INTERSECT - static final int

In intersect mode, drag and drop interaction is defined by the cursor position or the amount of overlap of two or more drag and drop objects.

locationCache - private static object

Location cache that is set for all drag drop objects when a drag is initiated, cleared when the drag is finished.

locked - private static object

All drag and drop can be disabled.

mode - static int

The current drag and drop mode. Default: POINT

POINT - static final int

In point mode, drag and drop interaction is defined by the location of the cursor during the drag/drop

preventDefault - static boolean

Flag to determine if we should prevent the default behavior of the events we define. By default this is true, but this can be set to false if you need the default behavior (not recommended)

startX - private static int

The X position of the mousedown event stored for later use when a drag threshold is met.

startY - private static int

The Y position of the mousedown event stored for later use when a drag threshold is met.

stopPropagation - static boolean

Flag to determine if we should stop the propagation of the events we generate. This is true by default but you may want to set it to false if the html element contains other features that require the mouse click.

STRICT_INTERSECT - static final int

In intersect mode, drag and drop interaction is defined only by the overlap of two or more drag and drop objects.

useCache - static boolean

Set useCache to false if you want to force object the lookup of each drag and drop linked element constantly during a drag.

Methods

_addListeners

private static void _addListeners ( )
Trying to make the load order less important. Without this we get an error if this file is loaded before the Event Utility.
Returns: void

_execOnAll

private static void _execOnAll ( )
Runs method on all drag and drop objects
Returns: void

_onLoad

private static void _onLoad ( )
Drag and drop initialization. Sets up the global event handlers
Returns: void

_onResize

private static void _onResize ( )
Reset constraints on all drag and drop objs
Returns: void

_onUnload

private static void _onUnload ( )
unload event handler
Returns: void

_remove

private static void _remove ( )
Unregisters a drag and drop item. This is executed in DragDrop.unreg, use that method instead of calling this directly.
Returns: void

fireEvents

private static void fireEvents ( e , isDrop )
Iterates over all of the DragDrop elements to find ones we are hovering over or dropping on
Parameters:
e <Event> the event
isDrop <boolean> is this a drop op or a mouseover op?
Returns: void

getBestMatch

static DragDrop getBestMatch ( dds )
Helper function for getting the best match from the list of drag and drop objects returned by the drag and drop events when we are in INTERSECT mode. It returns either the first object that the cursor is over, or the object that has the greatest overlap with the dragged element.
Parameters:
dds <DragDrop[]> The array of drag and drop objects targeted
Returns: DragDrop
The best single match

getClientHeight

static int getClientHeight ( )
Gets the client height
Returns: int
client height in px
Deprecated use YAHOO.util.Dom.getViewportHeight instead

getClientWidth

static int getClientWidth ( )
Gets the client width
Returns: int
client width in px
Deprecated use YAHOO.util.Dom.getViewportWidth instead

getCss

static Object getCss ( id )
Returns the style property for the DOM element (i.e., document.getElById(id).style)
Parameters:
id <String> the id of the elment to get
Returns: Object
The style property of the element
Deprecated use YAHOO.util.Dom instead

getDDById

static DragDrop getDDById ( id )
Returns the DragDrop instance for a given id
Parameters:
id <String> the id of the DragDrop object
Returns: DragDrop
the drag drop object, null if it is not found

getElement

static Object getElement ( id )
Returns the actual DOM element
Parameters:
id <String> the id of the elment to get
Returns: Object
The element
Deprecated use YAHOO.util.Dom.get instead

getElWrapper

private static YAHOO.util.DDM.ElementWrapper getElWrapper ( id )
Get the wrapper for the DOM element specified
Parameters:
id <String> the id of the element to get
Returns: YAHOO.util.DDM.ElementWrapper
the wrapped element
Deprecated This wrapper isn't that useful

getLocation

static YAHOO.util.Region getLocation ( oDD )
Returns a Region object containing the drag and drop element's position and size, including the padding configured for it
Parameters:
oDD <DragDrop> the drag and drop object to get the location for
Returns: YAHOO.util.Region
a Region object representing the total area the element occupies, including any padding the instance is configured for.

getPosX

static int getPosX ( el )
Returns the X position of an html element
Parameters:
el <object> the element for which to get the position
Returns: int
the X coordinate
Deprecated use YAHOO.util.Dom.getX instead

getPosY

static int getPosY ( el )
Returns the Y position of an html element
Parameters:
el <object> the element for which to get the position
Returns: int
the Y coordinate
Deprecated use YAHOO.util.Dom.getY instead

getRelated

static DragDrop[] getRelated ( p_oDD , bTargetsOnly )
Returns the drag and drop instances that are in all groups the passed in instance belongs to.
Parameters:
p_oDD <DragDrop> the obj to get related data for
bTargetsOnly <boolean> if true, only return targetable objs
Returns: DragDrop[]
the related instances

getScroll

private static void getScroll ( )
Returns the current scroll position
Returns: void

getScrollLeft

static int getScrollLeft ( )
Gets the scrollLeft
Returns: int
the document's scrollTop

getScrollTop

static int getScrollTop ( )
Gets the scrollTop
Returns: int
the document's scrollTop

getStyle

static string getStyle ( el , styleProp )
Returns the specified element style property
Parameters:
el <HTMLElement> the element
styleProp <string> the style property
Returns: string
The value of the style property
Deprecated use YAHOO.util.Dom.getStyle

handleMouseDown

private static void handleMouseDown ( e , oDD )
Fired after a registered DragDrop object gets the mousedown event. Sets up the events required to track the object being dragged
Parameters:
e <Event> the event
oDD <object> the DragDrop object being dragged
Returns: void

handleMouseMove

private static void handleMouseMove ( e )
Internal function to handle the mousemove event. Will be invoked from the context of the html element.
Parameters:
e <Event> the event
Returns: void

handleMouseUp

private static void handleMouseUp ( e )
Internal function to handle the mouseup event. Will be invoked from the context of the document.
Parameters:
e <Event> the event
Returns: void

handleWasClicked

static void handleWasClicked ( node )
Recursively searches the immediate parent and all child nodes for the handle element in order to determine wheter or not it was clicked.
Parameters:
node <object> the html element to inspect
Returns: void

init

private static void init ( )
Called the first time an element is registered.
Returns: void

isDragDrop

static boolean isDragDrop ( id )
Utility function to determine if a given element has been registered as a drag drop item.
Parameters:
id <String> the element id to check
Returns: boolean
true if this element is a DragDrop item, false otherwise

isHandle

static boolean isHandle ( id )
Utility function to determine if a given element has been registered as a drag drop handle for the given Drag Drop object.
Parameters:
id <String> the element id to check
Returns: boolean
true if this element is a DragDrop handle, false otherwise

isLegalTarget

static boolean isLegalTarget ( the )
Returns true if the specified dd target is a legal target for the specifice drag obj
Parameters:
the <DragDrop> drag obj
the <DragDrop> target
Returns: boolean
true if the target is a legal target for the dd obj

isLocked

static boolean isLocked ( )
Is drag and drop locked?
Returns: boolean
True if drag and drop is locked, false otherwise.

isOverTarget

private static boolean isOverTarget ( pt , oTarget , intersect , pre-cached )
Checks the cursor location to see if it over the target
Parameters:
pt <YAHOO.util.Point> The point to evaluate
oTarget <DragDrop> the DragDrop object we are inspecting
intersect <boolean> true if we are in intersect mode
pre-cached <YAHOO.util.Region> location of the dragged element
Returns: boolean
true if the mouse is over the target

isTypeOfDD

static boolean isTypeOfDD ( the )
My goal is to be able to transparently determine if an object is typeof DragDrop, and the exact subclass of DragDrop. typeof returns "object", oDD.constructor.toString() always returns "DragDrop" and not the name of the subclass. So for now it just evaluates a well-known variable in DragDrop.
Parameters:
the <Object> object to evaluate
Returns: boolean
true if typeof oDD = DragDrop

lock

static void lock ( )
Lock all drag and drop functionality
Returns: void

moveToEl

static void moveToEl ( moveEl , targetEl )
Sets the x/y position of an element to the location of the target element.
Parameters:
moveEl <HTMLElement> The element to move
targetEl <HTMLElement> The position reference element
Returns: void

numericSort

static void numericSort ( )
Numeric array sort function
Returns: void

refreshCache

static void refreshCache ( groups )
Refreshes the cache of the top-left and bottom-right points of the drag and drop objects in the specified group(s). This is in the format that is stored in the drag and drop instance, so typical usage is: YAHOO.util.DragDropMgr.refreshCache(ddinstance.groups); Alternatively: YAHOO.util.DragDropMgr.refreshCache({group1:true, group2:true});
Parameters:
groups <Object> an associative array of groups to refresh
Returns: void

regDragDrop

static void regDragDrop ( oDD , sGroup )
Each DragDrop instance must be registered with the DragDropMgr. This is executed in DragDrop.init()
Parameters:
oDD <DragDrop> the DragDrop object to register
sGroup <String> the name of the group this element belongs to
Returns: void

regHandle

static void regHandle ( sDDId , sHandleId )
Each DragDrop handle element must be registered. This is done automatically when executing DragDrop.setHandleElId()
Parameters:
sDDId <String> the DragDrop id this element is a handle for
sHandleId <String> the id of the element that is the drag handle
Returns: void

removeDDFromGroup

private static void removeDDFromGroup ( )
Removes the supplied dd instance from the supplied group. Executed by DragDrop.removeFromGroup, so don't call this function directly.
Returns: void

startDrag

static void startDrag ( x , y )
Fired when either the drag pixel threshol or the mousedown hold time threshold has been met.
Parameters:
x <int> the X position of the original mousedown
y <int> the Y position of the original mousedown
Returns: void

stopDrag

static void stopDrag ( e , silent )
Ends the current drag, cleans up the state, and fires the endDrag and mouseUp events. Called internally when a mouseup is detected during the drag. Can be fired manually during the drag by passing either another event (such as the mousemove event received in onDrag) or a fake event with pageX and pageY defined (so that endDrag and onMouseUp have usable position data.). Alternatively, pass true for the silent parameter so that the endDrag and onMouseUp events are skipped (so no event data is needed.)
Parameters:
e <Event> the mouseup event, another event (or a fake event) with pageX and pageY defined, or nothing if the silent parameter is true
silent <boolean> skips the enddrag and mouseup events if true
Returns: void

stopEvent

static void stopEvent ( e )
Utility to stop event propagation and event default, if these features are turned on.
Parameters:
e <Event> the event as returned by this.getEvent()
Returns: void

swapNode

static void swapNode ( n1 , n2 )
Swap two nodes. In IE, we use the native method, for others we emulate the IE behavior
Parameters:
n1 <object> the first node to swap
n2 <object> the other node to swap
Returns: void

unlock

static void unlock ( )
Unlock all drag and drop functionality
Returns: void

unregAll

private static void unregAll ( )
Cleans up the drag and drop events and objects.
Returns: void

verifyEl

static boolean verifyEl ( el )
This checks to make sure an element exists and is in the DOM. The main purpose is to handle cases where innerHTML is used to remove drag and drop objects from the DOM. IE provides an 'unspecified error' when trying to access the offsetParent of such an element
Parameters:
el <HTMLElement> the element to check
Returns: boolean
true if the element looks usable


Copyright © 2007 Yahoo! Inc. All rights reserved.