Skip to content

Commit 629872b

Browse files
authored
1.8.0
1 parent b7473ac commit 629872b

21 files changed

+1590
-1030
lines changed

README.md

+56-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Sortable
2-
Sortable is a <s>minimalist</s> JavaScript library for reorderable drag-and-drop lists.
2+
Sortable is a JavaScript library for reorderable drag-and-drop lists.
33

44
Demo: http://sortablejs.github.io/Sortable/
55

@@ -11,6 +11,7 @@ Demo: http://sortablejs.github.io/Sortable/
1111
* CSS animation when moving items
1212
* Supports drag handles *and selectable text* (better than voidberg's html5sortable)
1313
* Smart auto-scrolling
14+
* Advanced swap detection
1415
* Built using native HTML5 drag and drop API
1516
* Supports
1617
* [Meteor](https://github.com/SortableJS/meteor-sortablejs)
@@ -86,6 +87,7 @@ var sortable = new Sortable(el, {
8687
disabled: false, // Disables the sortable if set to true.
8788
store: null, // @see Store
8889
animation: 150, // ms, animation speed moving items when sorting, `0` — without animation
90+
easing: "cubic-bezier(1, 0, 0, 1)", // Easing for animation. Defaults to null. See https://easings.net/ for examples.
8991
handle: ".my-handle", // Drag handle selector within list items
9092
filter: ".ignore-elements", // Selectors that do not lead to dragging (String or Function)
9193
preventOnFilter: true, // Call `event.preventDefault()` when triggered `filter`
@@ -113,6 +115,9 @@ var sortable = new Sortable(el, {
113115
bubbleScroll: true, // apply autoscroll to all parent elements, allowing for easier movement
114116

115117
dragoverBubble: false,
118+
removeCloneOnHide: true, // Remove the clone element when it is not showing, rather than just hiding it
119+
emptyInsertThreshold: 5, // px, distance mouse must be from empty sortable to insert drag element into it
120+
116121

117122
setData: function (/** DataTransfer */dataTransfer, /** HTMLElement*/dragEl) {
118123
dataTransfer.setData('Text', dragEl.textContent); // `dataTransfer` object of HTML5 DragEvent
@@ -123,6 +128,11 @@ var sortable = new Sortable(el, {
123128
evt.oldIndex; // element index within parent
124129
},
125130

131+
// Element is unchosen
132+
onUnchoose: function(/**Event*/evt) {
133+
// same properties as onEnd
134+
},
135+
126136
// Element dragging started
127137
onStart: function (/**Event*/evt) {
128138
evt.oldIndex; // element index within parent
@@ -166,17 +176,26 @@ var sortable = new Sortable(el, {
166176
onMove: function (/**Event*/evt, /**Event*/originalEvent) {
167177
// Example: https://jsbin.com/nawahef/edit?js,output
168178
evt.dragged; // dragged HTMLElement
169-
evt.draggedRect; // TextRectangle {left, top, right и bottom}
179+
evt.draggedRect; // DOMRect {left, top, right, bottom}
170180
evt.related; // HTMLElement on which have guided
171-
evt.relatedRect; // TextRectangle
181+
evt.relatedRect; // DOMRect
182+
evt.willInsertAfter; // Boolean that is true if Sortable will insert drag element after target by default
172183
originalEvent.clientY; // mouse position
173184
// return false; — for cancel
185+
// return -1; — insert before target
186+
// return 1; — insert after target
174187
},
175188

176189
// Called when creating a clone of element
177190
onClone: function (/**Event*/evt) {
178191
var origEl = evt.item;
179192
var cloneEl = evt.clone;
193+
},
194+
195+
// Called when dragging element changes position
196+
onChange: function(/**Event*/evt) {
197+
evt.newIndex // most likely why this event is used is to get the dragging element's current index
198+
// same properties as onEnd
180199
}
181200
});
182201
```
@@ -191,7 +210,7 @@ You can also define whether lists can give away, give and keep a copy (`clone`),
191210

192211
* name: `String` — group name
193212
* pull: `true|false|["foo", "bar"]|'clone'|function` — ability to move from the list. `clone` — copy the item, rather than move. Or an array of group names which the elements may be put in. Defaults to `true`.
194-
* put: `true|false|["baz", "qux"]|function` — whether elements can be added from other lists, or an array of group names from which elements can be taken.
213+
* put: `true|false|["baz", "qux"]|function` — whether elements can be added from other lists, or an array of group names from which elements can be added.
195214
* revertClone: `boolean` — revert cloned element to initial position after moving to a another list.
196215

197216

@@ -227,6 +246,8 @@ Percentage of the target that the swap zone will take up, as a float between `0`
227246

228247
Read more: https://github.com/SortableJS/Sortable/wiki/Swap-Thresholds-and-Direction#swap-threshold
229248

249+
Demo: http://sortablejs.github.io/Sortable#thresholds
250+
230251

231252
---
232253

@@ -236,6 +257,8 @@ Set to `true` to set the swap zone to the sides of the target, for the effect of
236257

237258
Read more: https://github.com/SortableJS/Sortable/wiki/Swap-Thresholds-and-Direction#forcing-inverted-swap-zone
238259

260+
Demo: http://sortablejs.github.io/Sortable#thresholds
261+
239262

240263
---
241264

@@ -255,12 +278,15 @@ Direction that the Sortable should sort in. Can be set to `'vertical'`, `'horizo
255278
Read more: https://github.com/SortableJS/Sortable/wiki/Swap-Thresholds-and-Direction#direction
256279

257280

258-
Example of dynamic direction detection:
281+
Example of direction detection for vertical list that includes full column and half column elements:
259282

260283
```js
261284
Sortable.create(el, {
262285
direction: function(evt, target, dragEl) {
263-
return Sortable.utils.detectDirection(el);
286+
if (target !== null && target.className.includes('half-column') && dragEl.className.includes('half-column')) {
287+
return 'horizontal';
288+
}
289+
return 'vertical';
264290
}
265291
});
266292
```
@@ -469,15 +495,33 @@ Demo: https://jsbin.com/kesewor/edit?html,js,output
469495

470496

471497
#### `dragoverBubble` option
472-
If set to `true`, the dragover event will bubble to parent Sortables. Useful for nested Sortables. Works on both fallback and native dragover event.
498+
If set to `true`, the dragover event will bubble to parent sortables. Works on both fallback and native dragover event.
499+
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).
500+
501+
Since 1.8.0, you will probably want to leave this option as false. Before 1.8.0, it may need to be `true` for nested sortables to work.
502+
503+
504+
---
505+
506+
507+
#### `removeCloneOnHide` option
508+
If set to `false`, the clone is hidden by having it's CSS `display` property set to `none`.
509+
By default, this option is `true`, meaning Sortable will remove the cloned element from the DOM when it is supposed to be hidden.
473510

474511

475512
---
476513

477514

515+
#### `emptyInsertThreshold` option
516+
The distance (in pixels) the mouse must be from an empty sortable while dragging for the drag element to be inserted into that sortable. Defaults to `5`. Set to `0` to disable this feature.
517+
518+
Demo: https://jsbin.com/becavoj/edit?js,output
519+
520+
521+
---
478522
### Event object ([demo](https://jsbin.com/fogujiv/edit?js,output))
479523

480-
- to:`HTMLElement` — list, in which moved element.
524+
- to:`HTMLElement` — list, in which moved element
481525
- from:`HTMLElement` — previous list
482526
- item:`HTMLElement` — dragged element
483527
- clone:`HTMLElement`
@@ -489,9 +533,10 @@ If set to `true`, the dragover event will bubble to parent Sortables. Useful for
489533
- to:`HTMLElement`
490534
- from:`HTMLElement`
491535
- dragged:`HTMLElement`
492-
- draggedRect:` TextRectangle`
536+
- draggedRect:`DOMRect`
493537
- related:`HTMLElement` — element on which have guided
494-
- relatedRect:` TextRectangle`
538+
- relatedRect:`DOMRect`
539+
- willInsertAfter:`Boolean``true` if will element be inserted after target (or `false` if before)
495540

496541

497542
---
@@ -638,7 +683,7 @@ Link to the active instance.
638683
* closest(el`:HTMLElement`, selector`:String`[, ctx`:HTMLElement`])`:HTMLElement|Null` — for each element in the set, get the first element that matches the selector by testing the element itself and traversing up through its ancestors in the DOM tree
639684
* clone(el`:HTMLElement`)`:HTMLElement` — create a deep copy of the set of matched elements
640685
* toggleClass(el`:HTMLElement`, name`:String`, state`:Boolean`) — add or remove one classes from each element
641-
* detectDirection(el`:HTMLElement`)`:String` — automatically detect the direction of the element as either `'vertical'` or `'horizontal'`
686+
* detectDirection(el`:HTMLElement`)`:String` — automatically detect the [direction](https://github.com/SortableJS/Sortable/wiki/Swap-Thresholds-and-Direction#direction) of the element as either `'vertical'` or `'horizontal'`
642687

643688

644689
---

0 commit comments

Comments
 (0)