Skip to content

Commit

Permalink
Support v-clipboard:error
Browse files Browse the repository at this point in the history
  • Loading branch information
Inndy committed Apr 20, 2017
1 parent b66a901 commit 8f2c7d1
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions vue-clipboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ var VueClipboard = {
bind: function (el, binding, vnode) {
if(binding.arg === 'success') {
el._v_clipboard_success = binding.value
} else if(binding.arg === 'error') {
el._v_clipboard_error = binding.value
} else {
var clipboard = new Clipboard(el, {
text: function () { return binding.value },
Expand All @@ -15,12 +17,18 @@ var VueClipboard = {
var callback = el._v_clipboard_success
callback && callback(e)
})
clipboard.on('error', function (e) {
var callback = el._v_clipboard_error
callback && callback(e)
})
el._v_clipboard = clipboard
}
},
update: function (el, binding) {
if(binding.arg === 'success') {
el._v_clipboard_success = binding.value
} else if(binding.arg === 'error') {
el._v_clipboard_error = binding.value
} else {
el._v_clipboard.text = function () { return binding.value }
el._v_clipboard.action = function () { return binding.arg === 'cut' ? 'cut' : 'copy' }
Expand All @@ -29,6 +37,8 @@ var VueClipboard = {
unbind: function (el, binding) {
if(binding.arg === 'success') {
delete el._v_clipboard_success
} else if(binding.arg === 'error') {
delete el._v_clipboard_error
} else {
el._v_clipboard.destroy()
delete el._v_clipboard
Expand Down

0 comments on commit 8f2c7d1

Please sign in to comment.