clipboard.min.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. "use strict";
  2. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
  3. function _defaults(obj, defaults) { var keys = Object.getOwnPropertyNames(defaults); for (var i = 0; i < keys.length; i++) { var key = keys[i]; var value = Object.getOwnPropertyDescriptor(defaults, key); if (value && value.configurable && obj[key] === undefined) { Object.defineProperty(obj, key, value); } } return obj; }
  4. /*!
  5. * clipboard.js v1.5.9
  6. * https://zenorocha.github.io/clipboard.js
  7. *
  8. * Licensed MIT © Zeno Rocha
  9. */
  10. !function (t) {
  11. if ("object" == (typeof exports === "undefined" ? "undefined" : _typeof(exports)) && "undefined" != typeof module) module.exports = t();else if ("function" == typeof define && define.amd) define([], t);else {
  12. var e;e = "undefined" != typeof window ? window : "undefined" != typeof global ? global : "undefined" != typeof self ? self : this, e.Clipboard = t();
  13. }
  14. }(function () {
  15. var t, e, n;return function t(e, n, o) {
  16. function r(c, s) {
  17. if (!n[c]) {
  18. if (!e[c]) {
  19. var a = "function" == typeof require && require;if (!s && a) return a(c, !0);if (i) return i(c, !0);var l = new Error("Cannot find module '" + c + "'");throw l.code = "MODULE_NOT_FOUND", l;
  20. }var u = n[c] = { exports: {} };e[c][0].call(u.exports, function (t) {
  21. var n = e[c][1][t];return r(n ? n : t);
  22. }, u, u.exports, t, e, n, o);
  23. }return n[c].exports;
  24. }for (var i = "function" == typeof require && require, c = 0; c < o.length; c++) {
  25. r(o[c]);
  26. }return r;
  27. }({ 1: [function (t, e, n) {
  28. var o = t("matches-selector");e.exports = function (t, e, n) {
  29. for (var r = n ? t : t.parentNode; r && r !== document;) {
  30. if (o(r, e)) return r;r = r.parentNode;
  31. }
  32. };
  33. }, { "matches-selector": 5 }], 2: [function (t, e, n) {
  34. function o(t, e, n, o, i) {
  35. var c = r.apply(this, arguments);return t.addEventListener(n, c, i), { destroy: function destroy() {
  36. t.removeEventListener(n, c, i);
  37. } };
  38. }function r(t, e, n, o) {
  39. return function (n) {
  40. n.delegateTarget = i(n.target, e, !0), n.delegateTarget && o.call(t, n);
  41. };
  42. }var i = t("closest");e.exports = o;
  43. }, { closest: 1 }], 3: [function (t, e, n) {
  44. n.node = function (t) {
  45. return void 0 !== t && t instanceof HTMLElement && 1 === t.nodeType;
  46. }, n.nodeList = function (t) {
  47. var e = Object.prototype.toString.call(t);return void 0 !== t && ("[object NodeList]" === e || "[object HTMLCollection]" === e) && "length" in t && (0 === t.length || n.node(t[0]));
  48. }, n.string = function (t) {
  49. return "string" == typeof t || t instanceof String;
  50. }, n.fn = function (t) {
  51. var e = Object.prototype.toString.call(t);return "[object Function]" === e;
  52. };
  53. }, {}], 4: [function (t, e, n) {
  54. function o(t, e, n) {
  55. if (!t && !e && !n) throw new Error("Missing required arguments");if (!s.string(e)) throw new TypeError("Second argument must be a String");if (!s.fn(n)) throw new TypeError("Third argument must be a Function");if (s.node(t)) return r(t, e, n);if (s.nodeList(t)) return i(t, e, n);if (s.string(t)) return c(t, e, n);throw new TypeError("First argument must be a String, HTMLElement, HTMLCollection, or NodeList");
  56. }function r(t, e, n) {
  57. return t.addEventListener(e, n), { destroy: function destroy() {
  58. t.removeEventListener(e, n);
  59. } };
  60. }function i(t, e, n) {
  61. return Array.prototype.forEach.call(t, function (t) {
  62. t.addEventListener(e, n);
  63. }), { destroy: function destroy() {
  64. Array.prototype.forEach.call(t, function (t) {
  65. t.removeEventListener(e, n);
  66. });
  67. } };
  68. }function c(t, e, n) {
  69. return a(document.body, t, e, n);
  70. }var s = t("./is"),
  71. a = t("delegate");e.exports = o;
  72. }, { "./is": 3, delegate: 2 }], 5: [function (t, e, n) {
  73. function o(t, e) {
  74. if (i) return i.call(t, e);for (var n = t.parentNode.querySelectorAll(e), o = 0; o < n.length; ++o) {
  75. if (n[o] == t) return !0;
  76. }return !1;
  77. }var r = Element.prototype,
  78. i = r.matchesSelector || r.webkitMatchesSelector || r.mozMatchesSelector || r.msMatchesSelector || r.oMatchesSelector;e.exports = o;
  79. }, {}], 6: [function (t, e, n) {
  80. function o(t) {
  81. var e;if ("INPUT" === t.nodeName || "TEXTAREA" === t.nodeName) t.focus(), t.setSelectionRange(0, t.value.length), e = t.value;else {
  82. t.hasAttribute("contenteditable") && t.focus();var n = window.getSelection(),
  83. o = document.createRange();o.selectNodeContents(t), n.removeAllRanges(), n.addRange(o), e = n.toString();
  84. }return e;
  85. }e.exports = o;
  86. }, {}], 7: [function (t, e, n) {
  87. function o() {}o.prototype = { on: function on(t, e, n) {
  88. var o = this.e || (this.e = {});return (o[t] || (o[t] = [])).push({ fn: e, ctx: n }), this;
  89. }, once: function once(t, e, n) {
  90. function o() {
  91. r.off(t, o), e.apply(n, arguments);
  92. }var r = this;return o._ = e, this.on(t, o, n);
  93. }, emit: function emit(t) {
  94. var e = [].slice.call(arguments, 1),
  95. n = ((this.e || (this.e = {}))[t] || []).slice(),
  96. o = 0,
  97. r = n.length;for (o; r > o; o++) {
  98. n[o].fn.apply(n[o].ctx, e);
  99. }return this;
  100. }, off: function off(t, e) {
  101. var n = this.e || (this.e = {}),
  102. o = n[t],
  103. r = [];if (o && e) for (var i = 0, c = o.length; c > i; i++) {
  104. o[i].fn !== e && o[i].fn._ !== e && r.push(o[i]);
  105. }return r.length ? n[t] = r : delete n[t], this;
  106. } }, e.exports = o;
  107. }, {}], 8: [function (e, n, o) {
  108. !function (r, i) {
  109. if ("function" == typeof t && t.amd) t(["module", "select"], i);else if ("undefined" != typeof o) i(n, e("select"));else {
  110. var c = { exports: {} };i(c, r.select), r.clipboardAction = c.exports;
  111. }
  112. }(this, function (t, e) {
  113. "use strict";
  114. function n(t) {
  115. return t && t.__esModule ? t : { "default": t };
  116. }function o(t, e) {
  117. if (!(t instanceof e)) throw new TypeError("Cannot call a class as a function");
  118. }var r = n(e),
  119. i = "function" == typeof Symbol && "symbol" == _typeof(Symbol.iterator) ? function (t) {
  120. return typeof t === "undefined" ? "undefined" : _typeof(t);
  121. } : function (t) {
  122. return t && "function" == typeof Symbol && t.constructor === Symbol ? "symbol" : typeof t === "undefined" ? "undefined" : _typeof(t);
  123. },
  124. c = function () {
  125. function t(t, e) {
  126. for (var n = 0; n < e.length; n++) {
  127. var o = e[n];o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(t, o.key, o);
  128. }
  129. }return function (e, n, o) {
  130. return n && t(e.prototype, n), o && t(e, o), e;
  131. };
  132. }(),
  133. s = function () {
  134. function t(e) {
  135. o(this, t), this.resolveOptions(e), this.initSelection();
  136. }return t.prototype.resolveOptions = function t() {
  137. var e = arguments.length <= 0 || void 0 === arguments[0] ? {} : arguments[0];this.action = e.action, this.emitter = e.emitter, this.target = e.target, this.text = e.text, this.trigger = e.trigger, this.selectedText = "";
  138. }, t.prototype.initSelection = function t() {
  139. if (this.text && this.target) throw new Error('Multiple attributes declared, use either "target" or "text"');if (this.text) this.selectFake();else {
  140. if (!this.target) throw new Error('Missing required attributes, use either "target" or "text"');this.selectTarget();
  141. }
  142. }, t.prototype.selectFake = function t() {
  143. var e = this,
  144. n = "rtl" == document.documentElement.getAttribute("dir");this.removeFake(), this.fakeHandler = document.body.addEventListener("click", function () {
  145. return e.removeFake();
  146. }), this.fakeElem = document.createElement("textarea"), this.fakeElem.style.fontSize = "12pt", this.fakeElem.style.border = "0", this.fakeElem.style.padding = "0", this.fakeElem.style.margin = "0", this.fakeElem.style.position = "fixed", this.fakeElem.style[n ? "right" : "left"] = "-9999px", this.fakeElem.style.top = (window.pageYOffset || document.documentElement.scrollTop) + "px", this.fakeElem.setAttribute("readonly", ""), this.fakeElem.value = this.text, document.body.appendChild(this.fakeElem), this.selectedText = (0, r.default)(this.fakeElem), this.copyText();
  147. }, t.prototype.removeFake = function t() {
  148. this.fakeHandler && (document.body.removeEventListener("click"), this.fakeHandler = null), this.fakeElem && (document.body.removeChild(this.fakeElem), this.fakeElem = null);
  149. }, t.prototype.selectTarget = function t() {
  150. this.selectedText = (0, r.default)(this.target), this.copyText();
  151. }, t.prototype.copyText = function t() {
  152. var e = void 0;try {
  153. e = document.execCommand(this.action);
  154. } catch (n) {
  155. e = !1;
  156. }this.handleResult(e);
  157. }, t.prototype.handleResult = function t(e) {
  158. e ? this.emitter.emit("success", { action: this.action, text: this.selectedText, trigger: this.trigger, clearSelection: this.clearSelection.bind(this) }) : this.emitter.emit("error", { action: this.action, trigger: this.trigger, clearSelection: this.clearSelection.bind(this) });
  159. }, t.prototype.clearSelection = function t() {
  160. this.target && this.target.blur(), window.getSelection().removeAllRanges();
  161. }, t.prototype.destroy = function t() {
  162. this.removeFake();
  163. }, c(t, [{ key: "action", set: function t() {
  164. var e = arguments.length <= 0 || void 0 === arguments[0] ? "copy" : arguments[0];if (this._action = e, "copy" !== this._action && "cut" !== this._action) throw new Error('Invalid "action" value, use either "copy" or "cut"');
  165. }, get: function t() {
  166. return this._action;
  167. } }, { key: "target", set: function t(e) {
  168. if (void 0 !== e) {
  169. if (!e || "object" !== ("undefined" == typeof e ? "undefined" : i(e)) || 1 !== e.nodeType) throw new Error('Invalid "target" value, use a valid Element');this._target = e;
  170. }
  171. }, get: function t() {
  172. return this._target;
  173. } }]), t;
  174. }();t.exports = s;
  175. });
  176. }, { select: 6 }], 9: [function (e, n, o) {
  177. !function (r, i) {
  178. if ("function" == typeof t && t.amd) t(["module", "./clipboard-action", "tiny-emitter", "good-listener"], i);else if ("undefined" != typeof o) i(n, e("./clipboard-action"), e("tiny-emitter"), e("good-listener"));else {
  179. var c = { exports: {} };i(c, r.clipboardAction, r.tinyEmitter, r.goodListener), r.clipboard = c.exports;
  180. }
  181. }(this, function (t, e, n, o) {
  182. "use strict";
  183. function r(t) {
  184. return t && t.__esModule ? t : { "default": t };
  185. }function i(t, e) {
  186. if (!(t instanceof e)) throw new TypeError("Cannot call a class as a function");
  187. }function c(t, e) {
  188. if (!t) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return !e || "object" != (typeof e === "undefined" ? "undefined" : _typeof(e)) && "function" != typeof e ? t : e;
  189. }function s(t, e) {
  190. if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function, not " + (typeof e === "undefined" ? "undefined" : _typeof(e)));t.prototype = Object.create(e && e.prototype, { constructor: { value: t, enumerable: !1, writable: !0, configurable: !0 } }), e && (Object.setPrototypeOf ? Object.setPrototypeOf(t, e) : _defaults(t, e));
  191. }function a(t, e) {
  192. var n = "data-clipboard-" + t;if (e.hasAttribute(n)) return e.getAttribute(n);
  193. }var l = r(e),
  194. u = r(n),
  195. f = r(o),
  196. d = function (t) {
  197. function e(n, o) {
  198. i(this, e);var r = c(this, t.call(this));return r.resolveOptions(o), r.listenClick(n), r;
  199. }return s(e, t), e.prototype.resolveOptions = function t() {
  200. var e = arguments.length <= 0 || void 0 === arguments[0] ? {} : arguments[0];this.action = "function" == typeof e.action ? e.action : this.defaultAction, this.target = "function" == typeof e.target ? e.target : this.defaultTarget, this.text = "function" == typeof e.text ? e.text : this.defaultText;
  201. }, e.prototype.listenClick = function t(e) {
  202. var n = this;this.listener = (0, f.default)(e, "click", function (t) {
  203. return n.onClick(t);
  204. });
  205. }, e.prototype.onClick = function t(e) {
  206. var n = e.delegateTarget || e.currentTarget;this.clipboardAction && (this.clipboardAction = null), this.clipboardAction = new l.default({ action: this.action(n), target: this.target(n), text: this.text(n), trigger: n, emitter: this });
  207. }, e.prototype.defaultAction = function t(e) {
  208. return a("action", e);
  209. }, e.prototype.defaultTarget = function t(e) {
  210. var n = a("target", e);return n ? document.querySelector(n) : void 0;
  211. }, e.prototype.defaultText = function t(e) {
  212. return a("text", e);
  213. }, e.prototype.destroy = function t() {
  214. this.listener.destroy(), this.clipboardAction && (this.clipboardAction.destroy(), this.clipboardAction = null);
  215. }, e;
  216. }(u.default);t.exports = d;
  217. });
  218. }, { "./clipboard-action": 8, "good-listener": 4, "tiny-emitter": 7 }] }, {}, [9])(9);
  219. });