/**
 * v-clipboard 剪切板
 */
import Vue from 'vue';
const clipboard = {
  bind(el, binding, vnode, oldVnode) {
    el.val = binding.value;
    el.handler = function() {
      const val = el.val;
      const input = document.createElement('input');
      el.appendChild(input);
      input.value = val;
      input.select();
      document.execCommand('Copy');
      Vue.prototype.$message({ type: 'success', message: '复制成功' });
      input.parentNode.removeChild(input);
    };
    el.addEventListener('click', el.handler);
  },
  update(el, binding, vnode, oldVnode) {
    el.val = binding.value;
  },
  unbind: function(el) {
    el.removeEventListener('click', el.handler);
  }
};
const linkMap = {
  code: 'https://www.yuque.com/exnmlu/oo64hg/thm172#w4sOg',
  link: 'https://www.yuque.com/exnmlu/oo64hg/lggf7q#eV2NM'
};
const jumpLink = {
  bind(el, binding) {
    const { arg } = binding;
    el.handler = function() {
      window.open(linkMap[arg]);
    };
    el.addEventListener('click', el.handler);
  },
  unbind: function(el) {
    el.removeEventListener('click', el.handler);
  }
};
export default { clipboard, jumpLink };
