aboutsummaryrefslogtreecommitdiffstats
path: root/library/Sortable/index.html
blob: 35264911d354f5b206bee55cab8de4d71d16d54c (plain) (blame)
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
<!DOCTYPE html>
<html>
<head>
	<link rel="icon" type="image/png" href="st/og-image.png">
	<title>SortableJS</title>
	<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS" crossorigin="anonymous">
	<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.3/css/all.css" integrity="sha384-UHRtZLI+pbxtHCWp1t77Bi1L4ZtiqrqD80Kn4Z8NTSRyMA2Fd33n5dQ8lWUE00s/" crossorigin="anonymous">
	<link rel="stylesheet" type="text/css" href="st/theme.css">

	<meta charset="utf-8"/>
	<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
	<meta property="og:image" content="/st/og-image.png"/>
	<meta name="keywords" content="sortable, reorder, list, javascript, html5, drag and drop, dnd, animation, groups, dnd, sortableJS"/>
	<meta name="description" content="Sortable — is a JavaScript library for reorderable drag-and-drop lists on modern browsers and touch devices. No jQuery required. Supports Meteor, AngularJS, React, Polymer, Vue, Knockout and any CSS library, e.g. Bootstrap."/>
	<meta name="viewport" content="width=device-width, initial-scale=0.5"/>
</head>
<body>

	<a href="https://github.com/SortableJS/Sortable"><img style="position: fixed; top: 0; right: 0; border: 0; z-index:99999" src="https://s3.amazonaws.com/github/ribbons/forkme_right_gray_6d6d6d.png" alt="Fork me on GitHub"></a>

	<div class="container">
		<div class="text-center row header">
			<img class="mx-auto d-block" src="st/og-image.png" style="max-width: 200px; max-height: 200px" />
			<h1 class="col-12">SortableJS</h1>
			<h3 class="col-12 text-center">JavaScript library for reorderable drag-and-drop lists</h3>

			<div class="toc col-12 col-md-5 mt-3">
				<h5>Features</h5>
				<li><a href="#simple-list">Simple list</a></li>
				<li><a href="#shared-lists">Shared lists</a></li>
				<li><a href="#cloning">Cloning</a></li>
				<li><a href="#sorting-disabled">Disabling sorting</a></li>
				<li><a href="#handle">Handles</a></li>
				<li><a href="#filter">Filter</a></li>
				<li><a href="#thresholds">Thresholds</a></li>
				<h5>Examples</h5>
				<li><a href="#grid">Grid</a></li>
				<li><a href="#nested">Nested sortables</a></li>
				<h5>Plugins</h5>
				<li><a href="#multi-drag">MultiDrag</a></li>
				<li><a href="#swap">Swap</a></li>
				<h5><a href="#comparisons">Comparisons</a></h5>
				<h5><a href="#frameworks">Framework Support</a></h5>
			</div>
		</div>

		<div class="row">
			<h2 class="col-12">Features</h2>
		</div>
		<hr />
		<div id="simple-list" class="row">
			<h4 class="col-12">Simple list example</h4>
			<div id="example1" class="list-group col">
				<div class="list-group-item">Item 1</div>
				<div class="list-group-item">Item 2</div>
				<div class="list-group-item">Item 3</div>
				<div class="list-group-item">Item 4</div>
				<div class="list-group-item">Item 5</div>
				<div class="list-group-item">Item 6</div>
			</div>
			<div style="padding: 0" class="col-12">
<pre class="prettyprint">new Sortable(example1, {
    animation: 150,
    ghostClass: 'blue-background-class'
});</pre>
			</div>
		</div>
		<hr />

		<div id="shared-lists" class="row">
			<h4 class="col-12">Shared lists</h4>
			<div id="example2-left" class="list-group col">
				<div class="list-group-item">Item 1</div>
				<div class="list-group-item">Item 2</div>
				<div class="list-group-item">Item 3</div>
				<div class="list-group-item">Item 4</div>
				<div class="list-group-item">Item 5</div>
				<div class="list-group-item">Item 6</div>
			</div>

			<div id="example2-right" class="list-group col">
				<div class="list-group-item tinted">Item 1</div>
				<div class="list-group-item tinted">Item 2</div>
				<div class="list-group-item tinted">Item 3</div>
				<div class="list-group-item tinted">Item 4</div>
				<div class="list-group-item tinted">Item 5</div>
				<div class="list-group-item tinted">Item 6</div>
			</div>
			<div style="padding: 0" class="col-12">
<pre class="prettyprint">new Sortable(example2Left, {
    group: 'shared', // set both lists to same group
    animation: 150
});

new Sortable(example2Right, {
    group: 'shared',
    animation: 150
});</pre>
			</div>
		</div>
		<hr />

		<div id="cloning" class="row">
			<h4 class="col-12">Cloning</h4>
			<p class="col-12">Try dragging from one list to another. The item you drag will be cloned and the clone will stay in the original list.</p>
			<div id="example3-left" class="list-group col">
				<div class="list-group-item">Item 1</div>
				<div class="list-group-item">Item 2</div>
				<div class="list-group-item">Item 3</div>
				<div class="list-group-item">Item 4</div>
				<div class="list-group-item">Item 5</div>
				<div class="list-group-item">Item 6</div>
			</div>

			<div id="example3-right" class="list-group col">
				<div class="list-group-item tinted">Item 1</div>
				<div class="list-group-item tinted">Item 2</div>
				<div class="list-group-item tinted">Item 3</div>
				<div class="list-group-item tinted">Item 4</div>
				<div class="list-group-item tinted">Item 5</div>
				<div class="list-group-item tinted">Item 6</div>
			</div>
			<div style="padding: 0" class="col-12">
<pre class="prettyprint">new Sortable(example3Left, {
    group: {
        name: 'shared',
        pull: 'clone' // To clone: set pull to 'clone'
    },
    animation: 150
});

new Sortable(example3Right, {
    group: {
        name: 'shared',
        pull: 'clone'
    },
    animation: 150
});</pre>
			</div>
		</div>
		<hr />

		<div id="sorting-disabled" class="row">
			<h4 class="col-12">Disabling Sorting</h4>
			<p class="col-12">Try sorting the list on the left. It is not possible because it has it's <code>sort</code> option set to false. However, you can still drag from the list on the left to the list on the right.</p>
			<div id="example4-left" class="list-group col">
				<div class="list-group-item">Item 1</div>
				<div class="list-group-item">Item 2</div>
				<div class="list-group-item">Item 3</div>
				<div class="list-group-item">Item 4</div>
				<div class="list-group-item">Item 5</div>
				<div class="list-group-item">Item 6</div>
			</div>

			<div id="example4-right" class="list-group col">
				<div class="list-group-item tinted">Item 1</div>
				<div class="list-group-item tinted">Item 2</div>
				<div class="list-group-item tinted">Item 3</div>
				<div class="list-group-item tinted">Item 4</div>
				<div class="list-group-item tinted">Item 5</div>
				<div class="list-group-item tinted">Item 6</div>
			</div>
			<div style="padding: 0" class="col-12">
<pre class="prettyprint">new Sortable(example4Left, {
    group: {
        name: 'shared',
        pull: 'clone',
        put: false // Do not allow items to be put into this list
    },
    animation: 150,
    sort: false // To disable sorting: set sort to false
});

new Sortable(example4Right, {
    group: 'shared',
    animation: 150
});</pre>
			</div>
		</div>
		<hr />

		<div id="handle" class="row">
			<h4 class="col-12">Handle</h4>
			<div id="example5" class="list-group col">
				<div class="list-group-item"><i class="fas fa-arrows-alt handle"></i>&nbsp;&nbsp;Item 1</div>
				<div class="list-group-item"><i class="fas fa-arrows-alt handle"></i>&nbsp;&nbsp;Item 2</div>
				<div class="list-group-item"><i class="fas fa-arrows-alt handle"></i>&nbsp;&nbsp;Item 3</div>
				<div class="list-group-item"><i class="fas fa-arrows-alt handle"></i>&nbsp;&nbsp;Item 4</div>
				<div class="list-group-item"><i class="fas fa-arrows-alt handle"></i>&nbsp;&nbsp;Item 5</div>
				<div class="list-group-item"><i class="fas fa-arrows-alt handle"></i>&nbsp;&nbsp;Item 6</div>
			</div>
			<div style="padding: 0" class="col-12">
<pre class="prettyprint">new Sortable(example5, {
    handle: '.handle', // handle's class
    animation: 150
});</pre>
			</div>
		</div>
		<hr />

		<div id="filter" class="row">
			<h4 class="col-12">Filter</h4>
			<p class="col-12">Try dragging the item with a red background. It cannot be done, because that item is filtered out using the <code>filter</code> option.</p>
			<div id="example6" class="list-group col">
				<div class="list-group-item">Item 1</div>
				<div class="list-group-item">Item 2</div>
				<div class="list-group-item">Item 3</div>
				<div class="list-group-item bg-danger filtered">Filtered</div>
				<div class="list-group-item">Item 4</div>
				<div class="list-group-item">Item 5</div>
			</div>
			<div style="padding: 0" class="col-12">
<pre class="prettyprint">new Sortable(example6, {
    filter: '.filtered', // 'filtered' class is not draggable
    animation: 150
});</pre>
			</div>
		</div>
		<hr />

		<div id="thresholds" class="row">
			<h4 class="col-12">Thresholds</h4>
			<p class="col-12">Try modifying the inputs below to affect the swap thresholds. You can see the swap zones of the squares colored in dark blue, while the "dead zones" (that do not cause a swap) are colored in light blue.</p>
			<div id="example7" class="square-section col">
				<div class="square">
					<div style="display: none;" class="inverted-swap-threshold-indicator indicator-left"></div>
					<div class="swap-threshold-indicator"></div>
					<div style="display: none;" class="inverted-swap-threshold-indicator indicator-right"></div>
					<div class="num-indicator">1</div>
				</div><!--
			 --><div class="square">
					<div style="display: none;" class="inverted-swap-threshold-indicator indicator-left"></div>
					<div class="swap-threshold-indicator"></div>
					<div style="display: none;" class="inverted-swap-threshold-indicator indicator-right"></div>
					<div class="num-indicator">2</div>
				</div>
			</div>
			<div class="col-12 input-section">
				<form>
					<div class="form-group row">
						<label class="col-sm-2 col-form-label" for="example7SwapThresholdInput">Swap Threshold</label>
						<div class="col-sm-8 col-form-label">
							<input min="0" max="1" value="1" step="0.01" type="range" class="form-control-range" id="example7SwapThresholdInput">
						</div>
					</div>
					<div class="form-group row">
						<div class="col-sm-2">Invert Swap</div>
						<div class="col-sm-10">
							<div class="form-check">
								<input class="form-check-input" type="checkbox" id="example7InvertSwapInput">
							</div>
						</div>
					</div>
					<div class="form-group row">
						<label class="col-sm-2 col-form-label" for="example7DirectionInput">Direction</label>
						<select class="col-sm-4 form-control" id="example7DirectionInput">
							<option value="h" selected>Horizontal</option>
							<option value="v">Vertical</option>
						</select>
					</div>
				</form>
			</div>
			<div style="padding: 0" class="col-12">
<pre class="prettyprint">new Sortable(example7, {
    swapThreshold: <span id="example7SwapThresholdCode">1</span>,<span id="example7InvertSwapCode" style="display: none">
    invertSwap: true,</span>
    animation: 150
});</pre>
			</div>
		</div>


		<div class="row">
			<h2 class="col-12">Examples</h2>
		</div>
		<hr />

		<div id="grid" class="row">
			<h4 class="col-12">Grid Example</h4>
			<div id="gridDemo" class="col">
				<div class="grid-square">Item 1</div><!--
			 --><div class="grid-square">Item 2</div><!--
			 --><div class="grid-square">Item 3</div><!--
			 --><div class="grid-square">Item 4</div><!--
			 --><div class="grid-square">Item 5</div><!--
			 --><div class="grid-square">Item 6</div><!--
			 --><div class="grid-square">Item 7</div><!--
			 --><div class="grid-square">Item 8</div><!--
			 --><div class="grid-square">Item 9</div><!--
			 --><div class="grid-square">Item 10</div><!--
			 --><div class="grid-square">Item 11</div><!--
			 --><div class="grid-square">Item 12</div><!--
			 --><div class="grid-square">Item 13</div><!--
			 --><div class="grid-square">Item 14</div><!--
			 --><div class="grid-square">Item 15</div><!--
			 --><div class="grid-square">Item 16</div><!--
			 --><div class="grid-square">Item 17</div><!--
			 --><div class="grid-square">Item 18</div><!--
			 --><div class="grid-square">Item 19</div><!--
			 --><div class="grid-square">Item 20</div>
			</div>
		</div>
		<hr />

		<div id="nested" class="row">
			<h4 class="col-12">Nested Sortables Example</h4>
			<p class="col-12">NOTE: When using nested Sortables with animation, it is recommended that the <code>fallbackOnBody</code> option is set to true. <br />It is also always recommended that either the <code>invertSwap</code> option is set to true, or the <code>swapThreshold</code> option is lower than the default value of 1 (eg <code>0.65</code>).</p>
			<div id="nestedDemo" class="list-group col nested-sortable">
				<div class="list-group-item nested-1">Item 1.1
					<div class="list-group nested-sortable">
						<div class="list-group-item nested-2">Item 2.1</div>
						<div class="list-group-item nested-2">Item 2.2
							<div class="list-group nested-sortable">
								<div class="list-group-item nested-3">Item 3.1</div>
								<div class="list-group-item nested-3">Item 3.2</div>
								<div class="list-group-item nested-3">Item 3.3</div>
								<div class="list-group-item nested-3">Item 3.4</div>
							</div>
						</div>
						<div class="list-group-item nested-2">Item 2.3</div>
						<div class="list-group-item nested-2">Item 2.4</div>
					</div>
				</div>
				<div class="list-group-item nested-1">Item 1.2</div>
				<div class="list-group-item nested-1">Item 1.3</div>
				<div class="list-group-item nested-1">Item 1.4
					<div class="list-group nested-sortable">
						<div class="list-group-item nested-2">Item 2.1</div>
						<div class="list-group-item nested-2">Item 2.2</div>
						<div class="list-group-item nested-2">Item 2.3</div>
						<div class="list-group-item nested-2">Item 2.4</div>
					</div>
				</div>
				<div class="list-group-item nested-1">Item 1.5</div>
			</div>
			<div style="padding: 0" class="col-12">
<pre class="prettyprint">// Loop through each nested sortable element
for (var i = 0; i < nestedSortables.length; i++) {
	new Sortable(nestedSortables[i], {
		group: 'nested',
		animation: 150,
		fallbackOnBody: true,
		swapThreshold: 0.65
	});
}</pre>
			</div>
		</div>

		<div class="row">
			<h2 class="col-12">Plugins</h2>
		</div>
		<hr />

		<div id="multi-drag" class="row">
			<h4 class="col-12">MultiDrag</h4>
			<p class="col-12">The <a target="_blank" href="https://github.com/SortableJS/Sortable/tree/master/plugins/MultiDrag">MultiDrag</a> plugin allows for multiple items to be dragged at a time. You can click to "select" multiple items, and then drag them as one item.</p>
			<div id="multiDragDemo" class="list-group col">
				<div class="list-group-item">Item 1</div>
				<div class="list-group-item">Item 2</div>
				<div class="list-group-item">Item 3</div>
				<div class="list-group-item">Item 4</div>
				<div class="list-group-item">Item 5</div>
				<div class="list-group-item">Item 6</div>
			</div>
			<div style="padding: 0" class="col-12">
<pre class="prettyprint">new Sortable(multiDragDemo, {
	multiDrag: true,
	selectedClass: 'selected',
	fallbackTolerance: 3, // So that we can select items on mobile
	animation: 150
});</pre>
			</div>
		</div>
		<hr />

		<div id="swap" class="row">
			<h4 class="col-12">Swap</h4>
			<p class="col-12">The <a target="_blank" href="https://github.com/SortableJS/Sortable/tree/master/plugins/Swap">Swap</a> plugin changes the behaviour of Sortable to allow for items to be swapped with eachother rather than sorted.</p>
			<div id="swapDemo" class="list-group col">
				<div class="list-group-item">Item 1</div>
				<div class="list-group-item">Item 2</div>
				<div class="list-group-item">Item 3</div>
				<div class="list-group-item">Item 4</div>
				<div class="list-group-item">Item 5</div>
				<div class="list-group-item">Item 6</div>
			</div>
			<div style="padding: 0" class="col-12">
<pre class="prettyprint">new Sortable(swapDemo, {
	swap: true, // Enable swap plugin
	swapClass: 'highlight', // The class applied to the hovered swap item
	animation: 150
});</pre>
			</div>
		</div>
		<hr />



		<div class="mt-4"></div>

		<div id="comparisons" class="row">
			<h2 class="col-12">Comparisons</h2>
		</div>
		<hr />


		<div class="row frameworks">
			<h2 class="col-12 text-center">jQuery-UI</h2>
			<iframe class="mx-auto" src="https://player.vimeo.com/video/311581236?title=0&byline=0&portrait=0" width="640" height="361" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>

			<h2 class="col-12 text-center mt-5">Dragula</h2>
			<iframe class="mx-auto" src="https://player.vimeo.com/video/311584137?title=0&byline=0&portrait=0" width="640" height="361" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
		</div>

		<div class="mt-4"></div>

		<div id="frameworks" class="row">
			<h2 class="col-12">Framework Support</h2>
		</div>
		<hr />

		<div class="row frameworks">

			<h3 class="col-6">Vue</h3>
			<h3 class="col-6"><a target="_blank" href="https://github.com/SortableJS/Vue.Draggable">Vue.Draggable</a></h3>

			<h3 class="col-6">React</h3>
			<h3 class="col-6"><a target="_blank" href="https://github.com/SortableJS/react-sortablejs">react-sortablejs</a></h3>

			<h3 class="col-6">Angular</h3>
			<h3 class="col-6"><a target="_blank" href="https://github.com/SortableJS/ngx-sortablejs">ngx-sortablejs</a></h3>

			<h3 class="col-6">jQuery</h3>
			<h3 class="col-6"><a target="_blank" href="https://github.com/SortableJS/jquery-sortablejs">jquery-sortablejs</a></h3>

			<h3 class="col-6">Knockout</h3>
			<h3 class="col-6"><a target="_blank" href="https://github.com/SortableJS/knockout-sortablejs">knockout-sortablejs</a></h3>

			<h3 class="col-6">Meteor</h3>
			<h3 class="col-6"><a target="_blank" href="https://github.com/SortableJS/meteor-sortablejs">meteor-sortablejs</a></h3>

			<h3 class="col-6">Polymer</h3>
			<h3 class="col-6"><a target="_blank" href="https://github.com/SortableJS/polymer-sortablejs">polymer-sortablejs</a></h3>

			<h3 class="col-6">Ember</h3>
			<h3 class="col-6"><a target="_blank" href="https://github.com/SortableJS/ember-sortablejs">ember-sortablejs</a></h3>
		</div>

	</div>


	<!-- Latest Sortable -->
	<script src="./Sortable.js"></script>

	<script type="text/javascript" src="st/prettify/prettify.js"></script>
	<script type="text/javascript" src="st/prettify/run_prettify.js"></script>

	<script src="st/app.js"></script>
</body>
</html>