forked from mjsarfatti/nestedSortable
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
525 lines (446 loc) · 16 KB
/
Copy pathindex.html
File metadata and controls
525 lines (446 loc) · 16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
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
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
<!doctype html>
<!-- =================================================================================================================== -->
<html lang="en">
<!-- =================================================================================================================== -->
<head>
<meta charset="utf-8">
<title>nestedSortable jQuery Plugin</title>
<meta name="description" content="Demo page of the Nested Sortable jQuery Plugin">
<meta name="author" content="Manuele J Sarfatti">
<script>
(function(){
if (!/*@cc_on!@*/0) return;
var e = ("abbr article aside audio canvas command datalist details figure figcaption footer "+
"header hgroup mark meter nav output progress section summary time video").split(' '),
i=e.length;
while (i--) {
document.createElement(e[i])
}
})(document.documentElement,'className');
</script>
<style type="text/css">
html {
background-color: #eee;
}
body {
color: #333;
background-color: #fff;
font-size: 13px;
font-family: "Helvetica Neue", Corbel, "Nimbus Sans L", Helvetica, Arial, sans-serif;
padding: 2em 4em;
width: 860px;
margin: 0 auto;
box-shadow: 1px 1px 8px #444;
-mox-box-shadow: 1px 1px 8px #444;
-webkit-box-shadow: 1px -1px 8px #444;
}
pre, code {
font-size: 12px;
}
pre {
width: 100%;
overflow: auto;
}
small {
font-size: 90%;
}
small code {
font-size: 11px;
}
.placeholder {
background-color: #cfcfcf;
}
.ui-nestedSortable-error {
background:#fbe3e4;
color:#8a1f11;
}
ol {
margin: 0;
padding: 0;
padding-left: 30px;
}
ol.sortable, ol.sortable ol {
margin: 0 0 0 25px;
padding: 0;
list-style-type: none;
}
ol.sortable {
margin: 4em 0;
}
.sortable li {
margin: 7px 0 0 0;
padding: 0;
}
.sortable li div {
border: 1px solid black;
padding: 3px;
margin: 0;
cursor: move;
}
h1 {
font-size: 2em;
margin-bottom: 0;
}
h2 {
font-size: 1.2em;
font-weight: normal;
font-style: italic;
margin-top: .2em;
margin-bottom: 1.5em;
}
h3 {
font-size: 1em;
margin: 1em 0 .3em;;
}
p, ol, ul, pre, form {
margin-top: 0;
margin-bottom: 1em;
}
dl {
margin: 0;
}
dd {
margin: 0;
padding: 0 0 0 1.5em;
}
code {
background: #e5e5e5;
}
input {
vertical-align: text-bottom;
}
.notice {
color: #c33;
}
</style>
<!-- =================================================================================================================== -->
<body>
<header>
<h1>nestedSortable jQuery Plugin</h1>
<h2>Sort and move list items between nested lists</h2>
</header>
<section>
<p>
Latest version: <b>1.3.4</b> / <b>May 11, 2011</b>
<p>
<strong>Download the latest version directly from the
<a href="https://github.com/mjsarfatti/nestedSortable">GitHub page</a>.</strong>
<p class="notice">
<strong>For QA, feature requests and general support please visit the nestedSortable
<a href="http://mjsarfatti.com/sandbox/nestedSortable/forum">forum</a>.</strong>
</p>
</section> <!-- END section -->
<section id="demo">
<ol class="sortable">
<li id="list_1"><div>Item 1</div>
<li id="list_2"><div>Item 2</div>
<ol>
<li id="list_3"><div>Sub Item 2.1</div>
<li id="list_4"><div>Sub Item 2.2</div>
<li id="list_5"><div>Sub Item 2.3</div>
<li id="list_6"><div>Sub Item 2.4</div>
</ol>
<li id="list_7" class="no-nest"><div>Item 3 (no-nesting)</div>
<li id="list_8" class="no-nest"><div>Item 4 (no-nesting)</div>
<li id="list_9"><div>Item 5</div>
<li id="list_10"><div>Item 6</div>
<ol>
<li id="list_11"><div>Sub Item 6.1</div>
<li id="list_12" class="no-nest"><div>Sub Item 6.2 (no-nesting)</div>
<li id="list_13"><div>Sub Item 6.3</div>
<li id="list_14"><div>Sub Item 6.4</div>
</ol>
<li id="list_15"><div>Item 7</div>
<li id="list_16"><div>Item 8</div>
</ol>
<h3>Try the custom methods:</h3>
<p><br />
<input type="submit" name="serialize" id="serialize" value="Serialize" />
<pre id="serializeOutput"></pre>
<p>
<input type="submit" name="toArray" id="toArray" value="To array" />
<pre id="toArrayOutput"></pre>
<p>
<input type="submit" name="toHierarchy" id="toHierarchy" value="To hierarchy" />
<pre id="toHierarchyOutput"></pre>
<p>
<em>Note: This demo has the <code>maxLevels</code> option set to '3'.</em>
</p>
</section> <!-- END #demo -->
<section id="documentation">
<h3>Features:</h3>
<ul>
<li>Designed to work seamlessly with the <a href="http://en.wikipedia.org/wiki/Nested_set_model"
title="Link to the Wikipedia article">nested</a>
<a href="http://articles.sitepoint.com/article/hierarchical-data-database"
title="Link to a Sitepoint tutorial on the use of MYSQL and PHP">set</a> model (have a look at the
<code>toArray</code> method).
<li>Items can be sorted in their own list, moved across the tree, or nested under other items.
<li>All jQuery Sortable options, events and methods are available.
<li>It is possible to define elements that will not accept a new nested item/list (<code>no-nesting</code> in the
above list).
<li>It is possible to indicate a maximum number of nesting levels.
</ul>
<h3>Usage:</h3>
<pre>
<ol class="sortable">
<li><div>Some content</div></li>
<li><div>Some content</div>
<ol>
<li><div>Some sub-item content</div></li>
<li><div>Some sub-item content</div></li>
</ol>
</li>
<li><div>Some content</div></li>
</ol></pre>
<p>
<small>
<code><div></code> can be any tag (e.g. <code><span></code>), but it has to be some tag. This
same tag has to be set as the 'toleranceElement' in the options, and this, or one of its children, as the
'handle'.<br />
Any <code><li></code> can have either one or two tags, the second being <code><ol></code>.
</small>
<h3>Custom options:</h3>
<dl>
<dt><code>tabSize</code>
<dd>How far right or left (in pixels) the item has to travel in order to be nested or to be sent
outside its current list. Default: <code>20</code>
<dt><code>disableNesting</code>
<dd>The class name of the items that will not accept nested lists. Default:
<code>'ui-nestedSortable-no-nesting'</code>
<dt><code>errorClass</code>
<dd>The class given to the placeholder in case of error. Default:
<code>'ui-nestedSortable-error'</code>
<dt><code>listType</code>
<dd>The list type used (ordered or unordered). Default: <code>'ol'</code> (see 1.2 Changelog)
<dt><code>maxLevels</code>
<dd>How many nesting levels can the list have at the most. If set to <code>'0'</code> the levels are unlimited.
Default: <code>'0'</code>
<dt><code>noJumpFix</code>
<dd>Set this to <code>'1'</code> to deactivate the fix (see 1.2.2 Changelog), in case it messes
things up for you. Default: <code>'0'</code>
</dl>
<h3>Custom methods:</h3>
<dl>
<dt><code>serialize</code>
<dd>Serializes the nested list into a string like
<strong><em>setName</em>[<em>itemId</em>]=<em>parentId</em>&<em>setName</em>[<em>itemId</em>]=<em>parentId</em></strong>
from each item's id reading 'setName_itemId' (where itemId is a number).<br />
It accepts the same options as the UI Sortable method (<code>key</code>, <code>attribute</code> and
<code>expression</code>).
<dt><code>toArray</code>
<dd>Builds an array where each element is in the form:
<pre>
setName[n] =>
{
'item_id': <em>itemId</em>,
'parent_id': <em>parentId</em>,
'depth': <em>depth</em>,
'left': <em>left</em>,
'right': <em>right</em>,
}</pre>
looking at the items' id's as in <code>serialize</code>.<br />
The <strong>left</strong> and <strong>right</strong> values comply with the nested set model.<br />
This method accepts two options:<br />
<code>startDepthCount</code> sets the starting depth number (default is 0), <code>expression</code>
is the regex used to extract the number from the item's id (default is the same as
<code>serialize</code>), <code>attribute</code> is the element's attribute that the method will look
at (default is 'id').<br />
The first array element is the root element which contains all the others, and it is built from the
available data with no need for any special entry.
<dt><code>toHierarchy</code>
<dd>Builds a hierarchical object with data from the nested elements in the form:
<pre>
'0' ...
'id' => <em>itemId</em>
'1' ...
'id' => <em>itemId</em>
'children' ...
'0' ...
'id' => <em>itemId</em>
'1' ...
'id' => <em>itemId</em>
'2' ...
'id' => <em>itemId</em></pre>
Similarly to <code>toArray</code>, it accepts the <code>attribute</code> and <code>expression</code>
options.
</dl>
<h3>1.3.4 Changelog:</h3>
<ul>
<li>Fixed: the depth of a list item's subtree was miscalculated, having top-level elements occasionally
kicked out of the main <code><ol></code> containter.
</ul>
<h3>1.3.3 Changelog:</h3>
<ul>
<li>Fixed: if <code><li></code> items had the end tag and an element was moved upwards, a text node was
detected as <i>previousItem</i> instead of the correct <code><li></code> element.
</ul>
<h3>1.3.2 Changelog:</h3>
<ul>
<li>Fixed: the position error wasn't detected at the exact moment an item was moved in a not-allowed position, but
only after moving it 1px more.
</ul>
<h3>1.3.1 Changelog:</h3>
<ul>
<li>Fixed: single-item maxLevels error wasn't recognized.
<li>Fixed: <code>toArray</code> ran twice through nested items.
<li>Added: an item nested too deep is now sent to the closest allowed position.
</ul>
<h3>1.3 Changelog:</h3>
<ul>
<li>Implemented the <code>maxLevels</code> option.
</ul>
<h3>1.2.3 Changelog:</h3>
<ul>
<li>The <code>change</code> event is now correctly triggered.
<li>Using <code>toArray</code> and <code>toHierarchy</code> inside a <code>change</code> callback function
(and possibly other events' callback functions as well) doesn't result in an error anymore.
<li>The <code>toArray</code> method now outputs an ordered array.
</ul>
<h3>1.2.2 Changelog:</h3>
<ul>
<li>Fixed an issue with the page jumping upwards in some situations with the list taller then the viewport.
<li>Fix to prevent an item to be moved under a no-nest item while moved to the right.
(Thanks to <a href="http://philworks.com/">Philippe Archambault</a>)
<li>Added <code>toHierarchy</code> method. (Thanks to <a href="http://www.millan.rs">Milan Petrovic</a>)
</ul>
<h3>1.2.1 Changelog:</h3>
<ul>
<li>Finally made <code>serialize</code> and <code>toArray</code> work in IE6+ (In fact,
<code>serialize</code> already worked, but it was badly implemented in this demo page).
</ul>
<h3>1.2b Changelog:</h3>
<ul>
<li>There was a trailing comma too much on line 21. Either download 1.2b or remove that comma yourself.
</ul>
<h3>1.2 Changelog:</h3>
<ul>
<li>Added a custom option to specify the desired list type, and changed the default list type to
<code><ol></code>. Since we are dealing with ordering sets of items ordered lists are the way to go
according to HTML specifications.
</ul>
<h3>1.1.1 Changelog:</h3>
<ul>
<li>Improved the <code>toArray</code> method (<strong>right</strong> and <strong>left</strong> values have
been added, <strong>item_id</strong> and <strong>parent_id</strong> are now actual numbers).
</ul>
<h3>1.1 Changelog:</h3>
<ul>
<li>Implemented <code>serialize</code> and <code>toArray</code> methods.
</ul>
<h3>1.0.3 Changelog:</h3>
<ul>
<li>Fixed a bug that made IE 6 & 7 to not detect the correct placeholder height.
<li>Fixed a minor visual issue.
</ul>
<h3>1.0.2 Changelog:</h3>
<ul>
<li>Definitive fix for absolutely positioned lists.
</ul>
<h3>Known bugs:</h3>
<p>
Text gets ugly when you sort items in some versions of IE, in certain situation. This is a sortable bug.
<h3>Roadmap:</h3>
<dl>
<dt><del>1.1</del>
<dd><del>Adapt <code>serialize</code> and <code>toArray</code> in order to have it show the
indentation level, somehow.</del>
<dt><del>1.3</del>
<dd><del>Make a <code>maxLevel</code> option.</del>
</dl>
<h3>Requires:</h3>
<p>
jQuery 1.4+<br />
jQuery UI Sortable 1.8+
<h3>Browser compatibility:</h3>
<p>
Tested with: IE 6, Firefox 3.6, Chrome 10, Safari 3<br />
Will also work with: IE 6+, Firefox 3.5+, Chrome 4+, Safari 3+
<h3>Licence:</h3>
<p>
This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/">Creative
Commons Attribution-ShareAlike 3.0 Unported License</a>.
<p>
This work is now <em>pizzaware</em>. If it saved your life, or you just feel good at heart, please consider
offering me a pizza. This can be done in two ways: (1) use the Paypal button below; (2) send me cash via
traditional mail to my home address in Italy. Is the second method legal? It is in Italy if you use Posta
assicurata. You should check with your local laws if you live elsewhere.
</p>
<!-- Paypal Donate Button -->
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_donations">
<input type="hidden" name="business" value="RSJEW3N9PRMYY">
<input type="hidden" name="lc" value="GB">
<input type="hidden" name="item_name" value="nestedSortable">
<input type="hidden" name="item_number" value="002">
<input type="hidden" name="currency_code" value="EUR">
<input type="hidden" name="bn" value="PP-DonationsBF:btn_donate_SM.gif:NonHosted">
<input type="image" src="https://www.paypalobjects.com/WEBSCR-640-20110306-1/en_GB/i/btn/btn_donate_SM.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online.">
<img alt="" border="0" src="https://www.paypalobjects.com/WEBSCR-640-20110306-1/it_IT/i/scr/pixel.gif" width="1" height="1">
<a href="http://mjsarfatti.com/info.php">contact me</a>
</form>
<!-- END Paypal Donate Button -->
<p>
© 2010–2011 Manuele J Sarfatti
</p>
</section> <!-- END #documentation -->
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.5/jquery-ui.min.js"></script>
<script type="text/javascript" src="../jquery.mjs.nestedSortable.js"></script>
<script>
$(document).ready(function(){
$('ol.sortable').nestedSortable({
disableNesting: 'no-nest',
forcePlaceholderSize: true,
handle: 'div',
helper: 'clone',
items: 'li',
maxLevels: 3,
opacity: .6,
placeholder: 'placeholder',
revert: 250,
tabSize: 25,
tolerance: 'pointer',
toleranceElement: '> div'
});
$('#serialize').click(function(){
serialized = $('ol.sortable').nestedSortable('serialize');
$('#serializeOutput').text(serialized+'\n\n');
})
$('#toHierarchy').click(function(e){
hiered = $('ol.sortable').nestedSortable('toHierarchy', {startDepthCount: 0});
hiered = dump(hiered);
(typeof($('#toHierarchyOutput')[0].textContent) != 'undefined') ?
$('#toHierarchyOutput')[0].textContent = hiered : $('#toHierarchyOutput')[0].innerText = hiered;
})
$('#toArray').click(function(e){
arraied = $('ol.sortable').nestedSortable('toArray', {startDepthCount: 0});
arraied = dump(arraied);
(typeof($('#toArrayOutput')[0].textContent) != 'undefined') ?
$('#toArrayOutput')[0].textContent = arraied : $('#toArrayOutput')[0].innerText = arraied;
})
});
function dump(arr,level) {
var dumped_text = "";
if(!level) level = 0;
//The padding given at the beginning of the line.
var level_padding = "";
for(var j=0;j<level+1;j++) level_padding += " ";
if(typeof(arr) == 'object') { //Array/Hashes/Objects
for(var item in arr) {
var value = arr[item];
if(typeof(value) == 'object') { //If it is an array,
dumped_text += level_padding + "'" + item + "' ...\n";
dumped_text += dump(value,level+1);
} else {
dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
}
}
} else { //Strings/Chars/Numbers etc.
dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
}
return dumped_text;
}
</script>
</body>
</html>