clipboard.js/dist/clipboard.min.js
2015-09-21 00:37:02 -07:00

1 line
3.5 KiB
JavaScript

!function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);var j=new Error("Cannot find module '"+g+"'");throw j.code="MODULE_NOT_FOUND",j}var k=c[g]={exports:{}};b[g][0].call(k.exports,function(a){var c=b[g][1][a];return e(c?c:a)},k,k.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g<d.length;g++)e(d[g]);return e}({1:[function(a,b,c){(function(a){function c(){try{var a=new d("cat",{detail:{foo:"bar"}});return"cat"===a.type&&"bar"===a.detail.foo}catch(b){}return!1}var d=a.CustomEvent;b.exports=c()?d:"function"==typeof document.createEvent?function(a,b){var c=document.createEvent("CustomEvent");return b?c.initCustomEvent(a,b.bubbles,b.cancelable,b.detail):c.initCustomEvent(a,!1,!1,void 0),c}:function(a,b){var c=document.createEventObject();return c.type=a,b?(c.bubbles=Boolean(b.bubbles),c.cancelable=Boolean(b.cancelable),c.detail=b.detail):(c.bubbles=!1,c.cancelable=!1,c.detail=void 0),c}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],2:[function(a,b,c){(function(d){"use strict";function e(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}c.__esModule=!0;var f=a("custom-event"),g=function(){function a(b){var c=this;if(e(this,a),this.triggers=document.querySelectorAll(b),!this.triggers.length)throw new Error("No matches were found for the provided selector");[].forEach.call(this.triggers,function(a){return c.bind(a)})}return a.prototype.bind=function(a){var b=this;a.addEventListener("click",function(a){return b.validate(a)})},a.prototype.validate=function(a){var b=a.currentTarget,c=b.getAttribute("data-action")||"copy",d=b.getAttribute("data-target"),e=b.getAttribute("data-text");if("copy"!==c&&"cut"!==c)throw new Error('Invalid "data-action" value, use either "copy" or "cut"');if(!d&&!e)throw new Error('Missing required attributes, use either "data-target" or "data-text"');if(d&&(d=document.getElementById(d),!d))throw new Error('Invalid "data-target" selector, use a value that matches an ID');new h(c,d,e,b)},a}();c["default"]=g;var h=function(){function a(b,c,d,f){e(this,a),this.action=b,this.target=c,this.text=d,this.trigger=f,this.selectedText="",this.text?this.selectValue():this.target&&this.selectTarget()}return a.prototype.selectValue=function(){var a=document.createElement("input");a.style.opacity=0,a.style.zIndex=-1,a.value=this.text,this.selectedText=this.text,document.body.appendChild(a),a.select(),this.copy(),document.body.removeChild(a)},a.prototype.selectTarget=function(){if("INPUT"===this.target.nodeName||"TEXTAREA"===this.target.nodeName)this.target.select(),this.selectedText=this.target.value;else{var a=document.createRange(),b=window.getSelection();a.selectNode(this.target),b.addRange(a),this.selectedText=b.toString()}this.copy()},a.prototype.copy=function(){var a=document.queryCommandSupported(this.action);try{document.execCommand(this.action),this.fireEventDetails(),window.getSelection().removeAllRanges()}catch(b){a=!1}a||this.fireNoSupport()},a.prototype.fireEventDetails=function(){var a=new f(this.action,{detail:this.selectedText});this.trigger.dispatchEvent(a)},a.prototype.fireNoSupport=function(){var a=new f("no-support");this.trigger.dispatchEvent(a)},a}();d.Clipboard=g,b.exports=c["default"]}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"custom-event":1}]},{},[2]);