forked from rhyzx/vue-transfer-dom
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathindex.js
38 lines (35 loc) · 1.1 KB
/
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
34
35
36
37
38
// umd https://github.com/umdjs/umd/blob/master/templates/returnExports.js
!function (root, install) {
if (typeof define === 'function' && define.amd) {
define([], { install: install })
} else if (typeof module === 'object' && module.exports) {
exports.install = install
} else {
root.VueTransferDom = { install: install }
}
}(this, function (Vue, options) {
var name = (options && options.name) || 'transferDom'
// Define the directive
Vue.directive(name, {
inserted: function (el, bindings, vnode) {
// default append to <body>
var container = bindings.arg
? document.getElementById(bindings.arg)
: document.body
if (container) {
( bindings.modifiers.prepend && container.firstChild )
? container.insertBefore(el, container.firstChild) // top of target
: container.appendChild(el) // bottom of target
} else {
console.warn(
'v-' + name + ' target element id "' + bindings.arg + '" not found.'
)
}
},
unbind: function (el) {
if(el.parentNode) {
el.parentNode.removeChild(el);
}
}
})
})