Mixin
O.DropTarget
The DropTarget mixin should be applied to views you wish to make drop targets.
"use strict";
( function ( NS ) {
NS.DropTarget = {
Property
O.DropTarget#isDropTarget
- Boolean
Identifies the view as a drop target.
isDropTarget: true,
Property
O.DropTarget#hasDragOver
- Boolean
True if the view is a drag is currently over the view.
hasDragOver: false,
dropEffect: NS.DragEffect.MOVE,
Property
O.DropTarget#dropAcceptedDataTypes
- Object
An object mapping data types the drop target can handle to a truthy value.
dropAcceptedDataTypes: {},
Method
O.DropTarget#willAcceptDrag( drag )
When a drag moves over the drop target, this method will be called to determine whether the target is willing to accept the drag. If it returns true, it will become the active drop target. If it returns false, it will be ignored, and any parent views which are drop targets will be considered instead.
Unless overridden, this method simply checks whether any of the data types available in the drag are included in its dropAcceptedDataTypes property.
Parameters
drag | O.Drag The drag instance. |
---|
Returns
Boolean Can the drag be dropped here?
willAcceptDrag: function ( drag ) {
var acceptedTypes = this.get( 'dropAcceptedDataTypes' ),
availableTypes = drag.get( 'dataTypes' ),
l = availableTypes.length;
while ( l-- ) {
if ( acceptedTypes[ availableTypes[l] ] ) {
return true;
}
}
return false;
},
Method
O.DropTarget#dropEntered( drag )
Called when a drag instance enters the view. If this method is called, the dropExited method is guaranteed to be called later.
Sets the drop effect on the drag instance and updates the hasDragOver property.
Parameters
drag | O.Drag The drag instance. |
---|
dropEntered: function ( drag ) {
drag.set( 'dropEffect', this.get( 'dropEffect' ) );
this.set( 'hasDragOver', true );
},
Method
O.DropTarget#dropMoved( drag )
Called when a drag instance that has entered the view moves position (without exiting the view).
Parameters
drag | O.Drag The drag instance. |
---|
dropMoved: function (/* drag */) {},
Method
O.DropTarget#dropExited( drag )
Called when a drag instance exits the view.
Resets the drop effect on the drag instance and updates the hasDragOver property.
Parameters
drag | O.Drag The drag instance. |
---|
dropExited: function ( drag ) {
drag.set( 'dropEffect', NS.DragEffect.DEFAULT );
this.set( 'hasDragOver', false );
},
Method
O.DropTarget#drop( drag )
Called when a drag instance is dropped on the view.
Parameters
drag | O.Drag The drag instance. |
---|
drop: function (/* drag */) {}
};
}( O ) );