v-copy
Version:
Vue directive to copy to clipboard.
3 lines (2 loc) • 1.27 kB
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(e.vCopy={})}(this,function(e){"use strict";var t=function(e){var t=document.createElement("textarea");t.value=e,t.setAttribute("readonly",""),t.style.contain="strict",t.style.position="absolute",t.style.left="-9999px",t.style.fontSize="12pt";var n=getSelection(),o=!1;n.rangeCount>0&&(o=n.getRangeAt(0)),document.body.appendChild(t),t.select(),t.selectionStart=0,t.selectionEnd=e.length;var c=!1;try{c=document.execCommand("copy")}catch(e){}return document.body.removeChild(t),o&&(n.removeAllRanges(),n.addRange(o)),c},n={bind:function(e,n){var o=n.value;if("callback"===n.arg)e.$copyCallback=o;else{e.$copyValue=o;var c=function(){t(e.$copyValue),e.$copyCallback&&e.$copyCallback(e.$copyValue)};e.addEventListener("click",c),e.$destroyCopy=function(){return e.removeEventListener("click",c)}}},unbind:function(e){e.$destroyCopy()},componentUpdated:function(e,t){var n=t.value;"callback"===t.arg?e.$copyCallback=n:e.$copyValue=n}},o=function(e){e.directive("copy",n)};"undefined"!=typeof window&&window.Vue&&o(window.Vue),e.copy=n,e.default=o,Object.defineProperty(e,"__esModule",{value:!0})});
//# sourceMappingURL=v-copy.min.js.map