clipboard.min.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  1. /*!
  2. * clipboard.js v1.6.0
  3. * https://zenorocha.github.io/clipboard.js
  4. *
  5. * Licensed MIT © Zeno Rocha
  6. */
  7. !function (e) {
  8. if ("object" == typeof exports && "undefined" != typeof module)module.exports = e(); else if ("function" == typeof define && define.amd)define([], e); else {
  9. var t;
  10. t = "undefined" != typeof window ? window : "undefined" != typeof global ? global : "undefined" != typeof self ? self : this, t.Clipboard = e()
  11. }
  12. }(function () {
  13. var e, t, n;
  14. return function e(t, n, o) {
  15. function i(a, c) {
  16. if (!n[a]) {
  17. if (!t[a]) {
  18. var l = "function" == typeof require && require;
  19. if (!c && l)return l(a, !0);
  20. if (r)return r(a, !0);
  21. var u = new Error("Cannot find module '" + a + "'");
  22. throw u.code = "MODULE_NOT_FOUND", u
  23. }
  24. var s = n[a] = {exports: {}};
  25. t[a][0].call(s.exports, function (e) {
  26. var n = t[a][1][e];
  27. return i(n ? n : e)
  28. }, s, s.exports, e, t, n, o)
  29. }
  30. return n[a].exports
  31. }
  32. for (var r = "function" == typeof require && require, a = 0; a < o.length; a++)i(o[a]);
  33. return i
  34. }({
  35. 1: [function (e, t, n) {
  36. function o(e, t) {
  37. for (; e && e.nodeType !== i;) {
  38. if (e.matches(t))return e;
  39. e = e.parentNode
  40. }
  41. }
  42. var i = 9;
  43. if (Element && !Element.prototype.matches) {
  44. var r = Element.prototype;
  45. r.matches = r.matchesSelector || r.mozMatchesSelector || r.msMatchesSelector || r.oMatchesSelector || r.webkitMatchesSelector
  46. }
  47. t.exports = o
  48. }, {}], 2: [function (e, t, n) {
  49. function o(e, t, n, o, r) {
  50. var a = i.apply(this, arguments);
  51. return e.addEventListener(n, a, r), {
  52. destroy: function () {
  53. e.removeEventListener(n, a, r)
  54. }
  55. }
  56. }
  57. function i(e, t, n, o) {
  58. return function (n) {
  59. n.delegateTarget = r(n.target, t), n.delegateTarget && o.call(e, n)
  60. }
  61. }
  62. var r = e("./closest");
  63. t.exports = o
  64. }, {"./closest": 1}], 3: [function (e, t, n) {
  65. n.node = function (e) {
  66. return void 0 !== e && e instanceof HTMLElement && 1 === e.nodeType
  67. }, n.nodeList = function (e) {
  68. var t = Object.prototype.toString.call(e);
  69. return void 0 !== e && ("[object NodeList]" === t || "[object HTMLCollection]" === t) && "length" in e && (0 === e.length || n.node(e[0]))
  70. }, n.string = function (e) {
  71. return "string" == typeof e || e instanceof String
  72. }, n.fn = function (e) {
  73. var t = Object.prototype.toString.call(e);
  74. return "[object Function]" === t
  75. }
  76. }, {}], 4: [function (e, t, n) {
  77. function o(e, t, n) {
  78. if (!e && !t && !n)throw new Error("Missing required arguments");
  79. if (!c.string(t))throw new TypeError("Second argument must be a String");
  80. if (!c.fn(n))throw new TypeError("Third argument must be a Function");
  81. if (c.node(e))return i(e, t, n);
  82. if (c.nodeList(e))return r(e, t, n);
  83. if (c.string(e))return a(e, t, n);
  84. throw new TypeError("First argument must be a String, HTMLElement, HTMLCollection, or NodeList")
  85. }
  86. function i(e, t, n) {
  87. return e.addEventListener(t, n), {
  88. destroy: function () {
  89. e.removeEventListener(t, n)
  90. }
  91. }
  92. }
  93. function r(e, t, n) {
  94. return Array.prototype.forEach.call(e, function (e) {
  95. e.addEventListener(t, n)
  96. }), {
  97. destroy: function () {
  98. Array.prototype.forEach.call(e, function (e) {
  99. e.removeEventListener(t, n)
  100. })
  101. }
  102. }
  103. }
  104. function a(e, t, n) {
  105. return l(document.body, e, t, n)
  106. }
  107. var c = e("./is"), l = e("delegate");
  108. t.exports = o
  109. }, {"./is": 3, delegate: 2}], 5: [function (e, t, n) {
  110. function o(e) {
  111. console.log(e);
  112. var t;
  113. if ("SELECT" === e.nodeName)e.focus(), t = e.value; else if ("INPUT" === e.nodeName || "TEXTAREA" === e.nodeName) {
  114. var n = e.hasAttribute("readonly");
  115. n || e.setAttribute("readonly", ""), e.select(), e.setSelectionRange(0, e.value.length), n || e.removeAttribute("readonly"), t = e.value
  116. } else {
  117. e.hasAttribute("contenteditable") && e.focus();
  118. var o = window.getSelection(), i = document.createRange();
  119. i.selectNodeContents(e), o.removeAllRanges(), o.addRange(i), t = o.toString()
  120. }
  121. return t
  122. }
  123. t.exports = o
  124. }, {}], 6: [function (e, t, n) {
  125. function o() {
  126. }
  127. o.prototype = {
  128. on: function (e, t, n) {
  129. var o = this.e || (this.e = {});
  130. return (o[e] || (o[e] = [])).push({fn: t, ctx: n}), this
  131. }, once: function (e, t, n) {
  132. function o() {
  133. i.off(e, o), t.apply(n, arguments)
  134. }
  135. var i = this;
  136. return o._ = t, this.on(e, o, n)
  137. }, emit: function (e) {
  138. var t = [].slice.call(arguments, 1), n = ((this.e || (this.e = {}))[e] || []).slice(), o = 0, i = n.length;
  139. for (o; o < i; o++)n[o].fn.apply(n[o].ctx, t);
  140. return this
  141. }, off: function (e, t) {
  142. var n = this.e || (this.e = {}), o = n[e], i = [];
  143. if (o && t)for (var r = 0, a = o.length; r < a; r++)o[r].fn !== t && o[r].fn._ !== t && i.push(o[r]);
  144. return i.length ? n[e] = i : delete n[e], this
  145. }
  146. }, t.exports = o
  147. }, {}], 7: [function (t, n, o) {
  148. !function (i, r) {
  149. if ("function" == typeof e && e.amd)e(["module", "select"], r); else if ("undefined" != typeof o)r(n, t("select")); else {
  150. var a = {exports: {}};
  151. r(a, i.select), i.clipboardAction = a.exports
  152. }
  153. }(this, function (e, t) {
  154. "use strict";
  155. function n(e) {
  156. return e && e.__esModule ? e : {default: e}
  157. }
  158. function o(e, t) {
  159. if (!(e instanceof t))throw new TypeError("Cannot call a class as a function")
  160. }
  161. var i = n(t), r = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (e) {
  162. return typeof e
  163. } : function (e) {
  164. return e && "function" == typeof Symbol && e.constructor === Symbol && e !== Symbol.prototype ? "symbol" : typeof e
  165. }, a = function () {
  166. function e(e, t) {
  167. for (var n = 0; n < t.length; n++) {
  168. var o = t[n];
  169. o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, o.key, o)
  170. }
  171. }
  172. return function (t, n, o) {
  173. return n && e(t.prototype, n), o && e(t, o), t
  174. }
  175. }(), c = function () {
  176. function e(t) {
  177. o(this, e), this.resolveOptions(t), this.initSelection()
  178. }
  179. return a(e, [{
  180. key: "resolveOptions", value: function e() {
  181. var t = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {};
  182. this.action = t.action, this.emitter = t.emitter, this.target = t.target, this.text = t.text, this.trigger = t.trigger, this.selectedText = ""
  183. }
  184. }, {
  185. key: "initSelection", value: function e() {
  186. this.text ? this.selectFake() : this.target && this.selectTarget()
  187. }
  188. }, {
  189. key: "selectFake", value: function e() {
  190. var t = this, n = "rtl" == document.documentElement.getAttribute("dir");
  191. this.removeFake(), this.fakeHandlerCallback = function () {
  192. return t.removeFake()
  193. }, this.fakeHandler = document.body.addEventListener("click", this.fakeHandlerCallback) || !0, 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 = "absolute", this.fakeElem.style[n ? "right" : "left"] = "-9999px";
  194. var o = window.pageYOffset || document.documentElement.scrollTop;
  195. this.fakeElem.style.top = o + "px", this.fakeElem.setAttribute("readonly", ""), this.fakeElem.value = this.text, document.body.appendChild(this.fakeElem), this.selectedText = (0, i.default)(this.fakeElem), this.copyText()
  196. }
  197. }, {
  198. key: "removeFake", value: function e() {
  199. this.fakeHandler && (document.body.removeEventListener("click", this.fakeHandlerCallback), this.fakeHandler = null, this.fakeHandlerCallback = null), this.fakeElem && (document.body.removeChild(this.fakeElem), this.fakeElem = null)
  200. }
  201. }, {
  202. key: "selectTarget", value: function e() {
  203. this.selectedText = (0, i.default)(this.target), this.copyText()
  204. }
  205. }, {
  206. key: "copyText", value: function e() {
  207. var t = void 0;
  208. try {
  209. t = document.execCommand(this.action)
  210. } catch (e) {
  211. t = !1
  212. }
  213. this.handleResult(t)
  214. }
  215. }, {
  216. key: "handleResult", value: function e(t) {
  217. this.emitter.emit(t ? "success" : "error", {
  218. action: this.action,
  219. text: this.selectedText,
  220. trigger: this.trigger,
  221. clearSelection: this.clearSelection.bind(this)
  222. })
  223. }
  224. }, {
  225. key: "clearSelection", value: function e() {
  226. this.target && this.target.blur(), window.getSelection().removeAllRanges()
  227. }
  228. }, {
  229. key: "destroy", value: function e() {
  230. this.removeFake()
  231. }
  232. }, {
  233. key: "action", set: function e() {
  234. var t = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : "copy";
  235. if (this._action = t, "copy" !== this._action && "cut" !== this._action)throw new Error('Invalid "action" value, use either "copy" or "cut"')
  236. }, get: function e() {
  237. return this._action
  238. }
  239. }, {
  240. key: "target", set: function e(t) {
  241. if (void 0 !== t) {
  242. if (!t || "object" !== ("undefined" == typeof t ? "undefined" : r(t)) || 1 !== t.nodeType)throw new Error('Invalid "target" value, use a valid Element');
  243. if ("copy" === this.action && t.hasAttribute("disabled"))throw new Error('Invalid "target" attribute. Please use "readonly" instead of "disabled" attribute');
  244. if ("cut" === this.action && (t.hasAttribute("readonly") || t.hasAttribute("disabled")))throw new Error('Invalid "target" attribute. You can\'t cut text from elements with "readonly" or "disabled" attributes');
  245. this._target = t
  246. }
  247. }, get: function e() {
  248. return this._target
  249. }
  250. }]), e
  251. }();
  252. e.exports = c
  253. })
  254. }, {select: 5}], 8: [function (t, n, o) {
  255. !function (i, r) {
  256. if ("function" == typeof e && e.amd)e(["module", "./clipboard-action", "tiny-emitter", "good-listener"], r); else if ("undefined" != typeof o)r(n, t("./clipboard-action"), t("tiny-emitter"), t("good-listener")); else {
  257. var a = {exports: {}};
  258. r(a, i.clipboardAction, i.tinyEmitter, i.goodListener), i.clipboard = a.exports
  259. }
  260. }(this, function (e, t, n, o) {
  261. "use strict";
  262. function i(e) {
  263. return e && e.__esModule ? e : {default: e}
  264. }
  265. function r(e, t) {
  266. if (!(e instanceof t))throw new TypeError("Cannot call a class as a function")
  267. }
  268. function a(e, t) {
  269. if (!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  270. return !t || "object" != typeof t && "function" != typeof t ? e : t
  271. }
  272. function c(e, t) {
  273. if ("function" != typeof t && null !== t)throw new TypeError("Super expression must either be null or a function, not " + typeof t);
  274. e.prototype = Object.create(t && t.prototype, {
  275. constructor: {
  276. value: e,
  277. enumerable: !1,
  278. writable: !0,
  279. configurable: !0
  280. }
  281. }), t && (Object.setPrototypeOf ? Object.setPrototypeOf(e, t) : e.__proto__ = t)
  282. }
  283. function l(e, t) {
  284. var n = "data-clipboard-" + e;
  285. if (t.hasAttribute(n))return t.getAttribute(n)
  286. }
  287. var u = i(t), s = i(n), f = i(o), d = function () {
  288. function e(e, t) {
  289. for (var n = 0; n < t.length; n++) {
  290. var o = t[n];
  291. o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, o.key, o)
  292. }
  293. }
  294. return function (t, n, o) {
  295. return n && e(t.prototype, n), o && e(t, o), t
  296. }
  297. }(), h = function (e) {
  298. function t(e, n) {
  299. r(this, t);
  300. var o = a(this, (t.__proto__ || Object.getPrototypeOf(t)).call(this));
  301. return o.resolveOptions(n), o.listenClick(e), o
  302. }
  303. return c(t, e), d(t, [{
  304. key: "resolveOptions", value: function e() {
  305. var t = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {};
  306. this.action = "function" == typeof t.action ? t.action : this.defaultAction, this.target = "function" == typeof t.target ? t.target : this.defaultTarget, this.text = "function" == typeof t.text ? t.text : this.defaultText
  307. }
  308. }, {
  309. key: "listenClick", value: function e(t) {
  310. var n = this;
  311. this.listener = (0, f.default)(t, "click", function (e) {
  312. return n.onClick(e)
  313. })
  314. }
  315. }, {
  316. key: "onClick", value: function e(t) {
  317. var n = t.delegateTarget || t.currentTarget;
  318. this.clipboardAction && (this.clipboardAction = null), this.clipboardAction = new u.default({
  319. action: this.action(n),
  320. target: this.target(n),
  321. text: this.text(n),
  322. trigger: n,
  323. emitter: this
  324. })
  325. }
  326. }, {
  327. key: "defaultAction", value: function e(t) {
  328. return l("action", t)
  329. }
  330. }, {
  331. key: "defaultTarget", value: function e(t) {
  332. var n = l("target", t);
  333. if (n)return document.querySelector(n)
  334. }
  335. }, {
  336. key: "defaultText", value: function e(t) {
  337. return l("text", t)
  338. }
  339. }, {
  340. key: "destroy", value: function e() {
  341. this.listener.destroy(), this.clipboardAction && (this.clipboardAction.destroy(), this.clipboardAction = null)
  342. }
  343. }], [{
  344. key: "isSupported", value: function e() {
  345. var t = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : ["copy", "cut"], n = "string" == typeof t ? [t] : t, o = !!document.queryCommandSupported;
  346. return n.forEach(function (e) {
  347. o = o && !!document.queryCommandSupported(e)
  348. }), o
  349. }
  350. }]), t
  351. }(s.default);
  352. e.exports = h
  353. })
  354. }, {"./clipboard-action": 7, "good-listener": 4, "tiny-emitter": 6}]
  355. }, {}, [8])(8)
  356. });