-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
33 lines (27 loc) · 933 Bytes
/
index.js
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
module.exports = {
compiled: function () {
var vm = this;
var $el = this.$el;
var key = 'elements';
// Refresh jQuery sortable when we make changes to the listKey array
vm.$watch(key, function () {
$($el).sortable('refresh')
});
var onStart = function (event, ui) {
ui.item.data('start', ui.item.index());
};
var onUpdate = function (event, ui) {
var start = ui.item.data('start');
var end = ui.item.index();
var array = vm.$get(key) || [];
var swappedEl = array.splice(start, 1)[0];
// Move the item to the new position(index) and add back the swapped element
// which was holding that position
array.splice(end, 0, swappedEl);
};
$($el).sortable({
start: onStart,
update: onUpdate
});
}
};