index.mustache revision 046ea4d1ee0f22d956cd360e1e0c0b275aa4bbd0
5432N/A<div class="intro">
5432N/A <p> The Drag and Drop Utility allows you to create a draggable interface efficiently, buffering you from browser-level abnormalities and enabling you to focus on the interesting logic surrounding your particular implementation. This component enables you to create a variety of standard draggable objects with just a few lines of code and then, using its extensive API, add your own specific implementation logic. </p>
5432N/A <p>For more information about drag and drop as a design pattern, see the <a href="http://developer.yahoo.com/ypatterns/parent_dragdrop.php">Yahoo! Design Pattern Library</a>.</p>
5432N/A</div>
5432N/A
5432N/A{{>getting-started}}
5432N/A
5432N/A<h2>Using Drag and Drop</h2>
5432N/A
5432N/A<h3>Basic Drag</h3>
5432N/A<p>You create a simple Drag instance by including the `dd-drag` module and using the following code:</p>
5432N/A
5432N/A```
5432N/AYUI().use('dd-drag', function(Y) {
5432N/A var dd = new Y.DD.Drag({
5432N/A node: '#drag'
5432N/A });
5432N/A});
5432N/A```
5432N/A
5432N/A<h3>Basic Proxy Drag</h3>
5432N/A<p>You create a simple Proxy Drag instance by including the `dd-drag` and `dd-proxy` modules and using the following code:</p>
5432N/A
5432N/A```
5432N/AYUI().use('dd-drag', 'dd-proxy', function(Y) {
5432N/A var dd = new Y.DD.Drag({
5432N/A node: '#drag'
5432N/A }).plug(Y.Plugin.DDProxy); //This config option makes the node a Proxy Drag
5432N/A});
5432N/A```
5432N/A
5432N/A<h3>Basic Drop Target</h3>
5432N/A<p>You create a simple Drop Target instance by including the `dd-drop` module and using the following code:</p>
5432N/A
5432N/A```
5432N/AYUI().use('dd-drop', function(Y) {
5432N/A var drop = new Y.DD.Drop({
5432N/A node: '#drop'
5432N/A });
5432N/A});
5432N/A```
5432N/A
5432N/A<h2 id="events">Events</h2>
5432N/A
5432N/A<p>Drag and Drop for YUI 3 has been been packed with useful events to allow the implementer to control the end user experience.</p>
5432N/A<p><em>* All Drag and Drop events bubble, by default, to the Drag and Drop Manager.</em></p>
5432N/A
5432N/A<table>
5432N/A <thead>
5432N/A <tr>
5432N/A <th>Event</th>
5432N/A <th>Target</th>
5432N/A <th>Preventable</th>
5432N/A <th>Stoppable</th>
5432N/A <th>Description</th>
5432N/A </tr>
5432N/A </thead>
5432N/A <tbody>
5432N/A <tr>
5432N/A <td>`drag:mouseDown`</td>
5432N/A <td>Drag</td>
5432N/A <td>yes</td>
5432N/A <td>yes</td>
5432N/A <td>Handles the mousedown/touchstart DOM event, checks to see if you have a valid handle then starts the drag timers.</td>
5432N/A </tr>
5432N/A <tr>
5432N/A <td>`drag:afterMouseDown`</td>
5432N/A <td>Drag</td>
5432N/A <td>no</td>
5432N/A <td>no</td>
5432N/A <td>Fires after the mousedown/touchstart event has been cleared.</td>
5432N/A </tr>
5432N/A <tr>
5432N/A <td>`drag:mouseup`</td>
5432N/A <td>Drag</td>
5432N/A <td>yes</td>
5432N/A <td>yes</td>
5432N/A <td>Fires the mouseup event.</td>
5432N/A </tr>
5432N/A <tr>
5432N/A <td>`drag:align`</td>
5432N/A <td>Drag</td>
5432N/A <td>yes</td>
5432N/A <td>yes</td>
5432N/A <td>Fires when this node is aligned.</td>
5432N/A </tr>
5432N/A <tr>
5432N/A <td>`drag:removeHandle`</td>
5432N/A <td>Drag</td>
5432N/A <td>no</td>
5432N/A <td>no</td>
5432N/A <td>Fires after a handle is removed.</td>
5432N/A </tr>
5432N/A <tr>
5432N/A <td>`drag:addHandle`</td>
5432N/A <td>Drag</td>
5432N/A <td>no</td>
5432N/A <td>no</td>
5432N/A <td>Fires after a handle is added.</td>
5432N/A </tr>
5432N/A <tr>
5432N/A <td>`drag:removeInvalid`</td>
5432N/A <td>Drag</td>
5432N/A <td>no</td>
5432N/A <td>no</td>
5432N/A <td>Fires after an invalid selector is removed.</td>
5432N/A </tr>
5432N/A <tr>
5432N/A <td>`drag:addInvalid`</td>
5432N/A <td>Drag</td>
5432N/A <td>no</td>
5432N/A <td>no</td>
5432N/A <td>Fires after an invalid selector is added.</td>
5432N/A </tr>
5432N/A <tr>
5432N/A <td>`drag:start`</td>
5432N/A <td>Drag</td>
5432N/A <td>no</td>
5432N/A <td>no</td>
5432N/A <td>Fires at the start of a drag operation.</td>
5432N/A </tr>
5432N/A <tr>
5432N/A <td>`drag:end`</td>
5432N/A <td>Drag</td>
5432N/A <td>yes</td>
5432N/A <td>yes</td>
5432N/A <td>Fires at the end of a drag operation.</td>
5432N/A </tr>
5432N/A <tr>
5432N/A <td>`drag:drag`</td>
5432N/A <td>Drag</td>
5432N/A <td>yes</td>
5432N/A <td>yes</td>
5432N/A <td>Fires every mousemove/touchmove during a drag operation.</td>
5432N/A </tr>
5432N/A <tr>
5432N/A <td>`drag:over`</td>
5432N/A <td>Drag</td>
5432N/A <td>no</td>
5432N/A <td>no</td>
5432N/A <td>Fires when this node is over a Drop Target. (Fired from dd-drop)</td>
5432N/A </tr>
5432N/A <tr>
5432N/A <td>`drag:enter`</td>
5432N/A <td>Drag</td>
5432N/A <td>no</td>
5432N/A <td>no</td>
5432N/A <td>Fires when this node enters a Drop Target. (Fired from dd-drop)</td>
5432N/A </tr>
5432N/A <tr>
5432N/A <td>`drag:exit`</td>
5432N/A <td>Drag</td>
5432N/A <td>no</td>
5432N/A <td>no</td>
5432N/A <td>Fires when this node exits a Drop Target. (Fired from dd-drop)</td>
5432N/A </tr>
5432N/A <tr>
5432N/A <td>`drag:drophit`</td>
5432N/A <td>Drag</td>
5432N/A <td>no</td>
5432N/A <td>no</td>
5432N/A <td>Fires when this node is dropped on a valid Drop Target. (Fired from dd-ddm-drop)</td>
5432N/A </tr>
5432N/A <tr>
5432N/A <td>`drag:dropmiss`</td>
5432N/A <td>Drag</td>
5432N/A <td>no</td>
5432N/A <td>no</td>
5432N/A <td>Fires when this node is dropped on an invalid Drop Target. (Fired from dd-ddm-drop)</td>
5432N/A </tr>
5432N/A <tr>
5432N/A <td>`drop:over`</td>
5432N/A <td>Drop</td>
5432N/A <td>no</td>
5432N/A <td>no</td>
5432N/A <td>Fires when a drag element is over this target.</td>
5432N/A </tr>
5432N/A <tr>
5432N/A <td>`drop:enter`</td>
5432N/A <td>Drop</td>
5432N/A <td>no</td>
5432N/A <td>no</td>
5432N/A <td>Fires when a drag element enters this target.</td>
5432N/A </tr>
5432N/A <tr>
5432N/A <td>`drop:exit`</td>
5432N/A <td>Drop</td>
5432N/A <td>no</td>
5432N/A <td>no</td>
5432N/A <td>Fires when a drag element exits this target.</td>
5432N/A </tr>
5432N/A <tr>
5432N/A <td>`drop:hit`</td>
5432N/A <td>Drop</td>
5432N/A <td>no</td>
5432N/A <td>no</td>
5432N/A <td>Fires when a draggable node is dropped on this Drop Target. (Fired from dd-ddm-drop)</td>
5432N/A </tr>
5432N/A </tbody>
5432N/A</table>
5432N/A
5432N/A<h3 id="bubbling">Event Bubbling</h3>
5432N/A
5432N/A<p>To allow for a truly Event driven application, all Drag and Drop related events are bubbled to the `DragDropMgr`.</p>
5432N/A<p>This allows you to listen for all Drag and Drop events from a central location, per YUI instance.</p>
5432N/A<p>This approach is also handy for situations where you are dynamically adding and removing items.</p>
5432N/A<p>So instead of doing this:</p>
5432N/A
5432N/A```
5432N/Avar doSomething = function() {
5432N/A Y.log('Do Something Here');
5432N/A};
5432N/Add1.on('drag:drag', doSomething);
5432N/Add2.on('drag:drag', doSomething);
5432N/Add3.on('drag:drag', doSomething);
5432N/Add4.on('drag:drag', doSomething);
5432N/Add5.on('drag:drag', doSomething);
5432N/Add6.on('drag:drag', doSomething);
5432N/Add7.on('drag:drag', doSomething);
5432N/Add8.on('drag:drag', doSomething);
5432N/Add9.on('drag:drag', doSomething);
5432N/A```
5432N/A
5432N/A<p>You can now do this:</p>
5432N/A
```
var doSomething = function() {
Y.log('Do Something Here');
};
Y.DD.DDM.on('drag:drag', doSomething);
```
<h2 id="delegate">Delegate Dragging</h2>
<p>Delegate dragging allows you to create a "list/group" of draggable items that are under a common "container". Using this approach, you can have hundreds of draggable items, yet only have one object created under the hood.</p>
<p>This approach is also handy for situations where you are dynamically adding and removing items from the "list" and need to make them draggable. Using `Delegate` you wouldn't have to create a new `drag` instance when adding or removing it.</p>
```
YUI().use('dd-delegate', function(Y) {
var del = new Y.DD.Delegate({
container: '#demo', //The common container
nodes: '.item' //The items to make draggable
});
});
```
<p><strong>Note:</strong> `DD.Delegate` does not auto find your drop target items, if you change the `nodes` under the hood (add or remove) you need to call `delegate.syncTargets();` to manage them.</p>
<h2 id="cssclasses">CSS Class Names</h2>
<p>The Drag and Drop Utility adds CSS class names for important moments in the drag and drop operation. Below you will find the list of these class names.</p>
<p>The Drag and Drop Utility doesn't ship with a default skin, so no style rules are attached to these class names. That is completely left up to the implementer.</p>
<p><strong>Note: </strong> As of version 3.1.0, Drag and Drop changed it's classname prefix from `yui-dd` to `yui3-dd` to mimic the global change in skinning.</p>
<table>
<thead>
<tr>
<th>Class Name</th>
<th>Target</th>
<th>State</th>
</tr>
</thead>
<tbody>
<tr>
<td nowrap="nowrap">`yui3-dd-draggable`</td>
<td>Drag</td>
<td>Given to all Drag Nodes</td>
</tr>
<tr>
<td nowrap="nowrap">`yui3-dd-locked`</td>
<td>Drag</td>
<td>Added when a Drag instance is locked</td>
</tr>
<tr>
<td nowrap="nowrap">`yui3-dd-dragging`</td>
<td>Drag</td>
<td>Added while a Drag instance is active</td>
</tr>
<tr>
<td nowrap="nowrap">`yui3-dd-proxy`</td>
<td>Proxy</td>
<td>Given to the Proxy Node</td>
</tr>
<tr>
<td nowrap="nowrap">`yui3-dd-drop`</td>
<td>Drop</td>
<td>Given to all Drop Targets</td>
</tr>
<tr>
<td nowrap="nowrap">`yui3-dd-drop-locked`</td>
<td>Drop</td>
<td>Added when a Drop instance is locked</td>
</tr>
<tr>
<td nowrap="nowrap">`yui3-dd-drop-active-valid`</td>
<td>Drop</td>
<td>Added to a Drop when it is an valid target for the current drag operation</td>
</tr>
<tr>
<td nowrap="nowrap">`yui3-dd-drop-active-invalid`</td>
<td>Drop</td>
<td>Added to a Drop when it is an invalid target for the current drag operation</td>
</tr>
<tr>
<td nowrap="nowrap">`yui3-dd-drop-over`</td>
<td>Drop</td>
<td>Added when a Drag instance is over this Drop Target</td>
</tr>
</tbody>
</table>
<h2 id="gestures">Touch/Gesture Support</h2>
<p>Native gesture support was added to DD in 3.2.0. This support is transparent and the implementor should not have to do anything to use this functionality. When `dd` is used, loader will check the device to see if it contains support for Gesture Events, if the device supports these events the `dd-gestures` module will automatically be loaded as well as it's dependencies. At this point, DD will operate as usual but it will utilize the native gesture events instead of mouse based events.</p>
<h2 id="modules">Module Descriptions</h2>
<p>Drag and Drop for YUI 3 has been broken up into several modules to allow you, as the implementer, to pick how you want it to work and what code you need on your page.</p>
<table>
<thead>
<tr>
<th>Module Name</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td nowrap="nowrap">`dd-drag`</td>
<td>Main drag class, this makes something draggable.</td>
</tr>
<tr>
<td nowrap="nowrap">`dd-proxy`</td>
<td>Adds proxy support to the main drag class.</td>
</tr>
<tr>
<td nowrap="nowrap">`dd-constrain`</td>
<td>Adds constrain support to the main drag class.</td>
</tr>
<tr>
<td nowrap="nowrap">`dd-scroll`</td>
<td>Adds node and window based scroll support.</td>
</tr>
<tr>
<td nowrap="nowrap">`dd-delegate`</td>
<td>Provides the ability to drag multiple nodes under a container element using only one Y.DD.Drag instance as a delegate.</td>
</tr>
<tr>
<td nowrap="nowrap">`dd-drop`</td>
<td>Drop Support, this is the support for all drop targets.</td>
</tr>
<tr>
<td nowrap="nowrap">`dd`</td>
<td>All of the Drag and Drop modules rolled up into one file.</td>
</tr>
<tr>
<th colspan="2">Other Included Modules</th>
</tr>
<tr>
<td nowrap="nowrap">`dd-ddm-base`</td>
<td>Base DragDrop Manager, required to make something draggable.</td>
</tr>
<tr>
<td nowrap="nowrap">`dd-ddm`</td>
<td>Adds shim support, only needed when you need to drag over something that steals mouse events or you are targeting.</td>
</tr>
<tr>
<td nowrap="nowrap">`dd-ddm-drop`</td>
<td>Adds Drop support, only required when you have drop targets you need to interact with.</td>
</tr>
</tbody>
</table>
<h2 id="plugins">DD Plugins</h2>
<p><strong>In 3.2.0, some modules have been removed from the rollup and were converted to DD Plugins.</strong> Below are the list of plugins that are no longer in the `dd` rollup.</p>
<table>
<thead>
<tr>
<th>Plugin</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td nowrap="nowrap">`dd-plugin`</td>
<td>Node plugin for Drag</td>
</tr>
<tr>
<td nowrap="nowrap">`dd-drop-plugin`</td>
<td>Node plugin for Drop</td>
</tr>
<tr>
<td nowrap="nowrap">`dd-gestures`</td>
<td>Node plugin for Gesture support. This module is automatically loaded by loader when `dd` is used on a device that supports gestures.</td>
</tr>
</tbody>
</table>