forked from ryanhightower/vue-sortable
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vue-sortable.js
48 lines (39 loc) · 1.18 KB
/
vue-sortable.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
;(function () {
var vSortable = {}
var Sortable = typeof require === 'function'
? require('sortablejs')
: window.Sortable
if (!Sortable) {
throw new Error('[vue-sortable] cannot locate Sortable.js.')
}
// exposed global options
vSortable.config = {}
vSortable.install = function (Vue) {
Vue.directive('sortable', {
bind: function (el, binding, vnode) {
options = binding.value || {}
var sortable = new Sortable(el, options)
const vm = vnode.context;
if (binding.arg && !vm.sortable) {
vm.sortable = {}
}
// Throw an error if the given ID is not unique
if (binding.arg && vm.sortable[binding.arg]) {
console.warn('[vue-sortable] cannot set already defined sortable id: \'' + binding.arg + '\'')
} else if( binding.arg ) {
vm.sortable[binding.arg] = sortable
}
}
})
}
if (typeof exports == "object") {
module.exports = vSortable
} else if (typeof define == "function" && define.amd) {
define([], function () {
return vSortable
})
} else if (window.Vue) {
window.vSortable = vSortable
Vue.use(vSortable)
}
})()