clipboard.js 26 KB

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