5
<title>Example: Using Drag Plugins with Delegate</title>
6
<link rel="stylesheet" href="http://yui.yahooapis.com/3.4.0pr3/build/cssgrids/grids-min.css">
7
<link rel="stylesheet" href="../assets/css/main.css">
8
<link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css">
9
<script src="../../build/yui/yui-min.js"></script>
14
<h1>Example: Using Drag Plugins with Delegate</h1>
17
<a href="#toc" class="jump">Jump to Table of Contents</a>
21
<div id="main" class="yui3-u">
22
<div class="content"><div class="intro">
23
<p>This example is the same as the "Drag Delegation with Drop Target" example except we add some plugins.</p>
31
border: 1px solid black;
32
background-color: #8DD5E7;
35
list-style-type: none;
41
border: 1px solid black;
44
border: 1px solid black;
45
background-color: #eee;
55
#drop.yui3-dd-drop-over {
56
background-color: #ccc;
82
<div id="drop">Drop on me</div>
88
YUI().use('dd-delegate', 'dd-drop-plugin', 'dd-constrain', 'dd-proxy', function(Y) {
89
var del = new Y.DD.Delegate({
94
del.on('drag:start', function(e) {
95
e.target.get('node').setStyle('opacity', '.5');
97
del.on('drag:end', function(e) {
98
e.target.get('node').setStyle('opacity', '1');
101
del.dd.plug(Y.Plugin.DDConstrained, {
102
constrain2node: '#play'
105
del.dd.plug(Y.Plugin.DDProxy, {
110
var drop = Y.one('#drop').plug(Y.Plugin.Drop);
111
drop.drop.on('drop:hit', function(e) {
112
drop.set('innerHTML', 'You dropped: <strong>' + e.drag.get('node').get('innerHTML') + '</strong>');
124
<h3 id="adding-plugins-to-a-delegate-instance">Adding Plugins to a Delegate instance</h3>
125
<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>.
126
This allows you to use DD plugins on a Delegate instance, as well as provides the ability to write plugins for Delegate itself.
129
<h3 id="constrain-plugin">Constrain Plugin</h3>
130
<p>Here is how you would add the constrain plugin to a <code>DD.Delegate</code> instance.</p>
132
<pre class="code prettyprint">YUI().use('dd-delegate', 'dd-constrain', function(Y) {
133
var del = new Y.DD.Delegate({
134
container: '#demo',
135
nodes: 'li'
138
del.dd.plug(Y.Plugin.DDConstrained, {
139
constrain2node: '#play'
144
<h3 id="ddproxy-plugin">DDProxy Plugin</h3>
145
<p>Here is how you would add the dd-proxy plugin to a <code>DD.Delegate</code> instance.</p>
147
<pre class="code prettyprint">YUI().use('dd-delegate', 'dd-proxy', function(Y) {
148
var del = new Y.DD.Delegate({
149
container: '#demo',
150
nodes: 'li'
153
del.dd.plug(Y.Plugin.DDProxy, {
161
<h3 id="full-example-source">Full Example Source</h3>
163
<h4 id="html">HTML</h4>
164
<pre class="code prettyprint"><div id="play">
166
<div id="demo">
168
<li>Item #1</li>
169
<li>Item #2</li>
170
<li>Item #3</li>
171
<li>Item #4</li>
172
<li>Item #5</li>
173
<li>Item #6</li>
174
<li>Item #7</li>
175
<li>Item #8</li>
176
<li>Item #9</li>
177
<li>Item #10</li>
181
<div id="drop">Drop on me</div>
182
</div></pre>
184
<h4 id="css">CSS</h4>
185
<pre class="code prettyprint">#demo {
188
border: 1px solid black;
189
background-color: #8DD5E7;
192
list-style-type: none;
198
border: 1px solid black;
201
border: 1px solid black;
202
background-color: #eee;
212
#drop.yui3-dd-drop-over {
213
background-color: #ccc;
219
<h4 id="javascript">Javascript</h4>
220
<pre class="code prettyprint">YUI().use('dd-delegate', 'dd-drop-plugin', 'dd-constrain', 'dd-proxy', function(Y) {
221
var del = new Y.DD.Delegate({
222
container: '#demo',
223
nodes: 'li'
226
del.on('drag:start', function(e) {
227
e.target.get('node').setStyle('opacity', '.5');
229
del.on('drag:end', function(e) {
230
e.target.get('node').setStyle('opacity', '1');
233
del.dd.plug(Y.Plugin.DDConstrained, {
234
constrain2node: '#play'
237
del.dd.plug(Y.Plugin.DDProxy, {
242
var drop = Y.one('#drop').plug(Y.Plugin.Drop);
243
drop.drop.on('drop:hit', function(e) {
244
drop.set('innerHTML', 'You dropped: <strong>' + e.drag.get('node').get('innerHTML') + '</strong>');
253
<div id="sidebar" class="yui3-u">
255
<div id="toc" class="sidebox">
257
<h2 class="no-toc">Table of Contents</h2>
263
<a href="#adding-plugins-to-a-delegate-instance">Adding Plugins to a Delegate instance</a>
266
<a href="#constrain-plugin">Constrain Plugin</a>
269
<a href="#ddproxy-plugin">DDProxy Plugin</a>
272
<a href="#full-example-source">Full Example Source</a>
275
<a href="#html">HTML</a>
278
<a href="#css">CSS</a>
281
<a href="#javascript">Javascript</a>
291
<div class="sidebox">
293
<h2 class="no-toc">Examples</h2>
297
<ul class="examples">
300
<li data-description="A simple drag interaction that doesn't require a drop interaction.">
301
<a href="simple-drag.html">Simple Drag</a>
306
<li data-description="How to apply the Drag Plugin to a node.">
307
<a href="drag-plugin.html">Drag - Node plugin</a>
312
<li data-description="A simple proxy drag interaction that doesn't require a drop interaction.">
313
<a href="proxy-drag.html">Drag - Proxy</a>
318
<li data-description="How to constrain a draggable Node to another Node's region.">
319
<a href="constrained-drag.html">Drag - Constrained to a Region</a>
324
<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.">
325
<a href="groups-drag.html">Drag - Interaction Groups</a>
330
<li data-description="The use of the drag shim when dragging nodes over other troublesome nodes.">
331
<a href="shim-drag.html">Using the Drag Shim</a>
336
<li data-description="How to use the Drop Target events to code your application.">
337
<a href="drop-code.html">Using Drop Based Coding</a>
342
<li data-description="How you can use the DD Scroll plugin to scroll the browser window as you drag.">
343
<a href="winscroll.html">Window Scrolling</a>
348
<li data-description="How to use DD.Delegate to create a scalable solution which supports multiple draggable items.">
349
<a href="delegate.html">Drag Delegation</a>
354
<li data-description="Using DD.Delegate to support dragging multiple items and dropping them onto a Drop Target.">
355
<a href="delegate-drop.html">Drag Delegation with a Drop Target</a>
360
<li data-description="How to use Drag plugins with a DD Delegate based solution.">
361
<a href="delegate-plugins.html">Using Drag Plugins with Delegate</a>
366
<li data-description="This example shows how to make a sortable list using Custom Event Bubbling.">
367
<a href="list-drag.html">List Reorder w/Bubbling</a>
372
<li data-description="This example shows how to make a sortable list using Custom Event Bubbling and Node Scrolling.">
373
<a href="scroll-list.html">List Reorder w/Scrolling</a>
378
<li data-description="How to make an animated node a Drop target.">
379
<a href="anim-drop.html">Animated Drop Targets</a>
384
<li data-description="Example Photo Browser application.">
385
<a href="photo-browser.html">Photo Browser</a>
390
<li data-description="Portal style example using Drag & Drop Event Bubbling and Animation.">
391
<a href="portal-drag.html">Portal Style Example</a>
405
<div class="sidebox">
407
<h2 class="no-toc">Examples That Use This Component</h2>
411
<ul class="examples">
446
<li data-description="Working with multiple YUI instances.">
447
<a href="../yui/yui-multi.html">Multiple Instances</a>
452
<li data-description="Use StyleSheet to adjust the CSS rules applying a page theme from user input">
453
<a href="../stylesheet/stylesheet-theme.html">Adjusting a Page Theme on the Fly</a>
465
<script src="../assets/vendor/prettify/prettify-min.js"></script>
466
<script>prettyPrint();</script>