forked from Inndy/vue-clipboard2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vue-clipboard.js
31 lines (29 loc) · 919 Bytes
/
vue-clipboard.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
var Clipboard = require('clipboard')
var VueClipboard = {
install: function (Vue) {
Vue.directive('clipboard', {
bind: function (el, binding, vnode) {
const clipboard = new Clipboard(el, {
text: function () { return binding.value },
action: function () { return binding.arg === 'cut' ? 'cut' : 'copy' }
})
el._v_clipboard = clipboard
},
update: function (el, binding) {
el._v_clipboard.text = function () { return binding.value },
el._v_clipboard.action = function () { return binding.arg === 'cut' ? 'cut' : 'copy' }
},
unbind: function (el, binding) {
el._v_clipboard.destroy()
delete el._v_clipboard
}
})
}
}
if (typeof exports == "object") {
module.exports = VueClipboard
} else if (typeof define == "function" && define.amd) {
define([], function() {
return VueClipboard
})
}