clipboard.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790
  1. /*!
  2. * clipboard.js v1.7.1
  3. * https://zenorocha.github.io/clipboard.js
  4. *
  5. * Licensed MIT © Zeno Rocha
  6. */
  7. (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Clipboard = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
  8. var DOCUMENT_NODE_TYPE = 9;
  9. /**
  10. * A polyfill for Element.matches()
  11. */
  12. if (typeof Element !== 'undefined' && !Element.prototype.matches) {
  13. var proto = Element.prototype;
  14. proto.matches = proto.matchesSelector ||
  15. proto.mozMatchesSelector ||
  16. proto.msMatchesSelector ||
  17. proto.oMatchesSelector ||
  18. proto.webkitMatchesSelector;
  19. }
  20. /**
  21. * Finds the closest parent that matches a selector.
  22. *
  23. * @param {Element} element
  24. * @param {String} selector
  25. * @return {Function}
  26. */
  27. function closest (element, selector) {
  28. while (element && element.nodeType !== DOCUMENT_NODE_TYPE) {
  29. if (typeof element.matches === 'function' &&
  30. element.matches(selector)) {
  31. return element;
  32. }
  33. element = element.parentNode;
  34. }
  35. }
  36. module.exports = closest;
  37. },{}],2:[function(require,module,exports){
  38. var closest = require('./closest');
  39. /**
  40. * Delegates event to a selector.
  41. *
  42. * @param {Element} element
  43. * @param {String} selector
  44. * @param {String} type
  45. * @param {Function} callback
  46. * @param {Boolean} useCapture
  47. * @return {Object}
  48. */
  49. function delegate(element, selector, type, callback, useCapture) {
  50. var listenerFn = listener.apply(this, arguments);
  51. element.addEventListener(type, listenerFn, useCapture);
  52. return {
  53. destroy: function() {
  54. element.removeEventListener(type, listenerFn, useCapture);
  55. }
  56. }
  57. }
  58. /**
  59. * Finds closest match and invokes callback.
  60. *
  61. * @param {Element} element
  62. * @param {String} selector
  63. * @param {String} type
  64. * @param {Function} callback
  65. * @return {Function}
  66. */
  67. function listener(element, selector, type, callback) {
  68. return function(e) {
  69. e.delegateTarget = closest(e.target, selector);
  70. if (e.delegateTarget) {
  71. callback.call(element, e);
  72. }
  73. }
  74. }
  75. module.exports = delegate;
  76. },{"./closest":1}],3:[function(require,module,exports){
  77. /**
  78. * Check if argument is a HTML element.
  79. *
  80. * @param {Object} value
  81. * @return {Boolean}
  82. */
  83. exports.node = function(value) {
  84. return value !== undefined
  85. && value instanceof HTMLElement
  86. && value.nodeType === 1;
  87. };
  88. /**
  89. * Check if argument is a list of HTML elements.
  90. *
  91. * @param {Object} value
  92. * @return {Boolean}
  93. */
  94. exports.nodeList = function(value) {
  95. var type = Object.prototype.toString.call(value);
  96. return value !== undefined
  97. && (type === '[object NodeList]' || type === '[object HTMLCollection]')
  98. && ('length' in value)
  99. && (value.length === 0 || exports.node(value[0]));
  100. };
  101. /**
  102. * Check if argument is a string.
  103. *
  104. * @param {Object} value
  105. * @return {Boolean}
  106. */
  107. exports.string = function(value) {
  108. return typeof value === 'string'
  109. || value instanceof String;
  110. };
  111. /**
  112. * Check if argument is a function.
  113. *
  114. * @param {Object} value
  115. * @return {Boolean}
  116. */
  117. exports.fn = function(value) {
  118. var type = Object.prototype.toString.call(value);
  119. return type === '[object Function]';
  120. };
  121. },{}],4:[function(require,module,exports){
  122. var is = require('./is');
  123. var delegate = require('delegate');
  124. /**
  125. * Validates all params and calls the right
  126. * listener function based on its target type.
  127. *
  128. * @param {String|HTMLElement|HTMLCollection|NodeList} target
  129. * @param {String} type
  130. * @param {Function} callback
  131. * @return {Object}
  132. */
  133. function listen(target, type, callback) {
  134. if (!target && !type && !callback) {
  135. throw new Error('Missing required arguments');
  136. }
  137. if (!is.string(type)) {
  138. throw new TypeError('Second argument must be a String');
  139. }
  140. if (!is.fn(callback)) {
  141. throw new TypeError('Third argument must be a Function');
  142. }
  143. if (is.node(target)) {
  144. return listenNode(target, type, callback);
  145. }
  146. else if (is.nodeList(target)) {
  147. return listenNodeList(target, type, callback);
  148. }
  149. else if (is.string(target)) {
  150. return listenSelector(target, type, callback);
  151. }
  152. else {
  153. throw new TypeError('First argument must be a String, HTMLElement, HTMLCollection, or NodeList');
  154. }
  155. }
  156. /**
  157. * Adds an event listener to a HTML element
  158. * and returns a remove listener function.
  159. *
  160. * @param {HTMLElement} node
  161. * @param {String} type
  162. * @param {Function} callback
  163. * @return {Object}
  164. */
  165. function listenNode(node, type, callback) {
  166. node.addEventListener(type, callback);
  167. return {
  168. destroy: function() {
  169. node.removeEventListener(type, callback);
  170. }
  171. }
  172. }
  173. /**
  174. * Add an event listener to a list of HTML elements
  175. * and returns a remove listener function.
  176. *
  177. * @param {NodeList|HTMLCollection} nodeList
  178. * @param {String} type
  179. * @param {Function} callback
  180. * @return {Object}
  181. */
  182. function listenNodeList(nodeList, type, callback) {
  183. Array.prototype.forEach.call(nodeList, function(node) {
  184. node.addEventListener(type, callback);
  185. });
  186. return {
  187. destroy: function() {
  188. Array.prototype.forEach.call(nodeList, function(node) {
  189. node.removeEventListener(type, callback);
  190. });
  191. }
  192. }
  193. }
  194. /**
  195. * Add an event listener to a selector
  196. * and returns a remove listener function.
  197. *
  198. * @param {String} selector
  199. * @param {String} type
  200. * @param {Function} callback
  201. * @return {Object}
  202. */
  203. function listenSelector(selector, type, callback) {
  204. return delegate(document.body, selector, type, callback);
  205. }
  206. module.exports = listen;
  207. },{"./is":3,"delegate":2}],5:[function(require,module,exports){
  208. function select(element) {
  209. var selectedText;
  210. if (element.nodeName === 'SELECT') {
  211. element.focus();
  212. selectedText = element.value;
  213. }
  214. else if (element.nodeName === 'INPUT' || element.nodeName === 'TEXTAREA') {
  215. var isReadOnly = element.hasAttribute('readonly');
  216. if (!isReadOnly) {
  217. element.setAttribute('readonly', '');
  218. }
  219. element.select();
  220. element.setSelectionRange(0, element.value.length);
  221. if (!isReadOnly) {
  222. element.removeAttribute('readonly');
  223. }
  224. selectedText = element.value;
  225. }
  226. else {
  227. if (element.hasAttribute('contenteditable')) {
  228. element.focus();
  229. }
  230. var selection = window.getSelection();
  231. var range = document.createRange();
  232. range.selectNodeContents(element);
  233. selection.removeAllRanges();
  234. selection.addRange(range);
  235. selectedText = selection.toString();
  236. }
  237. return selectedText;
  238. }
  239. module.exports = select;
  240. },{}],6:[function(require,module,exports){
  241. function E () {
  242. // Keep this empty so it's easier to inherit from
  243. // (via https://github.com/lipsmack from https://github.com/scottcorgan/tiny-emitter/issues/3)
  244. }
  245. E.prototype = {
  246. on: function (name, callback, ctx) {
  247. var e = this.e || (this.e = {});
  248. (e[name] || (e[name] = [])).push({
  249. fn: callback,
  250. ctx: ctx
  251. });
  252. return this;
  253. },
  254. once: function (name, callback, ctx) {
  255. var self = this;
  256. function listener () {
  257. self.off(name, listener);
  258. callback.apply(ctx, arguments);
  259. };
  260. listener._ = callback
  261. return this.on(name, listener, ctx);
  262. },
  263. emit: function (name) {
  264. var data = [].slice.call(arguments, 1);
  265. var evtArr = ((this.e || (this.e = {}))[name] || []).slice();
  266. var i = 0;
  267. var len = evtArr.length;
  268. for (i; i < len; i++) {
  269. evtArr[i].fn.apply(evtArr[i].ctx, data);
  270. }
  271. return this;
  272. },
  273. off: function (name, callback) {
  274. var e = this.e || (this.e = {});
  275. var evts = e[name];
  276. var liveEvents = [];
  277. if (evts && callback) {
  278. for (var i = 0, len = evts.length; i < len; i++) {
  279. if (evts[i].fn !== callback && evts[i].fn._ !== callback)
  280. liveEvents.push(evts[i]);
  281. }
  282. }
  283. // Remove event from queue to prevent memory leak
  284. // Suggested by https://github.com/lazd
  285. // Ref: https://github.com/scottcorgan/tiny-emitter/commit/c6ebfaa9bc973b33d110a84a307742b7cf94c953#commitcomment-5024910
  286. (liveEvents.length)
  287. ? e[name] = liveEvents
  288. : delete e[name];
  289. return this;
  290. }
  291. };
  292. module.exports = E;
  293. },{}],7:[function(require,module,exports){
  294. (function (global, factory) {
  295. if (typeof define === "function" && define.amd) {
  296. define(['module', 'select'], factory);
  297. } else if (typeof exports !== "undefined") {
  298. factory(module, require('select'));
  299. } else {
  300. var mod = {
  301. exports: {}
  302. };
  303. factory(mod, global.select);
  304. global.clipboardAction = mod.exports;
  305. }
  306. })(this, function (module, _select) {
  307. 'use strict';
  308. var _select2 = _interopRequireDefault(_select);
  309. function _interopRequireDefault(obj) {
  310. return obj && obj.__esModule ? obj : {
  311. default: obj
  312. };
  313. }
  314. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
  315. return typeof obj;
  316. } : function (obj) {
  317. return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
  318. };
  319. function _classCallCheck(instance, Constructor) {
  320. if (!(instance instanceof Constructor)) {
  321. throw new TypeError("Cannot call a class as a function");
  322. }
  323. }
  324. var _createClass = function () {
  325. function defineProperties(target, props) {
  326. for (var i = 0; i < props.length; i++) {
  327. var descriptor = props[i];
  328. descriptor.enumerable = descriptor.enumerable || false;
  329. descriptor.configurable = true;
  330. if ("value" in descriptor) descriptor.writable = true;
  331. Object.defineProperty(target, descriptor.key, descriptor);
  332. }
  333. }
  334. return function (Constructor, protoProps, staticProps) {
  335. if (protoProps) defineProperties(Constructor.prototype, protoProps);
  336. if (staticProps) defineProperties(Constructor, staticProps);
  337. return Constructor;
  338. };
  339. }();
  340. var ClipboardAction = function () {
  341. /**
  342. * @param {Object} options
  343. */
  344. function ClipboardAction(options) {
  345. _classCallCheck(this, ClipboardAction);
  346. this.resolveOptions(options);
  347. this.initSelection();
  348. }
  349. /**
  350. * Defines base properties passed from constructor.
  351. * @param {Object} options
  352. */
  353. _createClass(ClipboardAction, [{
  354. key: 'resolveOptions',
  355. value: function resolveOptions() {
  356. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  357. this.action = options.action;
  358. this.container = options.container;
  359. this.emitter = options.emitter;
  360. this.target = options.target;
  361. this.text = options.text;
  362. this.trigger = options.trigger;
  363. this.selectedText = '';
  364. }
  365. }, {
  366. key: 'initSelection',
  367. value: function initSelection() {
  368. if (this.text) {
  369. this.selectFake();
  370. } else if (this.target) {
  371. this.selectTarget();
  372. }
  373. }
  374. }, {
  375. key: 'selectFake',
  376. value: function selectFake() {
  377. var _this = this;
  378. var isRTL = document.documentElement.getAttribute('dir') == 'rtl';
  379. this.removeFake();
  380. this.fakeHandlerCallback = function () {
  381. return _this.removeFake();
  382. };
  383. this.fakeHandler = this.container.addEventListener('click', this.fakeHandlerCallback) || true;
  384. this.fakeElem = document.createElement('textarea');
  385. // Prevent zooming on iOS
  386. this.fakeElem.style.fontSize = '12pt';
  387. // Reset box model
  388. this.fakeElem.style.border = '0';
  389. this.fakeElem.style.padding = '0';
  390. this.fakeElem.style.margin = '0';
  391. // Move element out of screen horizontally
  392. this.fakeElem.style.position = 'absolute';
  393. this.fakeElem.style[isRTL ? 'right' : 'left'] = '-9999px';
  394. // Move element to the same position vertically
  395. var yPosition = window.pageYOffset || document.documentElement.scrollTop;
  396. this.fakeElem.style.top = yPosition + 'px';
  397. this.fakeElem.setAttribute('readonly', '');
  398. this.fakeElem.value = this.text;
  399. this.container.appendChild(this.fakeElem);
  400. this.selectedText = (0, _select2.default)(this.fakeElem);
  401. this.copyText();
  402. }
  403. }, {
  404. key: 'removeFake',
  405. value: function removeFake() {
  406. if (this.fakeHandler) {
  407. this.container.removeEventListener('click', this.fakeHandlerCallback);
  408. this.fakeHandler = null;
  409. this.fakeHandlerCallback = null;
  410. }
  411. if (this.fakeElem) {
  412. this.container.removeChild(this.fakeElem);
  413. this.fakeElem = null;
  414. }
  415. }
  416. }, {
  417. key: 'selectTarget',
  418. value: function selectTarget() {
  419. this.selectedText = (0, _select2.default)(this.target);
  420. this.copyText();
  421. }
  422. }, {
  423. key: 'copyText',
  424. value: function copyText() {
  425. var succeeded = void 0;
  426. try {
  427. succeeded = document.execCommand(this.action);
  428. } catch (err) {
  429. succeeded = false;
  430. }
  431. this.handleResult(succeeded);
  432. }
  433. }, {
  434. key: 'handleResult',
  435. value: function handleResult(succeeded) {
  436. this.emitter.emit(succeeded ? 'success' : 'error', {
  437. action: this.action,
  438. text: this.selectedText,
  439. trigger: this.trigger,
  440. clearSelection: this.clearSelection.bind(this)
  441. });
  442. }
  443. }, {
  444. key: 'clearSelection',
  445. value: function clearSelection() {
  446. if (this.trigger) {
  447. this.trigger.focus();
  448. }
  449. window.getSelection().removeAllRanges();
  450. }
  451. }, {
  452. key: 'destroy',
  453. value: function destroy() {
  454. this.removeFake();
  455. }
  456. }, {
  457. key: 'action',
  458. set: function set() {
  459. var action = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'copy';
  460. this._action = action;
  461. if (this._action !== 'copy' && this._action !== 'cut') {
  462. throw new Error('Invalid "action" value, use either "copy" or "cut"');
  463. }
  464. },
  465. get: function get() {
  466. return this._action;
  467. }
  468. }, {
  469. key: 'target',
  470. set: function set(target) {
  471. if (target !== undefined) {
  472. if (target && (typeof target === 'undefined' ? 'undefined' : _typeof(target)) === 'object' && target.nodeType === 1) {
  473. if (this.action === 'copy' && target.hasAttribute('disabled')) {
  474. throw new Error('Invalid "target" attribute. Please use "readonly" instead of "disabled" attribute');
  475. }
  476. if (this.action === 'cut' && (target.hasAttribute('readonly') || target.hasAttribute('disabled'))) {
  477. throw new Error('Invalid "target" attribute. You can\'t cut text from elements with "readonly" or "disabled" attributes');
  478. }
  479. this._target = target;
  480. } else {
  481. throw new Error('Invalid "target" value, use a valid Element');
  482. }
  483. }
  484. },
  485. get: function get() {
  486. return this._target;
  487. }
  488. }]);
  489. return ClipboardAction;
  490. }();
  491. module.exports = ClipboardAction;
  492. });
  493. },{"select":5}],8:[function(require,module,exports){
  494. (function (global, factory) {
  495. if (typeof define === "function" && define.amd) {
  496. define(['module', './clipboard-action', 'tiny-emitter', 'good-listener'], factory);
  497. } else if (typeof exports !== "undefined") {
  498. factory(module, require('./clipboard-action'), require('tiny-emitter'), require('good-listener'));
  499. } else {
  500. var mod = {
  501. exports: {}
  502. };
  503. factory(mod, global.clipboardAction, global.tinyEmitter, global.goodListener);
  504. global.clipboard = mod.exports;
  505. }
  506. })(this, function (module, _clipboardAction, _tinyEmitter, _goodListener) {
  507. 'use strict';
  508. var _clipboardAction2 = _interopRequireDefault(_clipboardAction);
  509. var _tinyEmitter2 = _interopRequireDefault(_tinyEmitter);
  510. var _goodListener2 = _interopRequireDefault(_goodListener);
  511. function _interopRequireDefault(obj) {
  512. return obj && obj.__esModule ? obj : {
  513. default: obj
  514. };
  515. }
  516. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
  517. return typeof obj;
  518. } : function (obj) {
  519. return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
  520. };
  521. function _classCallCheck(instance, Constructor) {
  522. if (!(instance instanceof Constructor)) {
  523. throw new TypeError("Cannot call a class as a function");
  524. }
  525. }
  526. var _createClass = function () {
  527. function defineProperties(target, props) {
  528. for (var i = 0; i < props.length; i++) {
  529. var descriptor = props[i];
  530. descriptor.enumerable = descriptor.enumerable || false;
  531. descriptor.configurable = true;
  532. if ("value" in descriptor) descriptor.writable = true;
  533. Object.defineProperty(target, descriptor.key, descriptor);
  534. }
  535. }
  536. return function (Constructor, protoProps, staticProps) {
  537. if (protoProps) defineProperties(Constructor.prototype, protoProps);
  538. if (staticProps) defineProperties(Constructor, staticProps);
  539. return Constructor;
  540. };
  541. }();
  542. function _possibleConstructorReturn(self, call) {
  543. if (!self) {
  544. throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  545. }
  546. return call && (typeof call === "object" || typeof call === "function") ? call : self;
  547. }
  548. function _inherits(subClass, superClass) {
  549. if (typeof superClass !== "function" && superClass !== null) {
  550. throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
  551. }
  552. subClass.prototype = Object.create(superClass && superClass.prototype, {
  553. constructor: {
  554. value: subClass,
  555. enumerable: false,
  556. writable: true,
  557. configurable: true
  558. }
  559. });
  560. if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
  561. }
  562. var Clipboard = function (_Emitter) {
  563. _inherits(Clipboard, _Emitter);
  564. /**
  565. * @param {String|HTMLElement|HTMLCollection|NodeList} trigger
  566. * @param {Object} options
  567. */
  568. function Clipboard(trigger, options) {
  569. _classCallCheck(this, Clipboard);
  570. var _this = _possibleConstructorReturn(this, (Clipboard.__proto__ || Object.getPrototypeOf(Clipboard)).call(this));
  571. _this.resolveOptions(options);
  572. _this.listenClick(trigger);
  573. return _this;
  574. }
  575. /**
  576. * Defines if attributes would be resolved using internal setter functions
  577. * or custom functions that were passed in the constructor.
  578. * @param {Object} options
  579. */
  580. _createClass(Clipboard, [{
  581. key: 'resolveOptions',
  582. value: function resolveOptions() {
  583. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  584. this.action = typeof options.action === 'function' ? options.action : this.defaultAction;
  585. this.target = typeof options.target === 'function' ? options.target : this.defaultTarget;
  586. this.text = typeof options.text === 'function' ? options.text : this.defaultText;
  587. this.container = _typeof(options.container) === 'object' ? options.container : document.body;
  588. }
  589. }, {
  590. key: 'listenClick',
  591. value: function listenClick(trigger) {
  592. var _this2 = this;
  593. this.listener = (0, _goodListener2.default)(trigger, 'click', function (e) {
  594. return _this2.onClick(e);
  595. });
  596. }
  597. }, {
  598. key: 'onClick',
  599. value: function onClick(e) {
  600. var trigger = e.delegateTarget || e.currentTarget;
  601. if (this.clipboardAction) {
  602. this.clipboardAction = null;
  603. }
  604. this.clipboardAction = new _clipboardAction2.default({
  605. action: this.action(trigger),
  606. target: this.target(trigger),
  607. text: this.text(trigger),
  608. container: this.container,
  609. trigger: trigger,
  610. emitter: this
  611. });
  612. }
  613. }, {
  614. key: 'defaultAction',
  615. value: function defaultAction(trigger) {
  616. return getAttributeValue('action', trigger);
  617. }
  618. }, {
  619. key: 'defaultTarget',
  620. value: function defaultTarget(trigger) {
  621. var selector = getAttributeValue('target', trigger);
  622. if (selector) {
  623. return document.querySelector(selector);
  624. }
  625. }
  626. }, {
  627. key: 'defaultText',
  628. value: function defaultText(trigger) {
  629. return getAttributeValue('text', trigger);
  630. }
  631. }, {
  632. key: 'destroy',
  633. value: function destroy() {
  634. this.listener.destroy();
  635. if (this.clipboardAction) {
  636. this.clipboardAction.destroy();
  637. this.clipboardAction = null;
  638. }
  639. }
  640. }], [{
  641. key: 'isSupported',
  642. value: function isSupported() {
  643. var action = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ['copy', 'cut'];
  644. var actions = typeof action === 'string' ? [action] : action;
  645. var support = !!document.queryCommandSupported;
  646. actions.forEach(function (action) {
  647. support = support && !!document.queryCommandSupported(action);
  648. });
  649. return support;
  650. }
  651. }]);
  652. return Clipboard;
  653. }(_tinyEmitter2.default);
  654. /**
  655. * Helper function to retrieve attribute value.
  656. * @param {String} suffix
  657. * @param {Element} element
  658. */
  659. function getAttributeValue(suffix, element) {
  660. var attribute = 'data-clipboard-' + suffix;
  661. if (!element.hasAttribute(attribute)) {
  662. return;
  663. }
  664. return element.getAttribute(attribute);
  665. }
  666. module.exports = Clipboard;
  667. });
  668. },{"./clipboard-action":7,"good-listener":4,"tiny-emitter":6}]},{},[8])(8)
  669. });