clipboard.js 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954
  1. /*!
  2. * clipboard.js v2.0.8
  3. * https://clipboardjs.com/
  4. *
  5. * Licensed MIT © Zeno Rocha
  6. */
  7. (function webpackUniversalModuleDefinition(root, factory) {
  8. if(typeof exports === 'object' && typeof module === 'object')
  9. module.exports = factory();
  10. else if(typeof define === 'function' && define.amd)
  11. define([], factory);
  12. else if(typeof exports === 'object')
  13. exports["ClipboardJS"] = factory();
  14. else
  15. root["ClipboardJS"] = factory();
  16. })(this, function() {
  17. return /******/ (function() { // webpackBootstrap
  18. /******/ var __webpack_modules__ = ({
  19. /***/ 134:
  20. /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
  21. "use strict";
  22. // EXPORTS
  23. __webpack_require__.d(__webpack_exports__, {
  24. "default": function() { return /* binding */ clipboard; }
  25. });
  26. // EXTERNAL MODULE: ./node_modules/tiny-emitter/index.js
  27. var tiny_emitter = __webpack_require__(279);
  28. var tiny_emitter_default = /*#__PURE__*/__webpack_require__.n(tiny_emitter);
  29. // EXTERNAL MODULE: ./node_modules/good-listener/src/listen.js
  30. var listen = __webpack_require__(370);
  31. var listen_default = /*#__PURE__*/__webpack_require__.n(listen);
  32. // EXTERNAL MODULE: ./node_modules/select/src/select.js
  33. var src_select = __webpack_require__(817);
  34. var select_default = /*#__PURE__*/__webpack_require__.n(src_select);
  35. ;// CONCATENATED MODULE: ./src/clipboard-action.js
  36. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  37. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  38. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  39. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  40. /**
  41. * Inner class which performs selection from either `text` or `target`
  42. * properties and then executes copy or cut operations.
  43. */
  44. var ClipboardAction = /*#__PURE__*/function () {
  45. /**
  46. * @param {Object} options
  47. */
  48. function ClipboardAction(options) {
  49. _classCallCheck(this, ClipboardAction);
  50. this.resolveOptions(options);
  51. this.initSelection();
  52. }
  53. /**
  54. * Defines base properties passed from constructor.
  55. * @param {Object} options
  56. */
  57. _createClass(ClipboardAction, [{
  58. key: "resolveOptions",
  59. value: function resolveOptions() {
  60. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  61. this.action = options.action;
  62. this.container = options.container;
  63. this.emitter = options.emitter;
  64. this.target = options.target;
  65. this.text = options.text;
  66. this.trigger = options.trigger;
  67. this.selectedText = '';
  68. }
  69. /**
  70. * Decides which selection strategy is going to be applied based
  71. * on the existence of `text` and `target` properties.
  72. */
  73. }, {
  74. key: "initSelection",
  75. value: function initSelection() {
  76. if (this.text) {
  77. this.selectFake();
  78. } else if (this.target) {
  79. this.selectTarget();
  80. }
  81. }
  82. /**
  83. * Creates a fake textarea element, sets its value from `text` property,
  84. */
  85. }, {
  86. key: "createFakeElement",
  87. value: function createFakeElement() {
  88. var isRTL = document.documentElement.getAttribute('dir') === 'rtl';
  89. this.fakeElem = document.createElement('textarea'); // Prevent zooming on iOS
  90. this.fakeElem.style.fontSize = '12pt'; // Reset box model
  91. this.fakeElem.style.border = '0';
  92. this.fakeElem.style.padding = '0';
  93. this.fakeElem.style.margin = '0'; // Move element out of screen horizontally
  94. this.fakeElem.style.position = 'absolute';
  95. this.fakeElem.style[isRTL ? 'right' : 'left'] = '-9999px'; // Move element to the same position vertically
  96. var yPosition = window.pageYOffset || document.documentElement.scrollTop;
  97. this.fakeElem.style.top = "".concat(yPosition, "px");
  98. this.fakeElem.setAttribute('readonly', '');
  99. this.fakeElem.value = this.text;
  100. return this.fakeElem;
  101. }
  102. /**
  103. * Get's the value of fakeElem,
  104. * and makes a selection on it.
  105. */
  106. }, {
  107. key: "selectFake",
  108. value: function selectFake() {
  109. var _this = this;
  110. var fakeElem = this.createFakeElement();
  111. this.fakeHandlerCallback = function () {
  112. return _this.removeFake();
  113. };
  114. this.fakeHandler = this.container.addEventListener('click', this.fakeHandlerCallback) || true;
  115. this.container.appendChild(fakeElem);
  116. this.selectedText = select_default()(fakeElem);
  117. this.copyText();
  118. this.removeFake();
  119. }
  120. /**
  121. * Only removes the fake element after another click event, that way
  122. * a user can hit `Ctrl+C` to copy because selection still exists.
  123. */
  124. }, {
  125. key: "removeFake",
  126. value: function removeFake() {
  127. if (this.fakeHandler) {
  128. this.container.removeEventListener('click', this.fakeHandlerCallback);
  129. this.fakeHandler = null;
  130. this.fakeHandlerCallback = null;
  131. }
  132. if (this.fakeElem) {
  133. this.container.removeChild(this.fakeElem);
  134. this.fakeElem = null;
  135. }
  136. }
  137. /**
  138. * Selects the content from element passed on `target` property.
  139. */
  140. }, {
  141. key: "selectTarget",
  142. value: function selectTarget() {
  143. this.selectedText = select_default()(this.target);
  144. this.copyText();
  145. }
  146. /**
  147. * Executes the copy operation based on the current selection.
  148. */
  149. }, {
  150. key: "copyText",
  151. value: function copyText() {
  152. var succeeded;
  153. try {
  154. succeeded = document.execCommand(this.action);
  155. } catch (err) {
  156. succeeded = false;
  157. }
  158. this.handleResult(succeeded);
  159. }
  160. /**
  161. * Fires an event based on the copy operation result.
  162. * @param {Boolean} succeeded
  163. */
  164. }, {
  165. key: "handleResult",
  166. value: function handleResult(succeeded) {
  167. this.emitter.emit(succeeded ? 'success' : 'error', {
  168. action: this.action,
  169. text: this.selectedText,
  170. trigger: this.trigger,
  171. clearSelection: this.clearSelection.bind(this)
  172. });
  173. }
  174. /**
  175. * Moves focus away from `target` and back to the trigger, removes current selection.
  176. */
  177. }, {
  178. key: "clearSelection",
  179. value: function clearSelection() {
  180. if (this.trigger) {
  181. this.trigger.focus();
  182. }
  183. document.activeElement.blur();
  184. window.getSelection().removeAllRanges();
  185. }
  186. /**
  187. * Sets the `action` to be performed which can be either 'copy' or 'cut'.
  188. * @param {String} action
  189. */
  190. }, {
  191. key: "destroy",
  192. /**
  193. * Destroy lifecycle.
  194. */
  195. value: function destroy() {
  196. this.removeFake();
  197. }
  198. }, {
  199. key: "action",
  200. set: function set() {
  201. var action = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'copy';
  202. this._action = action;
  203. if (this._action !== 'copy' && this._action !== 'cut') {
  204. throw new Error('Invalid "action" value, use either "copy" or "cut"');
  205. }
  206. }
  207. /**
  208. * Gets the `action` property.
  209. * @return {String}
  210. */
  211. ,
  212. get: function get() {
  213. return this._action;
  214. }
  215. /**
  216. * Sets the `target` property using an element
  217. * that will be have its content copied.
  218. * @param {Element} target
  219. */
  220. }, {
  221. key: "target",
  222. set: function set(target) {
  223. if (target !== undefined) {
  224. if (target && _typeof(target) === 'object' && target.nodeType === 1) {
  225. if (this.action === 'copy' && target.hasAttribute('disabled')) {
  226. throw new Error('Invalid "target" attribute. Please use "readonly" instead of "disabled" attribute');
  227. }
  228. if (this.action === 'cut' && (target.hasAttribute('readonly') || target.hasAttribute('disabled'))) {
  229. throw new Error('Invalid "target" attribute. You can\'t cut text from elements with "readonly" or "disabled" attributes');
  230. }
  231. this._target = target;
  232. } else {
  233. throw new Error('Invalid "target" value, use a valid Element');
  234. }
  235. }
  236. }
  237. /**
  238. * Gets the `target` property.
  239. * @return {String|HTMLElement}
  240. */
  241. ,
  242. get: function get() {
  243. return this._target;
  244. }
  245. }]);
  246. return ClipboardAction;
  247. }();
  248. /* harmony default export */ var clipboard_action = (ClipboardAction);
  249. ;// CONCATENATED MODULE: ./src/clipboard.js
  250. function clipboard_typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { clipboard_typeof = function _typeof(obj) { return typeof obj; }; } else { clipboard_typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return clipboard_typeof(obj); }
  251. function clipboard_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  252. function clipboard_defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  253. function clipboard_createClass(Constructor, protoProps, staticProps) { if (protoProps) clipboard_defineProperties(Constructor.prototype, protoProps); if (staticProps) clipboard_defineProperties(Constructor, staticProps); return Constructor; }
  254. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  255. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  256. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  257. function _possibleConstructorReturn(self, call) { if (call && (clipboard_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  258. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  259. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  260. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  261. /**
  262. * Helper function to retrieve attribute value.
  263. * @param {String} suffix
  264. * @param {Element} element
  265. */
  266. function getAttributeValue(suffix, element) {
  267. var attribute = "data-clipboard-".concat(suffix);
  268. if (!element.hasAttribute(attribute)) {
  269. return;
  270. }
  271. return element.getAttribute(attribute);
  272. }
  273. /**
  274. * Base class which takes one or more elements, adds event listeners to them,
  275. * and instantiates a new `ClipboardAction` on each click.
  276. */
  277. var Clipboard = /*#__PURE__*/function (_Emitter) {
  278. _inherits(Clipboard, _Emitter);
  279. var _super = _createSuper(Clipboard);
  280. /**
  281. * @param {String|HTMLElement|HTMLCollection|NodeList} trigger
  282. * @param {Object} options
  283. */
  284. function Clipboard(trigger, options) {
  285. var _this;
  286. clipboard_classCallCheck(this, Clipboard);
  287. _this = _super.call(this);
  288. _this.resolveOptions(options);
  289. _this.listenClick(trigger);
  290. return _this;
  291. }
  292. /**
  293. * Defines if attributes would be resolved using internal setter functions
  294. * or custom functions that were passed in the constructor.
  295. * @param {Object} options
  296. */
  297. clipboard_createClass(Clipboard, [{
  298. key: "resolveOptions",
  299. value: function resolveOptions() {
  300. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  301. this.action = typeof options.action === 'function' ? options.action : this.defaultAction;
  302. this.target = typeof options.target === 'function' ? options.target : this.defaultTarget;
  303. this.text = typeof options.text === 'function' ? options.text : this.defaultText;
  304. this.container = clipboard_typeof(options.container) === 'object' ? options.container : document.body;
  305. }
  306. /**
  307. * Adds a click event listener to the passed trigger.
  308. * @param {String|HTMLElement|HTMLCollection|NodeList} trigger
  309. */
  310. }, {
  311. key: "listenClick",
  312. value: function listenClick(trigger) {
  313. var _this2 = this;
  314. this.listener = listen_default()(trigger, 'click', function (e) {
  315. return _this2.onClick(e);
  316. });
  317. }
  318. /**
  319. * Defines a new `ClipboardAction` on each click event.
  320. * @param {Event} e
  321. */
  322. }, {
  323. key: "onClick",
  324. value: function onClick(e) {
  325. var trigger = e.delegateTarget || e.currentTarget;
  326. if (this.clipboardAction) {
  327. this.clipboardAction = null;
  328. }
  329. this.clipboardAction = new clipboard_action({
  330. action: this.action(trigger),
  331. target: this.target(trigger),
  332. text: this.text(trigger),
  333. container: this.container,
  334. trigger: trigger,
  335. emitter: this
  336. });
  337. }
  338. /**
  339. * Default `action` lookup function.
  340. * @param {Element} trigger
  341. */
  342. }, {
  343. key: "defaultAction",
  344. value: function defaultAction(trigger) {
  345. return getAttributeValue('action', trigger);
  346. }
  347. /**
  348. * Default `target` lookup function.
  349. * @param {Element} trigger
  350. */
  351. }, {
  352. key: "defaultTarget",
  353. value: function defaultTarget(trigger) {
  354. var selector = getAttributeValue('target', trigger);
  355. if (selector) {
  356. return document.querySelector(selector);
  357. }
  358. }
  359. /**
  360. * Returns the support of the given action, or all actions if no action is
  361. * given.
  362. * @param {String} [action]
  363. */
  364. }, {
  365. key: "defaultText",
  366. /**
  367. * Default `text` lookup function.
  368. * @param {Element} trigger
  369. */
  370. value: function defaultText(trigger) {
  371. return getAttributeValue('text', trigger);
  372. }
  373. /**
  374. * Destroy lifecycle.
  375. */
  376. }, {
  377. key: "destroy",
  378. value: function destroy() {
  379. this.listener.destroy();
  380. if (this.clipboardAction) {
  381. this.clipboardAction.destroy();
  382. this.clipboardAction = null;
  383. }
  384. }
  385. }], [{
  386. key: "isSupported",
  387. value: function isSupported() {
  388. var action = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ['copy', 'cut'];
  389. var actions = typeof action === 'string' ? [action] : action;
  390. var support = !!document.queryCommandSupported;
  391. actions.forEach(function (action) {
  392. support = support && !!document.queryCommandSupported(action);
  393. });
  394. return support;
  395. }
  396. }]);
  397. return Clipboard;
  398. }((tiny_emitter_default()));
  399. /* harmony default export */ var clipboard = (Clipboard);
  400. /***/ }),
  401. /***/ 828:
  402. /***/ (function(module) {
  403. var DOCUMENT_NODE_TYPE = 9;
  404. /**
  405. * A polyfill for Element.matches()
  406. */
  407. if (typeof Element !== 'undefined' && !Element.prototype.matches) {
  408. var proto = Element.prototype;
  409. proto.matches = proto.matchesSelector ||
  410. proto.mozMatchesSelector ||
  411. proto.msMatchesSelector ||
  412. proto.oMatchesSelector ||
  413. proto.webkitMatchesSelector;
  414. }
  415. /**
  416. * Finds the closest parent that matches a selector.
  417. *
  418. * @param {Element} element
  419. * @param {String} selector
  420. * @return {Function}
  421. */
  422. function closest (element, selector) {
  423. while (element && element.nodeType !== DOCUMENT_NODE_TYPE) {
  424. if (typeof element.matches === 'function' &&
  425. element.matches(selector)) {
  426. return element;
  427. }
  428. element = element.parentNode;
  429. }
  430. }
  431. module.exports = closest;
  432. /***/ }),
  433. /***/ 438:
  434. /***/ (function(module, __unused_webpack_exports, __webpack_require__) {
  435. var closest = __webpack_require__(828);
  436. /**
  437. * Delegates event to a selector.
  438. *
  439. * @param {Element} element
  440. * @param {String} selector
  441. * @param {String} type
  442. * @param {Function} callback
  443. * @param {Boolean} useCapture
  444. * @return {Object}
  445. */
  446. function _delegate(element, selector, type, callback, useCapture) {
  447. var listenerFn = listener.apply(this, arguments);
  448. element.addEventListener(type, listenerFn, useCapture);
  449. return {
  450. destroy: function() {
  451. element.removeEventListener(type, listenerFn, useCapture);
  452. }
  453. }
  454. }
  455. /**
  456. * Delegates event to a selector.
  457. *
  458. * @param {Element|String|Array} [elements]
  459. * @param {String} selector
  460. * @param {String} type
  461. * @param {Function} callback
  462. * @param {Boolean} useCapture
  463. * @return {Object}
  464. */
  465. function delegate(elements, selector, type, callback, useCapture) {
  466. // Handle the regular Element usage
  467. if (typeof elements.addEventListener === 'function') {
  468. return _delegate.apply(null, arguments);
  469. }
  470. // Handle Element-less usage, it defaults to global delegation
  471. if (typeof type === 'function') {
  472. // Use `document` as the first parameter, then apply arguments
  473. // This is a short way to .unshift `arguments` without running into deoptimizations
  474. return _delegate.bind(null, document).apply(null, arguments);
  475. }
  476. // Handle Selector-based usage
  477. if (typeof elements === 'string') {
  478. elements = document.querySelectorAll(elements);
  479. }
  480. // Handle Array-like based usage
  481. return Array.prototype.map.call(elements, function (element) {
  482. return _delegate(element, selector, type, callback, useCapture);
  483. });
  484. }
  485. /**
  486. * Finds closest match and invokes callback.
  487. *
  488. * @param {Element} element
  489. * @param {String} selector
  490. * @param {String} type
  491. * @param {Function} callback
  492. * @return {Function}
  493. */
  494. function listener(element, selector, type, callback) {
  495. return function(e) {
  496. e.delegateTarget = closest(e.target, selector);
  497. if (e.delegateTarget) {
  498. callback.call(element, e);
  499. }
  500. }
  501. }
  502. module.exports = delegate;
  503. /***/ }),
  504. /***/ 879:
  505. /***/ (function(__unused_webpack_module, exports) {
  506. /**
  507. * Check if argument is a HTML element.
  508. *
  509. * @param {Object} value
  510. * @return {Boolean}
  511. */
  512. exports.node = function(value) {
  513. return value !== undefined
  514. && value instanceof HTMLElement
  515. && value.nodeType === 1;
  516. };
  517. /**
  518. * Check if argument is a list of HTML elements.
  519. *
  520. * @param {Object} value
  521. * @return {Boolean}
  522. */
  523. exports.nodeList = function(value) {
  524. var type = Object.prototype.toString.call(value);
  525. return value !== undefined
  526. && (type === '[object NodeList]' || type === '[object HTMLCollection]')
  527. && ('length' in value)
  528. && (value.length === 0 || exports.node(value[0]));
  529. };
  530. /**
  531. * Check if argument is a string.
  532. *
  533. * @param {Object} value
  534. * @return {Boolean}
  535. */
  536. exports.string = function(value) {
  537. return typeof value === 'string'
  538. || value instanceof String;
  539. };
  540. /**
  541. * Check if argument is a function.
  542. *
  543. * @param {Object} value
  544. * @return {Boolean}
  545. */
  546. exports.fn = function(value) {
  547. var type = Object.prototype.toString.call(value);
  548. return type === '[object Function]';
  549. };
  550. /***/ }),
  551. /***/ 370:
  552. /***/ (function(module, __unused_webpack_exports, __webpack_require__) {
  553. var is = __webpack_require__(879);
  554. var delegate = __webpack_require__(438);
  555. /**
  556. * Validates all params and calls the right
  557. * listener function based on its target type.
  558. *
  559. * @param {String|HTMLElement|HTMLCollection|NodeList} target
  560. * @param {String} type
  561. * @param {Function} callback
  562. * @return {Object}
  563. */
  564. function listen(target, type, callback) {
  565. if (!target && !type && !callback) {
  566. throw new Error('Missing required arguments');
  567. }
  568. if (!is.string(type)) {
  569. throw new TypeError('Second argument must be a String');
  570. }
  571. if (!is.fn(callback)) {
  572. throw new TypeError('Third argument must be a Function');
  573. }
  574. if (is.node(target)) {
  575. return listenNode(target, type, callback);
  576. }
  577. else if (is.nodeList(target)) {
  578. return listenNodeList(target, type, callback);
  579. }
  580. else if (is.string(target)) {
  581. return listenSelector(target, type, callback);
  582. }
  583. else {
  584. throw new TypeError('First argument must be a String, HTMLElement, HTMLCollection, or NodeList');
  585. }
  586. }
  587. /**
  588. * Adds an event listener to a HTML element
  589. * and returns a remove listener function.
  590. *
  591. * @param {HTMLElement} node
  592. * @param {String} type
  593. * @param {Function} callback
  594. * @return {Object}
  595. */
  596. function listenNode(node, type, callback) {
  597. node.addEventListener(type, callback);
  598. return {
  599. destroy: function() {
  600. node.removeEventListener(type, callback);
  601. }
  602. }
  603. }
  604. /**
  605. * Add an event listener to a list of HTML elements
  606. * and returns a remove listener function.
  607. *
  608. * @param {NodeList|HTMLCollection} nodeList
  609. * @param {String} type
  610. * @param {Function} callback
  611. * @return {Object}
  612. */
  613. function listenNodeList(nodeList, type, callback) {
  614. Array.prototype.forEach.call(nodeList, function(node) {
  615. node.addEventListener(type, callback);
  616. });
  617. return {
  618. destroy: function() {
  619. Array.prototype.forEach.call(nodeList, function(node) {
  620. node.removeEventListener(type, callback);
  621. });
  622. }
  623. }
  624. }
  625. /**
  626. * Add an event listener to a selector
  627. * and returns a remove listener function.
  628. *
  629. * @param {String} selector
  630. * @param {String} type
  631. * @param {Function} callback
  632. * @return {Object}
  633. */
  634. function listenSelector(selector, type, callback) {
  635. return delegate(document.body, selector, type, callback);
  636. }
  637. module.exports = listen;
  638. /***/ }),
  639. /***/ 817:
  640. /***/ (function(module) {
  641. function select(element) {
  642. var selectedText;
  643. if (element.nodeName === 'SELECT') {
  644. element.focus();
  645. selectedText = element.value;
  646. }
  647. else if (element.nodeName === 'INPUT' || element.nodeName === 'TEXTAREA') {
  648. var isReadOnly = element.hasAttribute('readonly');
  649. if (!isReadOnly) {
  650. element.setAttribute('readonly', '');
  651. }
  652. element.select();
  653. element.setSelectionRange(0, element.value.length);
  654. if (!isReadOnly) {
  655. element.removeAttribute('readonly');
  656. }
  657. selectedText = element.value;
  658. }
  659. else {
  660. if (element.hasAttribute('contenteditable')) {
  661. element.focus();
  662. }
  663. var selection = window.getSelection();
  664. var range = document.createRange();
  665. range.selectNodeContents(element);
  666. selection.removeAllRanges();
  667. selection.addRange(range);
  668. selectedText = selection.toString();
  669. }
  670. return selectedText;
  671. }
  672. module.exports = select;
  673. /***/ }),
  674. /***/ 279:
  675. /***/ (function(module) {
  676. function E () {
  677. // Keep this empty so it's easier to inherit from
  678. // (via https://github.com/lipsmack from https://github.com/scottcorgan/tiny-emitter/issues/3)
  679. }
  680. E.prototype = {
  681. on: function (name, callback, ctx) {
  682. var e = this.e || (this.e = {});
  683. (e[name] || (e[name] = [])).push({
  684. fn: callback,
  685. ctx: ctx
  686. });
  687. return this;
  688. },
  689. once: function (name, callback, ctx) {
  690. var self = this;
  691. function listener () {
  692. self.off(name, listener);
  693. callback.apply(ctx, arguments);
  694. };
  695. listener._ = callback
  696. return this.on(name, listener, ctx);
  697. },
  698. emit: function (name) {
  699. var data = [].slice.call(arguments, 1);
  700. var evtArr = ((this.e || (this.e = {}))[name] || []).slice();
  701. var i = 0;
  702. var len = evtArr.length;
  703. for (i; i < len; i++) {
  704. evtArr[i].fn.apply(evtArr[i].ctx, data);
  705. }
  706. return this;
  707. },
  708. off: function (name, callback) {
  709. var e = this.e || (this.e = {});
  710. var evts = e[name];
  711. var liveEvents = [];
  712. if (evts && callback) {
  713. for (var i = 0, len = evts.length; i < len; i++) {
  714. if (evts[i].fn !== callback && evts[i].fn._ !== callback)
  715. liveEvents.push(evts[i]);
  716. }
  717. }
  718. // Remove event from queue to prevent memory leak
  719. // Suggested by https://github.com/lazd
  720. // Ref: https://github.com/scottcorgan/tiny-emitter/commit/c6ebfaa9bc973b33d110a84a307742b7cf94c953#commitcomment-5024910
  721. (liveEvents.length)
  722. ? e[name] = liveEvents
  723. : delete e[name];
  724. return this;
  725. }
  726. };
  727. module.exports = E;
  728. module.exports.TinyEmitter = E;
  729. /***/ })
  730. /******/ });
  731. /************************************************************************/
  732. /******/ // The module cache
  733. /******/ var __webpack_module_cache__ = {};
  734. /******/
  735. /******/ // The require function
  736. /******/ function __webpack_require__(moduleId) {
  737. /******/ // Check if module is in cache
  738. /******/ if(__webpack_module_cache__[moduleId]) {
  739. /******/ return __webpack_module_cache__[moduleId].exports;
  740. /******/ }
  741. /******/ // Create a new module (and put it into the cache)
  742. /******/ var module = __webpack_module_cache__[moduleId] = {
  743. /******/ // no module.id needed
  744. /******/ // no module.loaded needed
  745. /******/ exports: {}
  746. /******/ };
  747. /******/
  748. /******/ // Execute the module function
  749. /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
  750. /******/
  751. /******/ // Return the exports of the module
  752. /******/ return module.exports;
  753. /******/ }
  754. /******/
  755. /************************************************************************/
  756. /******/ /* webpack/runtime/compat get default export */
  757. /******/ !function() {
  758. /******/ // getDefaultExport function for compatibility with non-harmony modules
  759. /******/ __webpack_require__.n = function(module) {
  760. /******/ var getter = module && module.__esModule ?
  761. /******/ function() { return module['default']; } :
  762. /******/ function() { return module; };
  763. /******/ __webpack_require__.d(getter, { a: getter });
  764. /******/ return getter;
  765. /******/ };
  766. /******/ }();
  767. /******/
  768. /******/ /* webpack/runtime/define property getters */
  769. /******/ !function() {
  770. /******/ // define getter functions for harmony exports
  771. /******/ __webpack_require__.d = function(exports, definition) {
  772. /******/ for(var key in definition) {
  773. /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
  774. /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
  775. /******/ }
  776. /******/ }
  777. /******/ };
  778. /******/ }();
  779. /******/
  780. /******/ /* webpack/runtime/hasOwnProperty shorthand */
  781. /******/ !function() {
  782. /******/ __webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }
  783. /******/ }();
  784. /******/
  785. /************************************************************************/
  786. /******/ // module exports must be returned from runtime so entry inlining is disabled
  787. /******/ // startup
  788. /******/ // Load entry module and return exports
  789. /******/ return __webpack_require__(134);
  790. /******/ })()
  791. .default;
  792. });