5
<title>Example: Multiple Lists</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: Multiple Lists</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 makes multiple sortable lists that are separate from one another and do not interact with each other.</p>
40
list-style-type: none;
43
border: 1px solid black;
49
background-color: #8DD5E7;
52
background-color: #EDFF9F;
58
<div id="demo" class="yui3-g">
59
<div class="yui3-u-1-2">
60
<h4 id="list-1">List 1</h4>
62
<li class="one">1</li>
63
<li class="one">2</li>
64
<li class="one">3</li>
65
<li class="one">4</li>
66
<li class="one">5</li>
67
<li class="one">6</li>
68
<li class="one">7</li>
69
<li class="one">8</li>
70
<li class="one">9</li>
71
<li class="one">10</li>
74
<div class="yui3-u-1-2">
75
<h4 id="list-2">List 2</h4>
77
<li class="two">A</li>
78
<li class="two">B</li>
79
<li class="two">C</li>
80
<li class="two">D</li>
81
<li class="two">E</li>
82
<li class="two">F</li>
83
<li class="two">G</li>
84
<li class="two">H</li>
85
<li class="two">I</li>
86
<li class="two">J</li>
93
YUI().use('dd-constrain', 'sortable', function(Y) {
94
var list1 = new Y.Sortable({
100
var list2 = new Y.Sortable({
113
<h3 id="setting-up-the-list">Setting Up the List</h3>
114
<p>First we need to create the HTML structure for the lists. Since <code>Sortable</code> uses <code>Y.DD.Delegate</code>, we need to set up the delegation containers (<code>#list1, #lists2</code>) and the list items (<code>li</code>).</p>
116
<pre class="code prettyprint"><div id="demo" class="yui3-g">
117
<div class="yui3-u-1-2">
118
<h4>List 1</h4>
119
<ul id="list1">
120
<li class="one">1</li>
121
<li class="one">2</li>
122
<li class="one">3</li>
123
<li class="one">4</li>
124
<li class="one">5</li>
125
<li class="one">6</li>
126
<li class="one">7</li>
127
<li class="one">8</li>
128
<li class="one">9</li>
129
<li class="one">10</li>
132
<div class="yui3-u-1-2">
133
<h4>List 2</h4>
134
<ul id="list2">
135
<li class="two">A</li>
136
<li class="two">B</li>
137
<li class="two">C</li>
138
<li class="two">D</li>
139
<li class="two">E</li>
140
<li class="two">F</li>
141
<li class="two">G</li>
142
<li class="two">H</li>
143
<li class="two">I</li>
144
<li class="two">J</li>
147
</div></pre>
150
<p>Now we give the lists some CSS to make them visible.</p>
152
<pre class="code prettyprint">#demo h4 {
164
list-style-type: none;
167
border: 1px solid black;
173
background-color: #8DD5E7;
176
background-color: #EDFF9F;
181
<h3 id="setting-up-the-yui-instance">Setting Up the YUI Instance</h3>
182
<p>Now we need to create our YUI instance and tell it to load the <code>sortable</code> module.</p>
183
<p>In this example we are also going to attach a <code>DD</code> plugin to the <code>Sortable</code> instances.</p>
185
<pre class="code prettyprint">YUI().use('dd-constrain', 'sortable'</pre>
188
<h3 id="making-the-lists-draggable">Making the Lists Draggable</h3>
189
<p>Now that we have a YUI instance with the <code>sortable</code> module, we need to instantiate a <code>Sortable</code> instance on each of the lists.</p>
191
<pre class="code prettyprint">YUI().use('dd-constrain', 'sortable', function(Y) {
192
var list1 = new Y.Sortable({
193
container: '#list1',
194
nodes: 'li',
195
opacity: '.1'
198
var list2 = new Y.Sortable({
199
container: '#list2',
200
nodes: 'li',
201
opacity: '.1'
207
<h3 id="applying-a-dd-plugin">Applying a DD Plugin</h3>
208
<p>Since <code>Sortable</code> uses <code>DD.Delegate</code>, there is a dd instance available after instantiation.</p>
209
<p>The <code>DD.Delegate</code> reference is found on the <code>.delegate</code> property of the <code>Sortable</code>.
210
This <code>DD.Delegate</code> instance has a <code>DD.Drag</code> instance bound to the <code>dd</code> property on the <code>DD.Delegate</code>
213
<pre class="code prettyprint">list1.delegate.dd.plug(Y.Plugin.DDConstrained, {
214
constrain2node: '#demo'
216
list2.delegate.dd.plug(Y.Plugin.DDConstrained, {
217
constrain2node: '#demo'
220
<p>Applying the <code>Plugin.DDConstrained</code> to the <code>Sortable</code> instance.</p>
222
<pre class="code prettyprint">YUI().use('dd-constrain', 'sortable', function(Y) {
223
var list1 = new Y.Sortable({
224
container: '#list1',
225
nodes: 'li',
226
opacity: '.1'
229
var list2 = new Y.Sortable({
230
container: '#list2',
231
nodes: 'li',
232
opacity: '.1'
235
list1.delegate.dd.plug(Y.Plugin.DDConstrained, {
236
constrain2node: '#demo'
238
list2.delegate.dd.plug(Y.Plugin.DDConstrained, {
239
constrain2node: '#demo'
248
<div id="sidebar" class="yui3-u">
250
<div id="toc" class="sidebox">
252
<h2 class="no-toc">Table of Contents</h2>
258
<a href="#list-1">List 1</a>
261
<a href="#list-2">List 2</a>
264
<a href="#setting-up-the-list">Setting Up the List</a>
267
<a href="#setting-up-the-yui-instance">Setting Up the YUI Instance</a>
270
<a href="#making-the-lists-draggable">Making the Lists Draggable</a>
273
<a href="#applying-a-dd-plugin">Applying a DD Plugin</a>
281
<div class="sidebox">
283
<h2 class="no-toc">Examples</h2>
287
<ul class="examples">
290
<li data-description="Create a simple sortable list.">
291
<a href="simple-sortable.html">Simple Sortable List</a>
296
<li data-description="Sortable list example with floated nodes.">
297
<a href="sortable-float.html">Floated List</a>
302
<li data-description="Multiple Sortable Lists that are separate from one another.">
303
<a href="sortable-multi.html">Multiple Lists</a>
308
<li data-description="Multiple Sortable Lists that are fully joined together.">
309
<a href="sortable-multi-full.html">Multiple Lists - Full Join</a>
314
<li data-description="Multiple Sortable Lists that are outer joined together.">
315
<a href="sortable-multi-out.html">Multiple Lists - Outer Join</a>
320
<li data-description="Multiple Sortable Lists that are inner joined together.">
321
<a href="sortable-multi-in.html">Multiple Lists - Inner Join</a>
335
<script src="../assets/vendor/prettify/prettify-min.js"></script>
336
<script>prettyPrint();</script>