5
<title>Example: Using Drag Plugins with Delegate</title>
6
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Maven+Pro:400,700">
7
<link rel="stylesheet" href="../../build/cssgrids/grids-min.css">
8
<link rel="stylesheet" href="../assets/css/main.css">
9
<link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css">
10
<script src="../../build/yui/yui-min.js"></script>
15
<h1>Example: Using Drag Plugins with Delegate</h1>
18
<a href="#toc" class="jump">Jump to Table of Contents</a>
22
<div class="yui3-u-3-4">
24
<div class="content"><div class="intro">
25
<p>This example is the same as the "Drag Delegation with Drop Target" example except we add some plugins.</p>
33
border: 1px solid black;
34
background-color: #8DD5E7;
37
list-style-type: none;
45
border: 1px solid black;
50
border: 1px solid black;
51
background-color: #eee;
61
#drop.yui3-dd-drop-over {
62
background-color: #ccc;
88
<div id="drop">Drop on me</div>
94
YUI().use('dd-delegate', 'dd-drop-plugin', 'dd-constrain', 'dd-proxy', function(Y) {
95
var del = new Y.DD.Delegate({
100
del.on('drag:start', function(e) {
101
e.target.get('node').setStyle('opacity', '.5');
103
del.on('drag:end', function(e) {
104
e.target.get('node').setStyle('opacity', '1');
107
del.dd.plug(Y.Plugin.DDConstrained, {
108
constrain2node: '#play'
111
del.dd.plug(Y.Plugin.DDProxy, {
116
var drop = Y.one('#drop').plug(Y.Plugin.Drop);
117
drop.drop.on('drop:hit', function(e) {
118
drop.set('innerHTML', 'You dropped: <strong>' + e.drag.get('node').get('innerHTML') + '</strong>');
130
<h3 id="adding-plugins-to-a-delegate-instance">Adding Plugins to a Delegate instance</h3>
131
<p><code>DD.Delegate</code> provides a reference to the <code>dd</code> instance so you can plug into the underlying <code>dd</code> with <code>del.dd.plug()</code>.
132
This allows you to use DD plugins on a Delegate instance, as well as provides the ability to write plugins for Delegate itself.
135
<h3 id="constrain-plugin">Constrain Plugin</h3>
136
<p>Here is how you would add the constrain plugin to a <code>DD.Delegate</code> instance.</p>
138
<pre class="code prettyprint">YUI().use('dd-delegate', 'dd-constrain', function(Y) {
139
var del = new Y.DD.Delegate({
140
container: '#demo',
141
nodes: 'li'
144
del.dd.plug(Y.Plugin.DDConstrained, {
145
constrain2node: '#play'
150
<h3 id="ddproxy-plugin">DDProxy Plugin</h3>
151
<p>Here is how you would add the dd-proxy plugin to a <code>DD.Delegate</code> instance.</p>
153
<pre class="code prettyprint">YUI().use('dd-delegate', 'dd-proxy', function(Y) {
154
var del = new Y.DD.Delegate({
155
container: '#demo',
156
nodes: 'li'
159
del.dd.plug(Y.Plugin.DDProxy, {
167
<h3 id="full-example-source">Full Example Source</h3>
169
<h4 id="html">HTML</h4>
170
<pre class="code prettyprint"><div id="play">
172
<div id="demo">
174
<li>Item #1</li>
175
<li>Item #2</li>
176
<li>Item #3</li>
177
<li>Item #4</li>
178
<li>Item #5</li>
179
<li>Item #6</li>
180
<li>Item #7</li>
181
<li>Item #8</li>
182
<li>Item #9</li>
183
<li>Item #10</li>
187
<div id="drop">Drop on me</div>
188
</div></pre>
190
<h4 id="css">CSS</h4>
191
<pre class="code prettyprint">#demo {
194
border: 1px solid black;
195
background-color: #8DD5E7;
198
list-style-type: none;
206
border: 1px solid black;
211
border: 1px solid black;
212
background-color: #eee;
222
#drop.yui3-dd-drop-over {
223
background-color: #ccc;
229
<h4 id="javascript">Javascript</h4>
230
<pre class="code prettyprint">YUI().use('dd-delegate', 'dd-drop-plugin', 'dd-constrain', 'dd-proxy', function(Y) {
231
var del = new Y.DD.Delegate({
232
container: '#demo',
233
nodes: 'li'
236
del.on('drag:start', function(e) {
237
e.target.get('node').setStyle('opacity', '.5');
239
del.on('drag:end', function(e) {
240
e.target.get('node').setStyle('opacity', '1');
243
del.dd.plug(Y.Plugin.DDConstrained, {
244
constrain2node: '#play'
247
del.dd.plug(Y.Plugin.DDProxy, {
252
var drop = Y.one('#drop').plug(Y.Plugin.Drop);
253
drop.drop.on('drop:hit', function(e) {
254
drop.set('innerHTML', 'You dropped: <strong>' + e.drag.get('node').get('innerHTML') + '</strong>');
264
<div class="yui3-u-1-4">
265
<div class="sidebar">
267
<div id="toc" class="sidebox">
269
<h2 class="no-toc">Table of Contents</h2>
275
<a href="#adding-plugins-to-a-delegate-instance">Adding Plugins to a Delegate instance</a>
278
<a href="#constrain-plugin">Constrain Plugin</a>
281
<a href="#ddproxy-plugin">DDProxy Plugin</a>
284
<a href="#full-example-source">Full Example Source</a>
287
<a href="#html">HTML</a>
290
<a href="#css">CSS</a>
293
<a href="#javascript">Javascript</a>
303
<div class="sidebox">
305
<h2 class="no-toc">Examples</h2>
309
<ul class="examples">
312
<li data-description="A simple drag interaction that doesn't require a drop interaction.">
313
<a href="simple-drag.html">Simple Drag</a>
318
<li data-description="How to apply the Drag Plugin to a node.">
319
<a href="drag-plugin.html">Drag - Node plugin</a>
324
<li data-description="A simple proxy drag interaction that doesn't require a drop interaction.">
325
<a href="proxy-drag.html">Drag - Proxy</a>
330
<li data-description="How to constrain a draggable Node to another Node's region.">
331
<a href="constrained-drag.html">Drag - Constrained to a Region</a>
336
<li data-description="Using interaction groups, this example demonstrates how to tie into the Drag & Drop Utility's interesting moments to provide visual affordances for the current drag operation.">
337
<a href="groups-drag.html">Drag - Interaction Groups</a>
342
<li data-description="The use of the drag shim when dragging nodes over other troublesome nodes.">
343
<a href="shim-drag.html">Using the Drag Shim</a>
348
<li data-description="How to use the Drop Target events to code your application.">
349
<a href="drop-code.html">Using Drop Based Coding</a>
354
<li data-description="How you can use the DD Scroll plugin to scroll the browser window as you drag.">
355
<a href="winscroll.html">Window Scrolling</a>
360
<li data-description="How to use DD.Delegate to create a scalable solution which supports multiple draggable items.">
361
<a href="delegate.html">Drag Delegation</a>
366
<li data-description="Using DD.Delegate to support dragging multiple items and dropping them onto a Drop Target.">
367
<a href="delegate-drop.html">Drag Delegation with a Drop Target</a>
372
<li data-description="How to use Drag plugins with a DD Delegate based solution.">
373
<a href="delegate-plugins.html">Using Drag Plugins with Delegate</a>
378
<li data-description="This example shows how to make a sortable list using Custom Event Bubbling.">
379
<a href="list-drag.html">List Reorder w/Bubbling</a>
384
<li data-description="This example shows how to make a sortable list using Custom Event Bubbling and Node Scrolling.">
385
<a href="scroll-list.html">List Reorder w/Scrolling</a>
390
<li data-description="How to make an animated node a Drop target.">
391
<a href="anim-drop.html">Animated Drop Targets</a>
396
<li data-description="Example Photo Browser application.">
397
<a href="photo-browser.html">Photo Browser</a>
402
<li data-description="Portal style example using Drag & Drop Event Bubbling and Animation.">
403
<a href="portal-drag.html">Portal Style Example</a>
417
<div class="sidebox">
419
<h2 class="no-toc">Examples That Use This Component</h2>
423
<ul class="examples">
458
<li data-description="Working with multiple YUI instances.">
459
<a href="../yui/yui-multi.html">Multiple Instances</a>
464
<li data-description="Use StyleSheet to adjust the CSS rules applying a page theme from user input">
465
<a href="../stylesheet/stylesheet-theme.html">Adjusting a Page Theme on the Fly</a>
478
<script src="../assets/vendor/prettify/prettify-min.js"></script>
479
<script>prettyPrint();</script>