-
Notifications
You must be signed in to change notification settings - Fork 442
/
index.html
1417 lines (1364 loc) · 60.9 KB
/
index.html
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
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html>
<head>
<title>jQuery Sortable</title>
<link href='css/vendor.css' rel='stylesheet'>
<link href='css/application.css' rel='stylesheet'>
</head>
<body>
<div class='navbar navbar-fixed-top'>
<div class='navbar-inner'>
<div class='bootstrap-container'>
<ul class='nav'>
<li>
<a href='#home'>Home</a>
</li>
<li>
<a href='#features'>Features</a>
</li>
<li>
<a href='#getting-started'>Getting started</a>
</li>
<li class='dropdown'>
<a class='dropdown-toggle' data-toggle='dropdown' href='#'>
Examples
<b class='caret'></b>
</a>
<ul class='dropdown-menu'>
<li>
<a href='#connected'>Connected lists with drop animation</a>
</li>
<li>
<a href='#handle'>Sort handle and limited drag/drop</a>
</li>
<li>
<a href='#nested'>Toggable nested lists</a>
</li>
<li>
<a href='#limited-target'>Limited drop targets</a>
</li>
<li>
<a href='#bootstrap'>Sorting a bootstrap menu</a>
</li>
<li>
<a href='#table'>Sort tables</a>
</li>
<li>
<a href='#external'>External examples</a>
</li>
</ul>
</li>
<li>
<a href='#docs'>Documentation</a>
</li>
<li>
<a href='#alternatives'>Alternatives</a>
</li>
</ul>
<div class='pull-right'>
<a class='brand' href='#'>jQuery Sortable</a>
</div>
</div>
</div>
</div>
<div class='bootstrap-container'>
<div id='home'>
<div class='hero-unit'>
<h1>jQuery Sortable</h1>
<p>A flexible, opinionated sorting plugin for jQuery</p>
<p>
<a class='btn btn-large btn-primary' href='https://github.com/johnny/jquery-sortable'>
<i class='icon-eye-open icon-white'></i>
View on GitHub
</a>
<a class='btn btn-large btn-success' href='js/jquery-sortable.js'>
<i class='icon-hdd icon-white'></i>
Download
(v0.9.13)
</a>
</p>
<p>
<small>
Download
<a href='js/jquery-sortable-min.js'>minified</a>
version
(9.7 kb, gzipped ~3.2 kb)
</small>
</p>
</div>
</div>
<div id='features'>
<div class='page-header'>
<h1>Features</h1>
</div>
<div class='row'>
<div class='span6'>
<h3>So what does it do?</h3>
<ul>
<li>Sorts any items in any container</li>
<li>Fully supports nested containers</li>
<li>Connect lists</li>
<li>Callbacks and events (see docs)</li>
<li>Pure drag/drop lists</li>
<li>Vertical and horizontal sorting</li>
</ul>
<h3>Why another sortable plugin?</h3>
<p>
you might ask.
Aren't there
<a href='#alternatives'>many</a>
others?
</p>
<p>
<strong>The answer is: nested lists.</strong>
None of the other solutions had a decent support for nested lists.
<a href='http://mjsarfatti.com/sandbox/nestedSortable/'>nestedSortable</a>
relies on a fixed width hierarchy.
Others mimic the way jQuery UI does
<a href='http://jqueryui.com/demos/sortable/'>sortables</a>
and therefore require ugly
<a href='https://github.com/jquery/jquery-ui/pull/555'>hacks</a>
that suffer from sudden jumps.
</p>
<h3>The opinionated part</h3>
<p>
This plugin does one and only one thing:
<strong>sorting</strong>
. If you need animations or autoscrolling, do them
<a href='#connected'>yourself</a>
.
</p>
<p>
Moreover this plugin assumes that the placeholder has zero height/width.
As a result, the item dimensions may be cached.
<small>This might change in the future, if need be.</small>
</p>
<h3>Compatibility</h3>
<p>
<code>jquery-sortable.js</code>
has been tested with the following browsers
</p>
<ul>
<li>Firefox >= 3.5</li>
<li>Chrome</li>
<li>IE > 7</li>
<li>Safari >= 6</li>
<li>Opera</li>
<li>Konqueror</li>
</ul>
<p>
If you confirmed, that it works on other browsers please
<a href='mailto:jvadev@gmail.com'>tell me</a>
.
</p>
</div>
<div class='span6'>
<h3>
Show it to me!
<small>
With default options.
</small>
</h3>
<p>
<span class='label label-info'>Heads Up!</span>
There is no on-the-fly creation of sublists.
Only list items that contain a sublist are drop targets.
</p>
<ol class='default vertical'>
<li>
First
<ol></ol>
</li>
<li>
Second
<ol></ol>
</li>
<li>
Third
<ol>
<li>First</li>
<li>Second</li>
<li>
Third
<ol>
<li>First</li>
<li>Second</li>
</ol>
<ol>
<li>First</li>
<li>Second</li>
</ol>
</li>
</ol>
</li>
<li>Fourth</li>
<li>Fifth</li>
<li>Sixth</li>
</ol>
</div>
</div>
</div>
<div id='getting-started'>
<div class='page-header'>
<h1>Getting started</h1>
</div>
<p>Making a list sortable consists of 3 easy steps</p>
<div class='row'>
<div class="span4">
<h3>Add styles</h3>
<div class="CodeRay">
<div class="code"><pre><span class="tag">body</span><span class="class">.dragging</span>, <span class="tag">body</span><span class="class">.dragging</span> <span class="tag">*</span> {
<span class="key">cursor</span>: <span class="value">move</span> <span class="important">!important</span>;
}
<span class="class">.dragged</span> {
<span class="key">position</span>: <span class="value">absolute</span>;
<span class="key">opacity</span>: <span class="float">0.5</span>;
<span class="key">z-index</span>: <span class="float">2000</span>;
}
<span class="tag">ol</span><span class="class">.example</span> <span class="tag">li</span><span class="class">.placeholder</span> {
<span class="key">position</span>: <span class="value">relative</span>;
<span class="comment">/** More li styles **/</span>
}
<span class="tag">ol</span><span class="class">.example</span> <span class="tag">li</span><span class="class">.placeholder</span><span class="pseudo-class">:before</span> {
<span class="key">position</span>: <span class="value">absolute</span>;
<span class="comment">/** Define arrowhead **/</span>
}</pre></div>
</div>
<p>
<small>
Look
<a href='https://github.com/johnny/jquery-sortable/blob/master/source/css/jquery-sortable.css.sass'>here</a>
for a complete example
</small>
</p>
</div>
<div class="span4">
<h3>Define your HTML</h3>
<div class="CodeRay">
<div class="code"><pre><span class="tag"><ol</span> <span class="attribute-name">class</span>=<span class="string"><span class="delimiter">'</span><span class="content">example</span><span class="delimiter">'</span></span><span class="tag">></span>
<span class="tag"><li></span>First<span class="tag"></li></span>
<span class="tag"><li></span>Second<span class="tag"></li></span>
<span class="tag"><li></span>Third<span class="tag"></li></span>
<span class="tag"></ol></span>
<span class="tag"><script</span> <span class="attribute-name">src</span>=<span class="string"><span class="delimiter">'</span><span class="content">js/jquery-sortable.js</span><span class="delimiter">'</span></span><span class="tag">></span><span class="tag"></script></span></pre></div>
</div>
</div>
<div class="span4">
<h3>Call the initializer</h3>
<div class="CodeRay">
<div class="code"><pre><span class="predefined">$</span>(<span class="keyword">function</span> () {
<span class="predefined">$</span>(<span class="string"><span class="delimiter">"</span><span class="content">ol.example</span><span class="delimiter">"</span></span>).sortable();
});</pre></div>
</div>
</div>
</div>
</div>
<div id='examples'>
<div class='page-header'>
<h1>Examples</h1>
</div>
<div id='connected'>
<h2>Connected lists with drop animation</h2>
<div class='row'>
<div class="span12 example">
<div class="CodeRay">
<div class="code"><pre><span class="keyword">var</span> adjustment;
<span class="predefined">$</span>(<span class="string"><span class="delimiter">"</span><span class="content">ol.simple_with_animation</span><span class="delimiter">"</span></span>).sortable({
<span class="key">group</span>: <span class="string"><span class="delimiter">'</span><span class="content">simple_with_animation</span><span class="delimiter">'</span></span>,
<span class="key">pullPlaceholder</span>: <span class="predefined-constant">false</span>,
<span class="comment">// animation on drop</span>
<span class="function">onDrop</span>: <span class="keyword">function</span> (<span class="predefined">$item</span>, container, _super) {
<span class="keyword">var</span> <span class="predefined">$clonedItem</span> = <span class="predefined">$</span>(<span class="string"><span class="delimiter">'</span><span class="content"><li/></span><span class="delimiter">'</span></span>).css({<span class="key">height</span>: <span class="integer">0</span>});
<span class="predefined">$item</span>.before(<span class="predefined">$clonedItem</span>);
<span class="predefined">$clonedItem</span>.animate({<span class="key"><span class="delimiter">'</span><span class="content">height</span><span class="delimiter">'</span></span>: <span class="predefined">$item</span>.height()});
<span class="predefined">$item</span>.animate(<span class="predefined">$clonedItem</span>.position(), <span class="keyword">function</span> () {
<span class="predefined">$clonedItem</span>.detach();
_super(<span class="predefined">$item</span>, container);
});
},
<span class="comment">// set $item relative to cursor position</span>
<span class="function">onDragStart</span>: <span class="keyword">function</span> (<span class="predefined">$item</span>, container, _super) {
<span class="keyword">var</span> offset = <span class="predefined">$item</span>.offset(),
pointer = container.rootGroup.pointer;
adjustment = {
<span class="key">left</span>: pointer.left - offset.left,
<span class="key">top</span>: pointer.top - offset.top
};
_super(<span class="predefined">$item</span>, container);
},
<span class="function">onDrag</span>: <span class="keyword">function</span> (<span class="predefined">$item</span>, position) {
<span class="predefined">$item</span>.css({
<span class="key">left</span>: position.left - adjustment.left,
<span class="key">top</span>: position.top - adjustment.top
});
}
});</pre></div>
</div>
</div>
<div class='span4'>
<ul>
<li>
Define your own
<strong>drop animation</strong>
</li>
<li>
Connect lists by placing them in the same
<code>group</code>
</li>
<li>
Only sort if the cursor is
<strong>above a container</strong>
</li>
</ul>
<p><div class="btn btn-primary show-code" data-toggle="button"><i class="icon-chevron-down"></i> show me the code</div></p>
</div>
<div class='span4'>
<ol class='simple_with_animation vertical'>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
<li>Item 4</li>
<li>Item 5</li>
<li>Item 6</li>
</ol>
</div>
<div class='span4'>
<ol class='simple_with_animation vertical'>
<li class='highlight'>Item 1</li>
<li class='highlight'>Item 2</li>
<li class='highlight'>Item 3</li>
<li class='highlight'>Item 4</li>
<li class='highlight'>Item 5</li>
<li class='highlight'>Item 6</li>
</ol>
</div>
</div>
</div>
<div id='handle'>
<h2>Sort handle and limited drag/drop</h2>
<div class='row'>
<div class="span12 example">
<div class="CodeRay">
<div class="code"><pre><span class="predefined">$</span>(<span class="string"><span class="delimiter">"</span><span class="content">ol.simple_with_drop</span><span class="delimiter">"</span></span>).sortable({
<span class="key">group</span>: <span class="string"><span class="delimiter">'</span><span class="content">no-drop</span><span class="delimiter">'</span></span>,
<span class="key">handle</span>: <span class="string"><span class="delimiter">'</span><span class="content">i.icon-move</span><span class="delimiter">'</span></span>,
<span class="function">onDragStart</span>: <span class="keyword">function</span> (<span class="predefined">$item</span>, container, _super) {
<span class="comment">// Duplicate items of the no drop area</span>
<span class="keyword">if</span>(!container.options.drop)
<span class="predefined">$item</span>.clone().insertAfter(<span class="predefined">$item</span>);
_super(<span class="predefined">$item</span>, container);
}
});
<span class="predefined">$</span>(<span class="string"><span class="delimiter">"</span><span class="content">ol.simple_with_no_drop</span><span class="delimiter">"</span></span>).sortable({
<span class="key">group</span>: <span class="string"><span class="delimiter">'</span><span class="content">no-drop</span><span class="delimiter">'</span></span>,
<span class="key">drop</span>: <span class="predefined-constant">false</span>
});
<span class="predefined">$</span>(<span class="string"><span class="delimiter">"</span><span class="content">ol.simple_with_no_drag</span><span class="delimiter">"</span></span>).sortable({
<span class="key">group</span>: <span class="string"><span class="delimiter">'</span><span class="content">no-drop</span><span class="delimiter">'</span></span>,
<span class="key">drag</span>: <span class="predefined-constant">false</span>
});</pre></div>
</div>
</div>
<div class='span4'>
<ul>
<li>
Drag the items by a
<strong>handle</strong>
</li>
<li>
Pure
<strong>drag/drop</strong>
container
</li>
<li>
<strong>Clone</strong>
items on drag
</li>
</ul>
<p><div class="btn btn-primary show-code" data-toggle="button"><i class="icon-chevron-down"></i> show me the code</div></p>
</div>
<div class='span4'>
<h3>I'm draggable and droppable</h3>
<ol class='simple_with_drop vertical'>
<li>
<i class='icon-move'></i>
Item 1
</li>
<li>
<i class='icon-move'></i>
Item 2
</li>
<li>
<i class='icon-move'></i>
Item 3
</li>
<li>
<i class='icon-move'></i>
Item 4
</li>
<li>
<i class='icon-move'></i>
Item 5
</li>
<li>
<i class='icon-move'></i>
Item 6
</li>
</ol>
</div>
<div class='span4'>
<h3>I'm only draggable</h3>
<ol class='simple_with_no_drop vertical'>
<li class='highlight'>
<i class='icon-move'></i>
Item 1
</li>
<li class='highlight'>
<i class='icon-move'></i>
Item 2
</li>
<li class='highlight'>
<i class='icon-move'></i>
Item 3
</li>
</ol>
<h3>I'm only droppable</h3>
<ol class='simple_with_no_drag vertical'>
<li>
<i class='icon-move'></i>
Item 1
</li>
<li>
<i class='icon-move'></i>
Item 2
</li>
<li>
<i class='icon-move'></i>
Item 3
</li>
</ol>
</div>
</div>
</div>
<div id='nested'>
<h2>Toggable nested lists</h2>
<div class='row'>
<div class="span12 example">
<div class="CodeRay">
<div class="code"><pre><span class="keyword">var</span> oldContainer;
<span class="predefined">$</span>(<span class="string"><span class="delimiter">"</span><span class="content">ol.nested_with_switch</span><span class="delimiter">"</span></span>).sortable({
<span class="key">group</span>: <span class="string"><span class="delimiter">'</span><span class="content">nested</span><span class="delimiter">'</span></span>,
<span class="function">afterMove</span>: <span class="keyword">function</span> (placeholder, container) {
<span class="keyword">if</span>(oldContainer != container){
<span class="keyword">if</span>(oldContainer)
oldContainer.el.removeClass(<span class="string"><span class="delimiter">"</span><span class="content">active</span><span class="delimiter">"</span></span>);
container.el.addClass(<span class="string"><span class="delimiter">"</span><span class="content">active</span><span class="delimiter">"</span></span>);
oldContainer = container;
}
},
<span class="function">onDrop</span>: <span class="keyword">function</span> (<span class="predefined">$item</span>, container, _super) {
container.el.removeClass(<span class="string"><span class="delimiter">"</span><span class="content">active</span><span class="delimiter">"</span></span>);
_super(<span class="predefined">$item</span>, container);
}
});
<span class="predefined">$</span>(<span class="string"><span class="delimiter">"</span><span class="content">.switch-container</span><span class="delimiter">"</span></span>).on(<span class="string"><span class="delimiter">"</span><span class="content">click</span><span class="delimiter">"</span></span>, <span class="string"><span class="delimiter">"</span><span class="content">.switch</span><span class="delimiter">"</span></span>, <span class="keyword">function</span> (e) {
<span class="keyword">var</span> method = <span class="predefined">$</span>(<span class="local-variable">this</span>).hasClass(<span class="string"><span class="delimiter">"</span><span class="content">active</span><span class="delimiter">"</span></span>) ? <span class="string"><span class="delimiter">"</span><span class="content">enable</span><span class="delimiter">"</span></span> : <span class="string"><span class="delimiter">"</span><span class="content">disable</span><span class="delimiter">"</span></span>;
<span class="predefined">$</span>(e.delegateTarget).next().sortable(method);
});</pre></div>
</div>
</div>
<div class='span4'>
<ul>
<li>
<strong>Nest lists</strong>
of arbitrary depth
</li>
<li>Highlight the current container</li>
<li>
<strong>Enable/disable</strong>
lists
</li>
</ul>
<p><div class="btn btn-primary show-code" data-toggle="button"><i class="icon-chevron-down"></i> show me the code</div></p>
</div>
<div class='span4'>
<div class='switch-container'>
<div class='switch active' data-off='OFF' data-on='ON' data-toggle='switch'></div>
</div>
<ol class='nested_with_switch vertical'>
<li>
Item 1
</li>
<li>
Item 2
</li>
<li>
Item 3
</li>
<li>
Item 4
<ol>
<li>Item 3.1</li>
<li>Item 3.2</li>
<li>Item 3.3</li>
<li>Item 3.4</li>
<li>Item 3.5</li>
<li>Item 3.6</li>
</ol>
</li>
<li>
Item 5
</li>
<li>
Item 6
</li>
</ol>
</div>
<div class='span4'>
<div class='switch-container'>
<div class='switch active' data-off='OFF' data-on='ON' data-toggle='switch'></div>
</div>
<ol class='nested_with_switch vertical'>
<li>
Item 1
</li>
<li>
Item 2
</li>
<li>
Item 3
</li>
<li>
Item 4
<ol>
<li>Item 3.1</li>
<li>Item 3.2</li>
<li>Item 3.3</li>
<li>Item 3.4</li>
<li>Item 3.5</li>
<li>Item 3.6</li>
</ol>
</li>
<li>
Item 5
</li>
<li>
Item 6
</li>
</ol>
</div>
</div>
</div>
<div id='limited-target'>
<h2>Connected lists with limited drop targets</h2>
<div class='row'>
<div class="span12 example">
<div class="CodeRay">
<div class="code"><pre><span class="keyword">var</span> group = <span class="predefined">$</span>(<span class="string"><span class="delimiter">"</span><span class="content">ol.limited_drop_targets</span><span class="delimiter">"</span></span>).sortable({
<span class="key">group</span>: <span class="string"><span class="delimiter">'</span><span class="content">limited_drop_targets</span><span class="delimiter">'</span></span>,
<span class="function">isValidTarget</span>: <span class="keyword">function</span> (<span class="predefined">$item</span>, container) {
<span class="keyword">if</span>(<span class="predefined">$item</span>.is(<span class="string"><span class="delimiter">"</span><span class="content">.highlight</span><span class="delimiter">"</span></span>))
<span class="keyword">return</span> <span class="predefined-constant">true</span>;
<span class="keyword">else</span>
<span class="keyword">return</span> <span class="predefined">$item</span>.parent(<span class="string"><span class="delimiter">"</span><span class="content">ol</span><span class="delimiter">"</span></span>)[<span class="integer">0</span>] == container.el[<span class="integer">0</span>];
},
<span class="function">onDrop</span>: <span class="keyword">function</span> (<span class="predefined">$item</span>, container, _super) {
<span class="predefined">$</span>(<span class="string"><span class="delimiter">'</span><span class="content">#serialize_output</span><span class="delimiter">'</span></span>).text(
group.sortable(<span class="string"><span class="delimiter">"</span><span class="content">serialize</span><span class="delimiter">"</span></span>).get().join(<span class="string"><span class="delimiter">"</span><span class="char">\n</span><span class="delimiter">"</span></span>));
_super(<span class="predefined">$item</span>, container);
},
<span class="function">serialize</span>: <span class="keyword">function</span> (parent, children, isContainer) {
<span class="keyword">return</span> isContainer ? children.join() : parent.text();
},
<span class="key">tolerance</span>: <span class="integer">6</span>,
<span class="key">distance</span>: <span class="integer">10</span>
});</pre></div>
</div>
</div>
<div class='span4'>
<ul>
<li>
<strong>Limit the drop targets</strong>
of the dragged item
</li>
<li>
Customize
<strong>serialization</strong>
of the lists
</li>
<li>
Decrease sort
<strong>sensitivity</strong>
</li>
<li>
Start dragging after a
<strong>distance</strong>
has been met
</li>
</ul>
<p><div class="btn btn-primary show-code" data-toggle="button"><i class="icon-chevron-down"></i> show me the code</div></p>
<h3>Serialize result</h3>
<pre id='serialize_output'></pre>
</div>
<div class='span4'>
<ol class='limited_drop_targets vertical'>
<li class='highlight'>Item 1</li>
<li>Item 2</li>
<li class='highlight'>Item 3</li>
<li>Item 4</li>
<li class='highlight'>Item 5</li>
<li>Item 6</li>
</ol>
</div>
<div class='span4'>
<ol class='limited_drop_targets vertical'>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
<li class='highlight'>Item 4</li>
<li class='highlight'>Item 5</li>
<li class='highlight'>Item 6</li>
</ol>
</div>
</div>
</div>
<div id='bootstrap'>
<h2>Sorting a bootstrap menu</h2>
<div class='row'>
<div class='span4'>
<ul>
<li>
Sort
<strong>vertically</strong>
</li>
<li>Define the nested containers differently</li>
<li>
<strong>Exclude</strong>
some items from being sortable
</li>
</ul>
<p>
<span class='label label-info'>Heads Up!</span>
The
<code>itemSelector</code>
should always match every sibling of any item.
If you want to exclude some items, use the
<code>exclude</code>
option.
<small>
See the first example
<a href='http://jqueryui.com/demos/sortable/#items'>here</a>
why this is a good idea.
</small>
</p>
</div>
<div class="span8">
<div class="CodeRay">
<div class="code"><pre><span class="predefined">$</span>(<span class="string"><span class="delimiter">"</span><span class="content">ol.nav</span><span class="delimiter">"</span></span>).sortable({
<span class="key">group</span>: <span class="string"><span class="delimiter">'</span><span class="content">nav</span><span class="delimiter">'</span></span>,
<span class="key">nested</span>: <span class="predefined-constant">false</span>,
<span class="key">vertical</span>: <span class="predefined-constant">false</span>,
<span class="key">exclude</span>: <span class="string"><span class="delimiter">'</span><span class="content">.divider-vertical</span><span class="delimiter">'</span></span>,
<span class="function">onDragStart</span>: <span class="keyword">function</span>(<span class="predefined">$item</span>, container, _super) {
<span class="predefined">$item</span>.find(<span class="string"><span class="delimiter">'</span><span class="content">ol.dropdown-menu</span><span class="delimiter">'</span></span>).sortable(<span class="string"><span class="delimiter">'</span><span class="content">disable</span><span class="delimiter">'</span></span>);
_super(<span class="predefined">$item</span>, container);
},
<span class="function">onDrop</span>: <span class="keyword">function</span>(<span class="predefined">$item</span>, container, _super) {
<span class="predefined">$item</span>.find(<span class="string"><span class="delimiter">'</span><span class="content">ol.dropdown-menu</span><span class="delimiter">'</span></span>).sortable(<span class="string"><span class="delimiter">'</span><span class="content">enable</span><span class="delimiter">'</span></span>);
_super(<span class="predefined">$item</span>, container);
}
});
<span class="predefined">$</span>(<span class="string"><span class="delimiter">"</span><span class="content">ol.dropdown-menu</span><span class="delimiter">"</span></span>).sortable({
<span class="key">group</span>: <span class="string"><span class="delimiter">'</span><span class="content">nav</span><span class="delimiter">'</span></span>
});</pre></div>
</div>
</div>
</div>
<div class='row'>
<div class='navbar-sort-container'>
<div class='navbar'>
<div class='navbar-inner'>
<div class='container'>
<ol class='nav pull-left'>
<li>
<a href='#'>Item 1</a>
</li>
<li>
<a href='#'>Item 2</a>
</li>
<li>
<a href='#'>Item 3</a>
</li>
<li class='divider-vertical'></li>
<li class='dropdown open'>
<a href='#'>Item 4</a>
<ol class='dropdown-menu'>
<li>
<a href='#'>Item 3.1</a>
</li>
<li>
<a href='#'>Item 3.2</a>
</li>
<li>
<a href='#'>Item 3.3</a>
</li>
<li>
<a href='#'>Item 3.4</a>
</li>
</ol>
</li>
<li>
<a href='#'>Item 5</a>
</li>
<li>
<a href='#'>Item 6</a>
</li>
</ol>
<ol class='nav pull-right'>
<li>
<a href='#'>Item 1</a>
</li>
<li>
<a href='#'>Item 2</a>
</li>
<li>
<a href='#'>Item 3</a>
</li>
<li class='divider-vertical'></li>
<li>
<a href='#'>Item 4</a>
</li>
<li>
<a href='#'>Item 5</a>
</li>
<li>
<a href='#'>Item 6</a>
</li>
</ol>
</div>
</div>
</div>
</div>
</div>
</div>
<div id='serialization'>
<h2>Serialization and delay</h2>
<div class='row'>
<div class="span12 example">
<div class="CodeRay">
<div class="code"><pre><span class="keyword">var</span> group = <span class="predefined">$</span>(<span class="string"><span class="delimiter">"</span><span class="content">ol.serialization</span><span class="delimiter">"</span></span>).sortable({
<span class="key">group</span>: <span class="string"><span class="delimiter">'</span><span class="content">serialization</span><span class="delimiter">'</span></span>,
<span class="key">delay</span>: <span class="integer">500</span>,
<span class="function">onDrop</span>: <span class="keyword">function</span> (<span class="predefined">$item</span>, container, _super) {
<span class="keyword">var</span> data = group.sortable(<span class="string"><span class="delimiter">"</span><span class="content">serialize</span><span class="delimiter">"</span></span>).get();
<span class="keyword">var</span> jsonString = JSON.stringify(data, <span class="predefined-constant">null</span>, <span class="string"><span class="delimiter">'</span><span class="content"> </span><span class="delimiter">'</span></span>);
<span class="predefined">$</span>(<span class="string"><span class="delimiter">'</span><span class="content">#serialize_output2</span><span class="delimiter">'</span></span>).text(jsonString);
_super(<span class="predefined">$item</span>, container);
}
});</pre></div>
</div>
</div>
<div class='span4'>
<ul>
<li>
Uses the default
<strong>serialize</strong>
implementation, that reads out the
<strong>data attributes</strong>
</li>
</ul>
<p><div class="btn btn-primary show-code" data-toggle="button"><i class="icon-chevron-down"></i> show me the code</div></p>
<h3>Serialize result</h3>
<pre id='serialize_output2'></pre>
</div>
<div class='span4'>
<ol class='serialization vertical'>
<li data-id='0' data-name='Item 1'>
Item 1
</li>
<li data-id='1' data-name='Item 2'>
Item 2
</li>
<li data-id='2' data-name='Item 3'>
Item 3
</li>
<li data-id='3' data-name='Item 4'>
Item 4
<ol>
<li data-id='3-0' data-name='Item 3.1'>Item 3.1</li>
<li data-id='3-1' data-name='Item 3.2'>Item 3.2</li>
<li data-id='3-2' data-name='Item 3.3'>Item 3.3</li>
<li data-id='3-3' data-name='Item 3.4'>Item 3.4</li>
<li data-id='3-4' data-name='Item 3.5'>Item 3.5</li>
<li data-id='3-5' data-name='Item 3.6'>Item 3.6</li>
</ol>
</li>
<li data-id='4' data-name='Item 5'>
Item 5
</li>
<li data-id='5' data-name='Item 6'>
Item 6
</li>
</ol>
</div>
<div class='span4'>
<ol class='serialization vertical'>
<li data-id='0' data-name='Item 1'>Item 1</li>
<li data-id='1' data-name='Item 2'>Item 2</li>
<li data-id='2' data-name='Item 3'>Item 3</li>
<li data-id='3' data-name='Item 4'>Item 4</li>
<li data-id='4' data-name='Item 5'>Item 5</li>
<li data-id='5' data-name='Item 6'>Item 6</li>
</ol>
</div>
</div>
</div>
<div id='table'>
<h2>
Sort tables
<small>(doesn't work well in Konqueror and IE)</small>
</h2>
<div class='row'>
<div class="span12 example">
<div class="CodeRay">
<div class="code"><pre><span class="comment">// Sortable rows</span>
<span class="predefined">$</span>(<span class="string"><span class="delimiter">'</span><span class="content">.sorted_table</span><span class="delimiter">'</span></span>).sortable({
<span class="key">containerSelector</span>: <span class="string"><span class="delimiter">'</span><span class="content">table</span><span class="delimiter">'</span></span>,
<span class="key">itemPath</span>: <span class="string"><span class="delimiter">'</span><span class="content">> tbody</span><span class="delimiter">'</span></span>,
<span class="key">itemSelector</span>: <span class="string"><span class="delimiter">'</span><span class="content">tr</span><span class="delimiter">'</span></span>,
<span class="key">placeholder</span>: <span class="string"><span class="delimiter">'</span><span class="content"><tr class="placeholder"/></span><span class="delimiter">'</span></span>
});
<span class="comment">// Sortable column heads</span>
<span class="keyword">var</span> oldIndex;
<span class="predefined">$</span>(<span class="string"><span class="delimiter">'</span><span class="content">.sorted_head tr</span><span class="delimiter">'</span></span>).sortable({
<span class="key">containerSelector</span>: <span class="string"><span class="delimiter">'</span><span class="content">tr</span><span class="delimiter">'</span></span>,
<span class="key">itemSelector</span>: <span class="string"><span class="delimiter">'</span><span class="content">th</span><span class="delimiter">'</span></span>,
<span class="key">placeholder</span>: <span class="string"><span class="delimiter">'</span><span class="content"><th class="placeholder"/></span><span class="delimiter">'</span></span>,
<span class="key">vertical</span>: <span class="predefined-constant">false</span>,
<span class="function">onDragStart</span>: <span class="keyword">function</span> (<span class="predefined">$item</span>, container, _super) {
oldIndex = <span class="predefined">$item</span>.index();
<span class="predefined">$item</span>.appendTo(<span class="predefined">$item</span>.parent());
_super(<span class="predefined">$item</span>, container);
},
<span class="function">onDrop</span>: <span class="keyword">function</span> (<span class="predefined">$item</span>, container, _super) {
<span class="keyword">var</span> field,
newIndex = <span class="predefined">$item</span>.index();
<span class="keyword">if</span>(newIndex != oldIndex) {
<span class="predefined">$item</span>.closest(<span class="string"><span class="delimiter">'</span><span class="content">table</span><span class="delimiter">'</span></span>).find(<span class="string"><span class="delimiter">'</span><span class="content">tbody tr</span><span class="delimiter">'</span></span>).each(<span class="keyword">function</span> (i, row) {
row = <span class="predefined">$</span>(row);
<span class="keyword">if</span>(newIndex < oldIndex) {
row.children().eq(newIndex).before(row.children()[oldIndex]);
} <span class="keyword">else</span> <span class="keyword">if</span> (newIndex > oldIndex) {
row.children().eq(newIndex).after(row.children()[oldIndex]);
}
});
}
_super(<span class="predefined">$item</span>, container);
}
});</pre></div>
</div>
</div>
<div class='span4'>
<ul>
<li>
Sort
<strong>tables</strong>
</li>
<li>
Specify custom
<code>placeholder</code>
</li>
<li>
Provide custom
<strong>callbacks,</strong>
to change the sorting behaviour
</li>
</ul>
<p><div class="btn btn-primary show-code" data-toggle="button"><i class="icon-chevron-down"></i> show me the code</div></p>
</div>
<div class='span4'>
<h3>Sortable Rows</h3>
<table class='table table-striped table-bordered sorted_table'>
<thead>
<tr>
<th>A Column</th>
<th>B Column</th>
</tr>
</thead>
<tbody>
<tr>
<td>A Item 1</td>
<td>B Item 1</td>
</tr>
<tr>
<td>A Item 2</td>
<td>B Item 2</td>
</tr>
<tr>
<td>A Item 3</td>
<td>B Item 3</td>
</tr>
<tr>
<td>A Item 4</td>
<td>B Item 4</td>
</tr>
<tr>
<td>A Item 5</td>
<td>B Item 5</td>
</tr>
<tr>
<td>A Item 6</td>
<td>B Item 6</td>
</tr>
</tbody>
</table>
</div>
<div class='span4'>
<h3>Sortable column heads</h3>
<table class='table table-striped table-bordered'>
<thead class='sorted_head'>
<tr>
<th>A Column</th>
<th>B Column</th>
<th>C Column</th>
</tr>
</thead>
<tbody>
<tr>
<td>A Item 1</td>
<td>B Item 1</td>
<td>C Item 1</td>
</tr>
<tr>
<td>A Item 2</td>
<td>B Item 2</td>
<td>C Item 2</td>
</tr>
<tr>
<td>A Item 3</td>
<td>B Item 3</td>
<td>C Item 3</td>
</tr>
<tr>
<td>A Item 4</td>
<td>B Item 4</td>
<td>C Item 4</td>
</tr>
<tr>
<td>A Item 5</td>
<td>B Item 5</td>
<td>C Item 5</td>
</tr>
<tr>
<td>A Item 6</td>
<td>B Item 6</td>
<td>C Item 6</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<div id='external'>
<h2>External examples</h2>
<ul>
<li>
<a href='http://www.catch.jp/program/soramame_block/'>SoraMame Block</a>
- program by drag and drop
</li>
</ul>
</div>
</div>
<div id='docs'>
<div class='page-header'>
<h1>Documentation</h1>
</div>