|
525
|
1 |
<!DOCTYPE html> |
|
|
2 |
<html lang="en"> |
|
|
3 |
<head> |
|
|
4 |
<meta charset="utf-8"> |
|
|
5 |
<title>Example: Drag Delegation</title> |
|
|
6 |
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=PT+Sans:400,700,400italic,700italic"> |
|
|
7 |
<link rel="stylesheet" href="../../build/cssgrids/cssgrids-min.css"> |
|
|
8 |
<link rel="stylesheet" href="../assets/css/main.css"> |
|
|
9 |
<link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css"> |
|
|
10 |
<link rel="shortcut icon" type="image/png" href="../assets/favicon.png"> |
|
|
11 |
<script src="../../build/yui/yui-min.js"></script> |
|
|
12 |
|
|
|
13 |
</head> |
|
|
14 |
<body> |
|
|
15 |
<!-- |
|
|
16 |
<a href="https://github.com/yui/yui3"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png" alt="Fork me on GitHub"></a> |
|
|
17 |
--> |
|
|
18 |
<div id="doc"> |
|
|
19 |
<div id="hd"> |
|
|
20 |
<h1><img src="http://yuilibrary.com/img/yui-logo.png"></h1> |
|
|
21 |
</div> |
|
|
22 |
|
|
|
23 |
<a href="#toc" class="jump">Jump to Table of Contents</a> |
|
|
24 |
|
|
|
25 |
|
|
|
26 |
<h1>Example: Drag Delegation</h1> |
|
|
27 |
<div class="yui3-g"> |
|
|
28 |
<div class="yui3-u-3-4"> |
|
|
29 |
<div id="main"> |
|
|
30 |
<div class="content"><div class="intro"> |
|
|
31 |
<p>This example shows how to create multiple draggable items efficiently.</p> |
|
|
32 |
</div> |
|
|
33 |
|
|
|
34 |
<div class="example"> |
|
|
35 |
<style> |
|
|
36 |
#demo { |
|
|
37 |
width: 200px; |
|
|
38 |
} |
|
|
39 |
#demo ul li { |
|
|
40 |
border: 1px solid black; |
|
|
41 |
background-color: #8DD5E7; |
|
|
42 |
cursor: move; |
|
|
43 |
margin: 3px; |
|
|
44 |
list-style-type: none; |
|
|
45 |
zoom: 1; |
|
|
46 |
} |
|
|
47 |
</style> |
|
|
48 |
|
|
|
49 |
<div id="demo"> |
|
|
50 |
<ul> |
|
|
51 |
<li>Item #1</li> |
|
|
52 |
<li>Item #2</li> |
|
|
53 |
<li>Item #3</li> |
|
|
54 |
<li>Item #4</li> |
|
|
55 |
<li>Item #5</li> |
|
|
56 |
<li>Item #6</li> |
|
|
57 |
<li>Item #7</li> |
|
|
58 |
<li>Item #8</li> |
|
|
59 |
<li>Item #9</li> |
|
|
60 |
<li>Item #10</li> |
|
|
61 |
</ul> |
|
|
62 |
</div> |
|
|
63 |
|
|
|
64 |
<button type="button" id="make">Add More</button> |
|
|
65 |
<script> |
|
|
66 |
|
|
|
67 |
YUI().use('dd-delegate', function(Y) { |
|
|
68 |
var del = new Y.DD.Delegate({ |
|
|
69 |
container: '#demo', |
|
|
70 |
nodes: 'li' |
|
|
71 |
}); |
|
|
72 |
|
|
|
73 |
Y.one('#make').on('click', function(e) { |
|
|
74 |
var demo = Y.one('#demo ul'); |
|
|
75 |
for (var i = 1; i < 11; i++) { |
|
|
76 |
demo.append('<li>New item #' + i + '</li>'); |
|
|
77 |
} |
|
|
78 |
}); |
|
|
79 |
}); |
|
|
80 |
</script> |
|
|
81 |
|
|
|
82 |
|
|
|
83 |
</div> |
|
|
84 |
|
|
|
85 |
<h3 id="setting-up-the-delegate-container-and-items">Setting up the Delegate container and items</h3> |
|
|
86 |
<p>First we need to create an HTML Node to act as the delegate container and give it some nodes to make draggable.</p> |
|
|
87 |
|
|
|
88 |
<pre class="code prettyprint"><div id="demo"> |
|
|
89 |
<ul> |
|
|
90 |
<li>Item #1</li> |
|
|
91 |
<li>Item #2</li> |
|
|
92 |
<li>Item #3</li> |
|
|
93 |
<li>Item #4</li> |
|
|
94 |
<li>Item #5</li> |
|
|
95 |
<li>Item #6</li> |
|
|
96 |
<li>Item #7</li> |
|
|
97 |
<li>Item #8</li> |
|
|
98 |
<li>Item #9</li> |
|
|
99 |
<li>Item #10</li> |
|
|
100 |
</ul> |
|
|
101 |
</div></pre> |
|
|
102 |
|
|
|
103 |
|
|
|
104 |
<p>Now we give them some CSS to make them visible.</p> |
|
|
105 |
|
|
|
106 |
<pre class="code prettyprint">#demo { |
|
|
107 |
width: 200px; |
|
|
108 |
} |
|
|
109 |
#demo ul li { |
|
|
110 |
border: 1px solid black; |
|
|
111 |
background-color: #8DD5E7; |
|
|
112 |
cursor: move; |
|
|
113 |
margin: 3px; |
|
|
114 |
list-style-type: none; |
|
|
115 |
}</pre> |
|
|
116 |
|
|
|
117 |
|
|
|
118 |
<h3 id="setting-up-the-yui-instance">Setting up the YUI Instance</h3> |
|
|
119 |
<p>Now we need to create our YUI instance and tell it to load the <code>dd-delegate</code> module.</p> |
|
|
120 |
|
|
|
121 |
<pre class="code prettyprint">YUI().use('dd-delegate');</pre> |
|
|
122 |
|
|
|
123 |
|
|
|
124 |
|
|
|
125 |
<h3 id="making-the-nodes-draggable">Making the Nodes draggable</h3> |
|
|
126 |
<p>Now that we have a YUI instance with the <code>dd-delegate</code> module, we need to instantiate the <code>Delegate</code> instance on this container and nodes.</p> |
|
|
127 |
|
|
|
128 |
<pre class="code prettyprint">YUI().use('dd-delegate', function(Y) { |
|
|
129 |
var del = new Y.DD.Delegate({ |
|
|
130 |
container: '#demo', |
|
|
131 |
nodes: 'li' |
|
|
132 |
}); |
|
|
133 |
});</pre> |
|
|
134 |
|
|
|
135 |
|
|
|
136 |
<h3 id="adding-items-to-the-list-without-creating-new-instances">Adding items to the list without creating new instances.</h3> |
|
|
137 |
<p>One of the benefits of using <code>DD.Delegate</code> is adding new items to the list of draggables without having to create new instances for each new item.</p> |
|
|
138 |
<p>Here we are simply adding new <code>LI</code>'s to the list. Notice that we are doing nothing with the <code>del</code> object. The items are automatically draggable since they match the <code>nodes</code> selector given to the <code>DD.Delegate</code> instance.</p> |
|
|
139 |
|
|
|
140 |
<pre class="code prettyprint">Y.one('#make').on('click', function(e) { |
|
|
141 |
var demo = Y.one('#demo ul'); |
|
|
142 |
for (var i = 1; i < 11; i++) { |
|
|
143 |
demo.append('<li>New item #' + i + '</li>'); |
|
|
144 |
} |
|
|
145 |
});</pre> |
|
|
146 |
|
|
|
147 |
</div> |
|
|
148 |
</div> |
|
|
149 |
</div> |
|
|
150 |
|
|
|
151 |
<div class="yui3-u-1-4"> |
|
|
152 |
<div class="sidebar"> |
|
|
153 |
|
|
|
154 |
<div id="toc" class="sidebox"> |
|
|
155 |
<div class="hd"> |
|
|
156 |
<h2 class="no-toc">Table of Contents</h2> |
|
|
157 |
</div> |
|
|
158 |
|
|
|
159 |
<div class="bd"> |
|
|
160 |
<ul class="toc"> |
|
|
161 |
<li> |
|
|
162 |
<a href="#setting-up-the-delegate-container-and-items">Setting up the Delegate container and items</a> |
|
|
163 |
</li> |
|
|
164 |
<li> |
|
|
165 |
<a href="#setting-up-the-yui-instance">Setting up the YUI Instance</a> |
|
|
166 |
</li> |
|
|
167 |
<li> |
|
|
168 |
<a href="#making-the-nodes-draggable">Making the Nodes draggable</a> |
|
|
169 |
</li> |
|
|
170 |
<li> |
|
|
171 |
<a href="#adding-items-to-the-list-without-creating-new-instances">Adding items to the list without creating new instances.</a> |
|
|
172 |
</li> |
|
|
173 |
</ul> |
|
|
174 |
</div> |
|
|
175 |
</div> |
|
|
176 |
|
|
|
177 |
|
|
|
178 |
|
|
|
179 |
<div class="sidebox"> |
|
|
180 |
<div class="hd"> |
|
|
181 |
<h2 class="no-toc">Examples</h2> |
|
|
182 |
</div> |
|
|
183 |
|
|
|
184 |
<div class="bd"> |
|
|
185 |
<ul class="examples"> |
|
|
186 |
|
|
|
187 |
|
|
|
188 |
<li data-description="A simple drag interaction that doesn't require a drop interaction."> |
|
|
189 |
<a href="simple-drag.html">Simple Drag</a> |
|
|
190 |
</li> |
|
|
191 |
|
|
|
192 |
|
|
|
193 |
|
|
|
194 |
<li data-description="How to apply the Drag Plugin to a node."> |
|
|
195 |
<a href="drag-plugin.html">Drag - Node plugin</a> |
|
|
196 |
</li> |
|
|
197 |
|
|
|
198 |
|
|
|
199 |
|
|
|
200 |
<li data-description="A simple proxy drag interaction that doesn't require a drop interaction."> |
|
|
201 |
<a href="proxy-drag.html">Drag - Proxy</a> |
|
|
202 |
</li> |
|
|
203 |
|
|
|
204 |
|
|
|
205 |
|
|
|
206 |
<li data-description="How to constrain a draggable Node to another Node's region."> |
|
|
207 |
<a href="constrained-drag.html">Drag - Constrained to a Region</a> |
|
|
208 |
</li> |
|
|
209 |
|
|
|
210 |
|
|
|
211 |
|
|
|
212 |
<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."> |
|
|
213 |
<a href="groups-drag.html">Drag - Interaction Groups</a> |
|
|
214 |
</li> |
|
|
215 |
|
|
|
216 |
|
|
|
217 |
|
|
|
218 |
<li data-description="The use of the drag shim when dragging nodes over other troublesome nodes."> |
|
|
219 |
<a href="shim-drag.html">Using the Drag Shim</a> |
|
|
220 |
</li> |
|
|
221 |
|
|
|
222 |
|
|
|
223 |
|
|
|
224 |
<li data-description="How to use the Drop Target events to code your application."> |
|
|
225 |
<a href="drop-code.html">Using Drop Based Coding</a> |
|
|
226 |
</li> |
|
|
227 |
|
|
|
228 |
|
|
|
229 |
|
|
|
230 |
<li data-description="How you can use the DD Scroll plugin to scroll the browser window as you drag."> |
|
|
231 |
<a href="winscroll.html">Window Scrolling</a> |
|
|
232 |
</li> |
|
|
233 |
|
|
|
234 |
|
|
|
235 |
|
|
|
236 |
<li data-description="How to use DD.Delegate to create a scalable solution which supports multiple draggable items."> |
|
|
237 |
<a href="delegate.html">Drag Delegation</a> |
|
|
238 |
</li> |
|
|
239 |
|
|
|
240 |
|
|
|
241 |
|
|
|
242 |
<li data-description="Using DD.Delegate to support dragging multiple items and dropping them onto a Drop Target."> |
|
|
243 |
<a href="delegate-drop.html">Drag Delegation with a Drop Target</a> |
|
|
244 |
</li> |
|
|
245 |
|
|
|
246 |
|
|
|
247 |
|
|
|
248 |
<li data-description="How to use Drag plugins with a DD Delegate based solution."> |
|
|
249 |
<a href="delegate-plugins.html">Using Drag Plugins with Delegate</a> |
|
|
250 |
</li> |
|
|
251 |
|
|
|
252 |
|
|
|
253 |
|
|
|
254 |
<li data-description="This example shows how to make a sortable list using Custom Event Bubbling."> |
|
|
255 |
<a href="list-drag.html">List Reorder w/Bubbling</a> |
|
|
256 |
</li> |
|
|
257 |
|
|
|
258 |
|
|
|
259 |
|
|
|
260 |
<li data-description="This example shows how to make a sortable list using Custom Event Bubbling and Node Scrolling."> |
|
|
261 |
<a href="scroll-list.html">List Reorder w/Scrolling</a> |
|
|
262 |
</li> |
|
|
263 |
|
|
|
264 |
|
|
|
265 |
|
|
|
266 |
<li data-description="How to make an animated node a Drop target."> |
|
|
267 |
<a href="anim-drop.html">Animated Drop Targets</a> |
|
|
268 |
</li> |
|
|
269 |
|
|
|
270 |
|
|
|
271 |
|
|
|
272 |
<li data-description="Example Photo Browser application."> |
|
|
273 |
<a href="photo-browser.html">Photo Browser</a> |
|
|
274 |
</li> |
|
|
275 |
|
|
|
276 |
|
|
|
277 |
|
|
|
278 |
<li data-description="Portal style example using Drag & Drop Event Bubbling and Animation."> |
|
|
279 |
<a href="portal-drag.html">Portal Style Example</a> |
|
|
280 |
</li> |
|
|
281 |
|
|
|
282 |
|
|
|
283 |
|
|
|
284 |
|
|
|
285 |
|
|
|
286 |
|
|
|
287 |
</ul> |
|
|
288 |
</div> |
|
|
289 |
</div> |
|
|
290 |
|
|
|
291 |
|
|
|
292 |
|
|
|
293 |
<div class="sidebox"> |
|
|
294 |
<div class="hd"> |
|
|
295 |
<h2 class="no-toc">Examples That Use This Component</h2> |
|
|
296 |
</div> |
|
|
297 |
|
|
|
298 |
<div class="bd"> |
|
|
299 |
<ul class="examples"> |
|
|
300 |
|
|
|
301 |
|
|
|
302 |
|
|
|
303 |
|
|
|
304 |
|
|
|
305 |
|
|
|
306 |
|
|
|
307 |
|
|
|
308 |
|
|
|
309 |
|
|
|
310 |
|
|
|
311 |
|
|
|
312 |
|
|
|
313 |
|
|
|
314 |
|
|
|
315 |
|
|
|
316 |
|
|
|
317 |
|
|
|
318 |
|
|
|
319 |
|
|
|
320 |
|
|
|
321 |
|
|
|
322 |
|
|
|
323 |
|
|
|
324 |
|
|
|
325 |
|
|
|
326 |
|
|
|
327 |
|
|
|
328 |
|
|
|
329 |
|
|
|
330 |
|
|
|
331 |
|
|
|
332 |
|
|
|
333 |
|
|
|
334 |
<li data-description="Working with multiple YUI instances."> |
|
|
335 |
<a href="../yui/yui-multi.html">Multiple Instances</a> |
|
|
336 |
</li> |
|
|
337 |
|
|
|
338 |
|
|
|
339 |
|
|
|
340 |
<li data-description="Use StyleSheet to adjust the CSS rules applying a page theme from user input"> |
|
|
341 |
<a href="../stylesheet/stylesheet-theme.html">Adjusting a Page Theme on the Fly</a> |
|
|
342 |
</li> |
|
|
343 |
|
|
|
344 |
|
|
|
345 |
</ul> |
|
|
346 |
</div> |
|
|
347 |
</div> |
|
|
348 |
|
|
|
349 |
</div> |
|
|
350 |
</div> |
|
|
351 |
</div> |
|
|
352 |
</div> |
|
|
353 |
|
|
|
354 |
<script src="../assets/vendor/prettify/prettify-min.js"></script> |
|
|
355 |
<script>prettyPrint();</script> |
|
|
356 |
|
|
|
357 |
<script> |
|
|
358 |
YUI.Env.Tests = { |
|
|
359 |
examples: [], |
|
|
360 |
project: '../assets', |
|
|
361 |
assets: '../assets/dd', |
|
|
362 |
name: 'delegate', |
|
|
363 |
title: 'Drag Delegation', |
|
|
364 |
newWindow: '', |
|
|
365 |
auto: false |
|
|
366 |
}; |
|
|
367 |
YUI.Env.Tests.examples.push('simple-drag'); |
|
|
368 |
YUI.Env.Tests.examples.push('drag-plugin'); |
|
|
369 |
YUI.Env.Tests.examples.push('proxy-drag'); |
|
|
370 |
YUI.Env.Tests.examples.push('constrained-drag'); |
|
|
371 |
YUI.Env.Tests.examples.push('groups-drag'); |
|
|
372 |
YUI.Env.Tests.examples.push('shim-drag'); |
|
|
373 |
YUI.Env.Tests.examples.push('drop-code'); |
|
|
374 |
YUI.Env.Tests.examples.push('winscroll'); |
|
|
375 |
YUI.Env.Tests.examples.push('delegate'); |
|
|
376 |
YUI.Env.Tests.examples.push('delegate-drop'); |
|
|
377 |
YUI.Env.Tests.examples.push('delegate-plugins'); |
|
|
378 |
YUI.Env.Tests.examples.push('list-drag'); |
|
|
379 |
YUI.Env.Tests.examples.push('scroll-list'); |
|
|
380 |
YUI.Env.Tests.examples.push('anim-drop'); |
|
|
381 |
YUI.Env.Tests.examples.push('photo-browser'); |
|
|
382 |
YUI.Env.Tests.examples.push('portal-drag'); |
|
|
383 |
YUI.Env.Tests.examples.push('yui-multi'); |
|
|
384 |
YUI.Env.Tests.examples.push('stylesheet-theme'); |
|
|
385 |
|
|
|
386 |
</script> |
|
|
387 |
<script src="../assets/yui/test-runner.js"></script> |
|
|
388 |
|
|
|
389 |
|
|
|
390 |
|
|
|
391 |
</body> |
|
|
392 |
</html> |