Skip to content

Commit 949ffa0

Browse files
2 parents 59767b6 + 0bcc409 commit 949ffa0

File tree

1 file changed

+61
-2
lines changed

1 file changed

+61
-2
lines changed

README.md

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Based on and offering all features of [Sortable.js](https://github.com/RubaXa/So
2424
* Keeps in sync view model and view
2525
* No jquery dependency
2626
* Plays nicely with Vue.js 2.0 transition-group
27+
* cancelation support
2728

2829
##For Vue.js 2.0
2930

@@ -46,6 +47,16 @@ With `transition-group`:
4647
</transition-group>
4748
</draggable>
4849
```
50+
.vue file:
51+
``` js
52+
import draggable from 'vuedraggable'
53+
...
54+
export default {
55+
components: {
56+
draggable,
57+
},
58+
...
59+
```
4960
5061
Draggable component should directly wrap the draggable elements, or a `transition-component` containing the draggable elements.
5162
@@ -79,11 +90,59 @@ Default: `(original) => { return original;}`<br>
7990
Function called on the source component to clone element when clone option is true. The unique argument is the viewModel element to be cloned and the returned value should be its cloned version.<br>
8091
By default vue.draggable reuse the viewmodel element, so you have to use this hook if you want to clone or deep clone it.
8192
93+
#### move
94+
Type: `Function`<br>
95+
Required: `false`<br>
96+
Default: `null`<br>
97+
98+
If not null this function will be called in a similar way as [Sortable onMove callback](https://github.com/RubaXa/Sortable#move-event-object).
99+
Returning false will cancel the drag operation.
100+
101+
```javascript
102+
function onMoveCallback(evt, originalEvent){
103+
...
104+
// return false; — for cancel
105+
}
106+
```
107+
evt object has same property as [Sortable onMove event](https://github.com/RubaXa/Sortable#move-event-object), plus two addicional properties:
108+
`move event` object addicional properties:
109+
- `draggedContext`: context linked to dragged element
110+
- `index`: dragged element index
111+
- `element`: dragged element underlying view model element
112+
- `relatedContext`: context linked to current drag position
113+
- `index`: target element index
114+
- `element`: target element view model element
115+
- `list`: target list
116+
- `component`: target VueComponent
117+
118+
Ex:
119+
120+
HTML:
121+
```HTML
122+
<draggable :list="list" :move="checkMove">
123+
```
124+
javascript:
125+
```javascript
126+
checkMove: function(evt){
127+
return (evt.draggedContext.element.name!=='apple');
128+
}
129+
```
130+
See complete example: [Cancel.html](https://github.com/SortableJS/Vue.Draggable/blob/master/examples/Cancel.html), [cancel.js](https://github.com/SortableJS/Vue.Draggable/blob/master/examples/script/cancel.js)
131+
132+
82133
### Events
83-
`start`, `add`, `remove`, `update`, `end`, `choose`, `sort`, `filter`, `move`, `clone`<br>
84-
Called when there equivalent onStart, onAdd, .... are fired by Sortabe.js with the same argument.<br>
134+
`start`, `add`, `remove`, `update`, `end`, `choose`, `sort`, `filter`, `clone`<br>
135+
events are called when respectivelly onStart, onAdd, onRemove, onUpdate, onEnd, onChoose, onSort, onClone are fired by Sortabe.js with the same argument.<br>
85136
[See here for reference](https://github.com/RubaXa/Sortable#event-object-demo)
86137
138+
The OnMove callback is mapped with the [move prop](https://github.com/SortableJS/Vue.Draggable/blob/master/README.md#move)
139+
140+
Ex:
141+
HTML:
142+
```HTML
143+
<draggable :list="list" @end="onEnd">
144+
```
145+
87146
###Fiddle
88147
Simple:
89148
https://jsfiddle.net/dede89/sqssmhtz/

0 commit comments

Comments
 (0)