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