clipboard.js/dist/clipboard.min.js
2015-09-24 16:18:50 -07:00

1 line
4.6 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){"use strict";function d(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}c.__esModule=!0;var e=function(){function a(a,b){for(var c=0;c<b.length;c++){var d=b[c];d.enumerable=d.enumerable||!1,d.configurable=!0,"value"in d&&(d.writable=!0),Object.defineProperty(a,d.key,d)}}return function(b,c,d){return c&&a(b.prototype,c),d&&a(b,d),b}}(),f=a("custom-event"),g=function(){function a(b){d(this,a),this.action=b.action,this.target=b.target,this.text=b.text,this.trigger=b.trigger,this.selectedText="",this.text?this.selectValue():this.target&&this.selectTarget()}return a.prototype.selectValue=function(){var a=document.createElement("input");a.style.position="absolute",a.style.left="-9999px",a.value=this.text,this.selectedText=this.text,document.body.appendChild(a),a.select(),this.copyText(),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.selectNodeContents(this.target),b.addRange(a),this.selectedText=b.toString()}this.copyText()},a.prototype.copyText=function(){var a=void 0;try{a=document.execCommand(this.action)}catch(b){a=!1}this.handleResult(a)},a.prototype.handleResult=function(a){a?this.fireEvent("success",{action:this.action,text:this.selectedText,clearSelection:this.clearSelection.bind(this)}):this.fireEvent("error",{action:this.action,clearSelection:this.clearSelection.bind(this)})},a.prototype.fireEvent=function(a,b){var c=new f(a,{detail:b});this.trigger.dispatchEvent(c)},a.prototype.clearSelection=function(){this.target&&this.target.blur(),window.getSelection().removeAllRanges()},e(a,[{key:"action",set:function(a){if(this._action=a||"copy","copy"!==this._action&&"cut"!==this._action)throw new Error('Invalid "data-action" value, use either "copy" or "cut"')},get:function(){return this._action}},{key:"target",set:function(a){if(a&&(this._target=document.getElementById(a),!this._target))throw new Error('Invalid "data-target" selector, use a value that matches an ID')},get:function(){return this._target}}]),a}();c["default"]=g,b.exports=c["default"]},{"custom-event":1}],3:[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=function(){function a(a,b){for(var c=0;c<b.length;c++){var d=b[c];d.enumerable=d.enumerable||!1,d.configurable=!0,"value"in d&&(d.writable=!0),Object.defineProperty(a,d.key,d)}}return function(b,c,d){return c&&a(b.prototype,c),d&&a(b,d),b}}(),g=a("./clipboard-action"),h=function(){function a(b){var c=this;e(this,a),this.triggers=document.querySelectorAll(b),[].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.initialize(a)})},a.prototype.initialize=function(a){new g({action:a.currentTarget.getAttribute("data-action"),target:a.currentTarget.getAttribute("data-target"),text:a.currentTarget.getAttribute("data-text"),trigger:a.currentTarget})},f(a,[{key:"triggers",set:function(a){if(!a.length)throw new Error("No matches were found for the provided selector");this._triggers=a},get:function(){return this._triggers}}]),a}();c["default"]=h,d.Clipboard=h,b.exports=c["default"]}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./clipboard-action":2}]},{},[3]);