Class: SC.Drag


Extends SC.Object.

An instance of this object is created whenever a drag occurs. The instance manages the mouse/touch events and coordinating with droppable targets until the user releases the mouse button.

To initiate a drag, you should call SC.Drag.start() with the options below specified in a hash. Pass the ones you need to get the drag you want:

Defined in: drag.js

Field Summary

Class Methods

Instance Methods

Field Detail

allowedDragOperations Number

Returns the currently allowed dragOperations for the drag. This will be set just before any callbacks are invoked on a drop target. The drag source is given an opportunity to set these operations.

data Hash

Optional hash of data. Used if no dataSource was provided.

Drag sources can provide a hash of data when the drag begins instead of specifying an actual dataSource. The data is stored in this property. If you are implementing a drop target, use the dataTypes property and dataForTypes() method to access data instead of working directly with these properties.

dataSource SC.DragDataSourceProtocol

Optional object used to provide the data for the drag.

Drag source can designate a dataSource object to generate the data for a drag dynamically. The data source can and often is the drag source object itself.

Data Source objects must comply with the SC.DragDataSourceProtocol interface. If you do not want to implement this interface, you can provide the data directly with the data property.

If you are implementing a drop target, use the dataTypes property and dataForTypes() method to access data instead of working directly with these properties.

dragView SC.View

The view that was used as the source of the ghostView.

The drag view is not moved from its original location during a drag. Instead, the DOM content of the view is cloned and managed by the ghostView. If you want to visually indicate that the view is being moved, you should set ghost to YES. If dragView is not provided the source is used instead.

ghost Boolean

If YES, the dragView is automatically hidden while dragging around the ghost.

ghostActsLikeCursor Boolean

If YES, then the ghostView will acts like a cursor and attach directly to the mouse/touch location.

ghostOffset Point

The origin to slide back to in the coordinate of the dragView's containerView.

ghostView SC.View

The view actually dragged around the screen. This is created automatically from the dragView.

location Point

The current location of the mouse pointer in window coordinates. This is updated as long as the mouse button is pressed or touch is active. Drop targets are encouraged to update this property in their dragUpdated() method implementations.

The ghostView will be positioned at this location.

slideBack Boolean

If YES, then the ghostView will slide back to its original location if drag is cancelled.

source SC.DragSource
The source object used to coordinate this drag.
sourceIsDraggable Boolean

If NO, the source will not be copied, clone, no ghost view will get created, and it won't be moved.

Class Method Detail

addDropTarget(target)

Register the view object as a drop target.

This method is called automatically whenever a view is created with the isDropTarget property set to YES. You generally will not need to call it yourself.

Parameters:
target SC.View
a view implementing the SC.DropTargetProtocol protocol
addScrollableView(target)

Register the view object as a scrollable view. These views will auto-scroll during a drag.

Parameters:
target SC.View
The view that should be auto-scrolled
inspectOperation(op)
Convenience method to turn an operation mask into a descriptive string.
Defined in: drag.js.
Parameters:
op
removeDropTarget(target)

Unregister the view object as a drop target.

This method is called automatically whenever a view is removed from the hierarchy. You generally will not need to call it yourself.

Parameters:
target SC.View
A previously registered drop target
removeScrollableView(target)

Remove the view object as a scrollable view. These views will auto-scroll during a drag.

Parameters:
target SC.View
A previously registered scrollable view
start(ops)

This is the method you use to initiate a new drag. See class documentation for more info on the options taken by this method.

Parameters:
ops

Instance Method Detail

dataForType(dataType)

Retrieve the data for the specified dataType from the drag source.

Drop targets can use this method during their performDragOperation() method to retrieve the actual data provided by the drag data source. This data may be generated dynamically depending on the data source.

Parameters:
dataType Object
data type you want to retrieve. Should be one of the values returned in the dataTypes property
Returns:
Object
The generated data.
dataTypes()

Data types supported by this drag operation.

Returns an array of data types supported by the drag source. This may be generated dynamically depending on the data source.

If you are implementing a drag source, you will need to provide these data types so that drop targets can detect if they can accept your drag data.

If you are implementing a drop target, you should inspect this property on your dragEntered() and prepareForDragOperation() methods to determine if you can handle any of the data types offered up by the drag source.

hasDataType(dataType)
Checks for a named data type in the drag.
Parameters:
dataType String
the data type
Returns:
Boolean
YES if data type is present in dataTypes array.
hideGhostView()
Hide the ghostView.
touchesDragged(evt)
Parameters:
evt
unhideGhostView()
Unhide the ghostView.
Documentation generated by JsDoc Toolkit 2.4.0 on Wed Apr 08 2015 10:02:20 GMT-0600 (CST)