70N/A<p>This example shows how to use the Drop Target events to code your application.</p>
70N/A<div class="example">
70N/A {{>drop-code-source}}
70N/A<h3>Setting up the HTML</h3>
70N/A<p>First we need to create the HTML for the example.</p>
70N/A{{>drop-code-source-html}}
70N/A<p>Now we give the HTML some CSS to make them visible.</p>
70N/A{{>drop-code-source-css}}
70N/A<h3>Setting up the YUI Instance</h3>
70N/A<p>Now we need to create our YUI instance and tell it to load the <code>dd-drop</code> and <code>dd-constrain</code> modules.</p>
70N/AYUI().use('dd-drop', 'dd-constrain');
70N/A<h3>Making the Nodes draggable</h3>
70N/A<p>Now that we have a YUI instance with the <code>dd-drop</code> module, we need to instantiate the <code>Drag</code> instance on each Drag Node.</p>
310N/A<p>In this example we are using the data config option of the drag to associate data with this Drag instance.</p>
70N/A<p>So we have set up an object literal containing information about our drag items.</p>
213N/A 'drag1': { color: 'white', size: 'x-small', price: '$5.00' },
304N/A 'drag2': { color: 'blue', size: 'small', price: '$6.00' },
231N/A 'drag3': { color: 'green', size: 'medium', price: '$7.00' },
98N/A 'drag4': { color: 'red', size: 'large', price: '$10.00' },
310N/A 'drag5': { color: 'purple', size: 'x-large', price: '$15.00' }
210N/A<p>Now we walk through the nodes and create a drag instance from each of them.</p>
294N/AYUI().use('dd-drop', 'dd-constrain', function(Y) {
98N/A //Data to attach to each drag object
289N/A 'drag1': { color: 'white', size: 'x-small', price: '$5.00' },
290N/A 'drag2': { color: 'blue', size: 'small', price: '$6.00' },
286N/A 'drag3': { color: 'green', size: 'medium', price: '$7.00' },
90N/A 'drag4': { color: 'red', size: 'large', price: '$10.00' },
295N/A 'drag5': { color: 'purple', size: 'x-large', price: '$15.00' }
299N/A //Get all the divs with the class drag
277N/A //Walk through each one
309N/A //scope a local var for the data
70N/A //Using
Y.mix to break this data from the data above
70N/A //Create the new Drag Instance
98N/A //Set the dragMode to intersect
156N/A //Attach the data here.
70N/A //Keep it inside the work area
70N/A constrain2node: '#play'
70N/A //Prevent the default end event (this moves the node back to its start position)
70N/A<h3>Setting up the Drop Target</h3>
70N/A<p>Here we set up the Drop Target and assign a listener to it.</p>
70N/A//Listen for a drop:hit on this target
//Now we get the drag instance that triggered the drop hit
//Do something with the data
var out = ['id: ' +
drag.get('node').get('id')];
var str = '<p><strong>Dropped</strong>: ' +
out.join(', ') + '</p>';
<h3>Full Example Source</h3>