Skip to content

Commit ef63dfd

Browse files
authored
Next version (#1524)
1 parent b321482 commit ef63dfd

39 files changed

+21184
-2583
lines changed

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,3 @@ mock.png
44
.build*
55
jquery.fn.*
66
.idea/
7-
package-lock.json

.jshintrc

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
{
2-
"strict": true,
2+
"strict": false,
33
"newcap": false,
44
"node": true,
55
"expr": true,
66
"supernew": true,
77
"laxbreak": true,
8+
"esversion": 9,
89
"white": true,
910
"globals": {
1011
"define": true,

README.md

+77-65
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
# Sortable
1+
# Sortable   [![DeepScan grade](https://deepscan.io/api/teams/3901/projects/5666/branches/43977/badge/grade.svg)](https://deepscan.io/dashboard#view=project&tid=3901&pid=5666&bid=43977) [![](https://data.jsdelivr.com/v1/package/npm/sortablejs/badge)](https://www.jsdelivr.com/package/npm/sortablejs) [![npm](https://img.shields.io/npm/v/sortablejs.svg)](https://www.npmjs.com/package/sortablejs)
2+
23
Sortable is a JavaScript library for reorderable drag-and-drop lists.
34

45
Demo: http://sortablejs.github.io/Sortable/
@@ -13,6 +14,8 @@ Supported by [<img width="100px" src="https://user-images.githubusercontent.com/
1314
* Supports drag handles *and selectable text* (better than voidberg's html5sortable)
1415
* Smart auto-scrolling
1516
* Advanced swap detection
17+
* Smooth animations
18+
* [Multi-drag](https://github.com/SortableJS/Sortable/wiki/Dragging-Multiple-Items-in-Sortable) support
1619
* Built using native HTML5 drag and drop API
1720
* Supports
1821
* [Meteor](https://github.com/SortableJS/meteor-sortablejs)
@@ -37,27 +40,54 @@ Supported by [<img width="100px" src="https://user-images.githubusercontent.com/
3740

3841
### Articles
3942

43+
* [Dragging Multiple Items in Sortable](https://github.com/SortableJS/Sortable/wiki/Dragging-Multiple-Items-in-Sortable) (April 26, 2019)
4044
* [Swap Thresholds and Direction](https://github.com/SortableJS/Sortable/wiki/Swap-Thresholds-and-Direction) (December 2, 2018)
4145
* [Sortable v1.0 — New capabilities](https://github.com/SortableJS/Sortable/wiki/Sortable-v1.0-—-New-capabilities/) (December 22, 2014)
4246
* [Sorting with the help of HTML5 Drag'n'Drop API](https://github.com/SortableJS/Sortable/wiki/Sorting-with-the-help-of-HTML5-Drag'n'Drop-API/) (December 23, 2013)
4347

4448
<br/>
4549

46-
### Install
47-
48-
Via npm
50+
### Getting Started
4951

52+
Install with NPM:
5053
```bash
5154
$ npm install sortablejs --save
5255
```
5356

54-
Via bower:
55-
57+
Install with Bower:
5658
```bash
5759
$ bower install --save sortablejs
5860
```
5961

60-
<br/>
62+
Import into your project:
63+
```js
64+
// Default SortableJS
65+
import Sortable from 'sortablejs';
66+
67+
// Core SortableJS (without default plugins)
68+
import Sortable from 'sortablejs/modular/sortable.core.esm.js';
69+
70+
// Complete SortableJS (with all plugins)
71+
import Sortable from 'sortablejs/modular/sortable.complete.esm.js';
72+
```
73+
74+
Cherrypick plugins:
75+
```js
76+
// Cherrypick extra plugins
77+
import Sortable, { MultiDrag, Swap } from 'sortablejs';
78+
79+
Sortable.mount(MultiDrag, Swap);
80+
81+
82+
// Cherrypick default plugins
83+
import Sortable, { AutoScroll } from 'sortablejs/modular/sortable.core.esm.js';
84+
85+
Sortable.mount(AutoScroll);
86+
```
87+
88+
89+
---
90+
6191

6292
### Usage
6393
```html
@@ -95,10 +125,12 @@ var sortable = new Sortable(el, {
95125
filter: ".ignore-elements", // Selectors that do not lead to dragging (String or Function)
96126
preventOnFilter: true, // Call `event.preventDefault()` when triggered `filter`
97127
draggable: ".item", // Specifies which items inside the element should be draggable
128+
129+
dataIdAttr: 'data-id',
130+
98131
ghostClass: "sortable-ghost", // Class name for the drop placeholder
99132
chosenClass: "sortable-chosen", // Class name for the chosen item
100133
dragClass: "sortable-drag", // Class name for the dragging item
101-
dataIdAttr: 'data-id',
102134

103135
swapThreshold: 1, // Threshold of the swap zone
104136
invertSwap: false, // Will always use inverted swap zone if set to true
@@ -111,12 +143,6 @@ var sortable = new Sortable(el, {
111143
fallbackOnBody: false, // Appends the cloned DOM Element into the Document's Body
112144
fallbackTolerance: 0, // Specify in pixels how far the mouse should move before it's considered as a drag.
113145

114-
scroll: true, // or HTMLElement
115-
scrollFn: function(offsetX, offsetY, originalEvent, touchEvt, hoverTargetEl) { ... }, // if you have custom scrollbar scrollFn may be used for autoscrolling
116-
scrollSensitivity: 30, // px, how near the mouse must be to an edge to start scrolling.
117-
scrollSpeed: 10, // px
118-
bubbleScroll: true, // apply autoscroll to all parent elements, allowing for easier movement
119-
120146
dragoverBubble: false,
121147
removeCloneOnHide: true, // Remove the clone element when it is not showing, rather than just hiding it
122148
emptyInsertThreshold: 5, // px, distance mouse must be from empty sortable to insert drag element into it
@@ -231,7 +257,7 @@ Demo:
231257

232258

233259
#### `sort` option
234-
Sorting inside list.
260+
Allow sorting inside list.
235261

236262
Demo: https://jsbin.com/jayedig/edit?js,output
237263

@@ -257,9 +283,9 @@ Whether or not the delay should be applied only if the user is using touch (eg.
257283

258284

259285
#### `swapThreshold` option
260-
Percentage of the target that the swap zone will take up, as a float between `0` and `1`.
286+
Percentage of the target that the swap zone will take up, as a float between `0` and `1`. This option has nothing to do with the `swap` option.
261287

262-
Read more: https://github.com/SortableJS/Sortable/wiki/Swap-Thresholds-and-Direction#swap-threshold
288+
[Read more](https://github.com/SortableJS/Sortable/wiki/Swap-Thresholds-and-Direction#swap-threshold)
263289

264290
Demo: http://sortablejs.github.io/Sortable#thresholds
265291

@@ -268,9 +294,9 @@ Demo: http://sortablejs.github.io/Sortable#thresholds
268294

269295

270296
#### `invertSwap` option
271-
Set to `true` to set the swap zone to the sides of the target, for the effect of sorting "in between" items.
297+
Set to `true` to set the swap zone to the sides of the target, for the effect of sorting "in between" items. This option has nothing to do with the `swap` option.
272298

273-
Read more: https://github.com/SortableJS/Sortable/wiki/Swap-Thresholds-and-Direction#forcing-inverted-swap-zone
299+
[Read more](https://github.com/SortableJS/Sortable/wiki/Swap-Thresholds-and-Direction#forcing-inverted-swap-zone)
274300

275301
Demo: http://sortablejs.github.io/Sortable#thresholds
276302

@@ -279,9 +305,9 @@ Demo: http://sortablejs.github.io/Sortable#thresholds
279305

280306

281307
#### `invertedSwapThreshold` option
282-
Percentage of the target that the inverted swap zone will take up, as a float between `0` and `1`. If not given, will default to `swapThreshold`.
308+
Percentage of the target that the inverted swap zone will take up, as a float between `0` and `1`. If not given, will default to `swapThreshold`. This option has nothing to do with the `swap` option.
283309

284-
Read more: https://github.com/SortableJS/Sortable/wiki/Swap-Thresholds-and-Direction#dealing-with-swap-glitching
310+
[Read more](https://github.com/SortableJS/Sortable/wiki/Swap-Thresholds-and-Direction#dealing-with-swap-glitching)
285311

286312

287313
---
@@ -290,7 +316,7 @@ Read more: https://github.com/SortableJS/Sortable/wiki/Swap-Thresholds-and-Direc
290316
#### `direction` option
291317
Direction that the Sortable should sort in. Can be set to `'vertical'`, `'horizontal'`, or a function, which will be called whenever a target is dragged over. Must return `'vertical'` or `'horizontal'`.
292318

293-
Read more: https://github.com/SortableJS/Sortable/wiki/Swap-Thresholds-and-Direction#direction
319+
[Read more](https://github.com/SortableJS/Sortable/wiki/Swap-Thresholds-and-Direction#direction)
294320

295321

296322
Example of direction detection for vertical list that includes full column and half column elements:
@@ -467,48 +493,6 @@ Dragging only starts if you move the pointer past a certain tolerance, so that y
467493
---
468494

469495

470-
#### `scroll` option
471-
If set to `true`, the page (or sortable-area) scrolls when coming to an edge.
472-
473-
Demo:
474-
- `window`: https://jsbin.com/dosilir/edit?js,output
475-
- `overflow: hidden`: https://jsbin.com/xecihez/edit?html,js,output
476-
477-
478-
---
479-
480-
481-
#### `scrollFn` option
482-
Defines function that will be used for autoscrolling. el.scrollTop/el.scrollLeft is used by default.
483-
Useful when you have custom scrollbar with dedicated scroll function.
484-
485-
486-
---
487-
488-
489-
#### `scrollSensitivity` option
490-
Defines how near the mouse must be to an edge to start scrolling.
491-
492-
493-
---
494-
495-
496-
#### `scrollSpeed` option
497-
The speed at which the window should scroll once the mouse pointer gets within the `scrollSensitivity` distance.
498-
499-
500-
---
501-
502-
503-
#### `bubbleScroll` option
504-
If set to `true`, the normal `autoscroll` function will also be applied to all parent elements of the element the user is dragging over.
505-
506-
Demo: https://jsbin.com/kesewor/edit?html,js,output
507-
508-
509-
---
510-
511-
512496
#### `dragoverBubble` option
513497
If set to `true`, the dragover event will bubble to parent sortables. Works on both fallback and native dragover event.
514498
By default, it is false, but Sortable will only stop bubbling the event once the element has been inserted into a parent Sortable, or *can* be inserted into a parent Sortable, but isn't at that specific time (due to animation, etc).
@@ -682,7 +666,35 @@ Create new instance.
682666

683667

684668
##### Sortable.active:`Sortable`
685-
Link to the active instance.
669+
The active Sortable instance.
670+
671+
672+
---
673+
674+
675+
##### Sortable.dragged:`HTMLElement`
676+
The element being dragged.
677+
678+
679+
---
680+
681+
682+
##### Sortable.ghost:`HTMLElement`
683+
The ghost element.
684+
685+
686+
---
687+
688+
689+
##### Sortable.clone:`HTMLElement`
690+
The clone element.
691+
692+
693+
---
694+
695+
696+
##### Sortable.mount(plugin:`...SortablePlugin|...SortablePlugin[]`)
697+
Mounts a plugin to Sortable.
686698

687699

688700
---

0 commit comments

Comments
 (0)