Advertisement
Guest User

Untitled

a guest
Apr 16th, 2018
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 29.43 KB | None | 0 0
  1. /*!
  2. * clipboard.js v2.0.0
  3. * https://zenorocha.github.io/clipboard.js
  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(modules) { // webpackBootstrap
  18. /******/ // The module cache
  19. /******/ var installedModules = {};
  20. /******/
  21. /******/ // The require function
  22. /******/ function __webpack_require__(moduleId) {
  23. /******/
  24. /******/ // Check if module is in cache
  25. /******/ if(installedModules[moduleId]) {
  26. /******/ return installedModules[moduleId].exports;
  27. /******/ }
  28. /******/ // Create a new module (and put it into the cache)
  29. /******/ var module = installedModules[moduleId] = {
  30. /******/ i: moduleId,
  31. /******/ l: false,
  32. /******/ exports: {}
  33. /******/ };
  34. /******/
  35. /******/ // Execute the module function
  36. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  37. /******/
  38. /******/ // Flag the module as loaded
  39. /******/ module.l = true;
  40. /******/
  41. /******/ // Return the exports of the module
  42. /******/ return module.exports;
  43. /******/ }
  44. /******/
  45. /******/
  46. /******/ // expose the modules object (__webpack_modules__)
  47. /******/ __webpack_require__.m = modules;
  48. /******/
  49. /******/ // expose the module cache
  50. /******/ __webpack_require__.c = installedModules;
  51. /******/
  52. /******/ // identity function for calling harmony imports with the correct context
  53. /******/ __webpack_require__.i = function(value) { return value; };
  54. /******/
  55. /******/ // define getter function for harmony exports
  56. /******/ __webpack_require__.d = function(exports, name, getter) {
  57. /******/ if(!__webpack_require__.o(exports, name)) {
  58. /******/ Object.defineProperty(exports, name, {
  59. /******/ configurable: false,
  60. /******/ enumerable: true,
  61. /******/ get: getter
  62. /******/ });
  63. /******/ }
  64. /******/ };
  65. /******/
  66. /******/ // getDefaultExport function for compatibility with non-harmony modules
  67. /******/ __webpack_require__.n = function(module) {
  68. /******/ var getter = module && module.__esModule ?
  69. /******/ function getDefault() { return module['default']; } :
  70. /******/ function getModuleExports() { return module; };
  71. /******/ __webpack_require__.d(getter, 'a', getter);
  72. /******/ return getter;
  73. /******/ };
  74. /******/
  75. /******/ // Object.prototype.hasOwnProperty.call
  76. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  77. /******/
  78. /******/ // __webpack_public_path__
  79. /******/ __webpack_require__.p = "";
  80. /******/
  81. /******/ // Load entry module and return exports
  82. /******/ return __webpack_require__(__webpack_require__.s = 3);
  83. /******/ })
  84. /************************************************************************/
  85. /******/ ([
  86. /* 0 */
  87. /***/ (function(module, exports, __webpack_require__) {
  88.  
  89. var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;(function (global, factory) {
  90. if (true) {
  91. !(__WEBPACK_AMD_DEFINE_ARRAY__ = [module, __webpack_require__(7)], __WEBPACK_AMD_DEFINE_FACTORY__ = (factory),
  92. __WEBPACK_AMD_DEFINE_RESULT__ = (typeof __WEBPACK_AMD_DEFINE_FACTORY__ === 'function' ?
  93. (__WEBPACK_AMD_DEFINE_FACTORY__.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__)) : __WEBPACK_AMD_DEFINE_FACTORY__),
  94. __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
  95. } else if (typeof exports !== "undefined") {
  96. factory(module, require('select'));
  97. } else {
  98. var mod = {
  99. exports: {}
  100. };
  101. factory(mod, global.select);
  102. global.clipboardAction = mod.exports;
  103. }
  104. })(this, function (module, _select) {
  105. 'use strict';
  106.  
  107. var _select2 = _interopRequireDefault(_select);
  108.  
  109. function _interopRequireDefault(obj) {
  110. return obj && obj.__esModule ? obj : {
  111. default: obj
  112. };
  113. }
  114.  
  115. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
  116. return typeof obj;
  117. } : function (obj) {
  118. return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
  119. };
  120.  
  121. function _classCallCheck(instance, Constructor) {
  122. if (!(instance instanceof Constructor)) {
  123. throw new TypeError("Cannot call a class as a function");
  124. }
  125. }
  126.  
  127. var _createClass = function () {
  128. function defineProperties(target, props) {
  129. for (var i = 0; i < props.length; i++) {
  130. var descriptor = props[i];
  131. descriptor.enumerable = descriptor.enumerable || false;
  132. descriptor.configurable = true;
  133. if ("value" in descriptor) descriptor.writable = true;
  134. Object.defineProperty(target, descriptor.key, descriptor);
  135. }
  136. }
  137.  
  138. return function (Constructor, protoProps, staticProps) {
  139. if (protoProps) defineProperties(Constructor.prototype, protoProps);
  140. if (staticProps) defineProperties(Constructor, staticProps);
  141. return Constructor;
  142. };
  143. }();
  144.  
  145. var ClipboardAction = function () {
  146. /**
  147. * @param {Object} options
  148. */
  149. function ClipboardAction(options) {
  150. _classCallCheck(this, ClipboardAction);
  151.  
  152. this.resolveOptions(options);
  153. this.initSelection();
  154. }
  155.  
  156. /**
  157. * Defines base properties passed from constructor.
  158. * @param {Object} options
  159. */
  160.  
  161.  
  162. _createClass(ClipboardAction, [{
  163. key: 'resolveOptions',
  164. value: function resolveOptions() {
  165. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  166.  
  167. this.action = options.action;
  168. this.container = options.container;
  169. this.emitter = options.emitter;
  170. this.target = options.target;
  171. this.text = options.text;
  172. this.trigger = options.trigger;
  173.  
  174. this.selectedText = '';
  175. }
  176. }, {
  177. key: 'initSelection',
  178. value: function initSelection() {
  179. if (this.text) {
  180. this.selectFake();
  181. } else if (this.target) {
  182. this.selectTarget();
  183. }
  184. }
  185. }, {
  186. key: 'selectFake',
  187. value: function selectFake() {
  188. var _this = this;
  189.  
  190. var isRTL = document.documentElement.getAttribute('dir') == 'rtl';
  191.  
  192. this.removeFake();
  193.  
  194. this.fakeHandlerCallback = function () {
  195. return _this.removeFake();
  196. };
  197. this.fakeHandler = this.container.addEventListener('click', this.fakeHandlerCallback) || true;
  198.  
  199. this.fakeElem = document.createElement('textarea');
  200. // Prevent zooming on iOS
  201. this.fakeElem.style.fontSize = '12pt';
  202. // Reset box model
  203. this.fakeElem.style.border = '0';
  204. this.fakeElem.style.padding = '0';
  205. this.fakeElem.style.margin = '0';
  206. // Move element out of screen horizontally
  207. this.fakeElem.style.position = 'absolute';
  208. this.fakeElem.style[isRTL ? 'right' : 'left'] = '-9999px';
  209. // Move element to the same position vertically
  210. var yPosition = window.pageYOffset || document.documentElement.scrollTop;
  211. this.fakeElem.style.top = yPosition + 'px';
  212.  
  213. this.fakeElem.setAttribute('readonly', '');
  214. this.fakeElem.value = this.text;
  215.  
  216. this.container.appendChild(this.fakeElem);
  217.  
  218. this.selectedText = (0, _select2.default)(this.fakeElem);
  219. this.copyText();
  220. }
  221. }, {
  222. key: 'removeFake',
  223. value: function removeFake() {
  224. if (this.fakeHandler) {
  225. this.container.removeEventListener('click', this.fakeHandlerCallback);
  226. this.fakeHandler = null;
  227. this.fakeHandlerCallback = null;
  228. }
  229.  
  230. if (this.fakeElem) {
  231. this.container.removeChild(this.fakeElem);
  232. this.fakeElem = null;
  233. }
  234. }
  235. }, {
  236. key: 'selectTarget',
  237. value: function selectTarget() {
  238. this.selectedText = (0, _select2.default)(this.target);
  239. this.copyText();
  240. }
  241. }, {
  242. key: 'copyText',
  243. value: function copyText() {
  244. var succeeded = void 0;
  245.  
  246. try {
  247. succeeded = document.execCommand(this.action);
  248. } catch (err) {
  249. succeeded = false;
  250. }
  251.  
  252. this.handleResult(succeeded);
  253. }
  254. }, {
  255. key: 'handleResult',
  256. value: function handleResult(succeeded) {
  257. this.emitter.emit(succeeded ? 'success' : 'error', {
  258. action: this.action,
  259. text: this.selectedText,
  260. trigger: this.trigger,
  261. clearSelection: this.clearSelection.bind(this)
  262. });
  263. }
  264. }, {
  265. key: 'clearSelection',
  266. value: function clearSelection() {
  267. if (this.trigger) {
  268. this.trigger.focus();
  269. }
  270.  
  271. window.getSelection().removeAllRanges();
  272. }
  273. }, {
  274. key: 'destroy',
  275. value: function destroy() {
  276. this.removeFake();
  277. }
  278. }, {
  279. key: 'action',
  280. set: function set() {
  281. var action = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'copy';
  282.  
  283. this._action = action;
  284.  
  285. if (this._action !== 'copy' && this._action !== 'cut') {
  286. throw new Error('Invalid "action" value, use either "copy" or "cut"');
  287. }
  288. },
  289. get: function get() {
  290. return this._action;
  291. }
  292. }, {
  293. key: 'target',
  294. set: function set(target) {
  295. if (target !== undefined) {
  296. if (target && (typeof target === 'undefined' ? 'undefined' : _typeof(target)) === 'object' && target.nodeType === 1) {
  297. if (this.action === 'copy' && target.hasAttribute('disabled')) {
  298. throw new Error('Invalid "target" attribute. Please use "readonly" instead of "disabled" attribute');
  299. }
  300.  
  301. if (this.action === 'cut' && (target.hasAttribute('readonly') || target.hasAttribute('disabled'))) {
  302. throw new Error('Invalid "target" attribute. You can\'t cut text from elements with "readonly" or "disabled" attributes');
  303. }
  304.  
  305. this._target = target;
  306. } else {
  307. throw new Error('Invalid "target" value, use a valid Element');
  308. }
  309. }
  310. },
  311. get: function get() {
  312. return this._target;
  313. }
  314. }]);
  315.  
  316. return ClipboardAction;
  317. }();
  318.  
  319. module.exports = ClipboardAction;
  320. });
  321.  
  322. /***/ }),
  323. /* 1 */
  324. /***/ (function(module, exports, __webpack_require__) {
  325.  
  326. var is = __webpack_require__(6);
  327. var delegate = __webpack_require__(5);
  328.  
  329. /**
  330. * Validates all params and calls the right
  331. * listener function based on its target type.
  332. *
  333. * @param {String|HTMLElement|HTMLCollection|NodeList} target
  334. * @param {String} type
  335. * @param {Function} callback
  336. * @return {Object}
  337. */
  338. function listen(target, type, callback) {
  339. if (!target && !type && !callback) {
  340. throw new Error('Missing required arguments');
  341. }
  342.  
  343. if (!is.string(type)) {
  344. throw new TypeError('Second argument must be a String');
  345. }
  346.  
  347. if (!is.fn(callback)) {
  348. throw new TypeError('Third argument must be a Function');
  349. }
  350.  
  351. if (is.node(target)) {
  352. return listenNode(target, type, callback);
  353. }
  354. else if (is.nodeList(target)) {
  355. return listenNodeList(target, type, callback);
  356. }
  357. else if (is.string(target)) {
  358. return listenSelector(target, type, callback);
  359. }
  360. else {
  361. throw new TypeError('First argument must be a String, HTMLElement, HTMLCollection, or NodeList');
  362. }
  363. }
  364.  
  365. /**
  366. * Adds an event listener to a HTML element
  367. * and returns a remove listener function.
  368. *
  369. * @param {HTMLElement} node
  370. * @param {String} type
  371. * @param {Function} callback
  372. * @return {Object}
  373. */
  374. function listenNode(node, type, callback) {
  375. node.addEventListener(type, callback);
  376.  
  377. return {
  378. destroy: function() {
  379. node.removeEventListener(type, callback);
  380. }
  381. }
  382. }
  383.  
  384. /**
  385. * Add an event listener to a list of HTML elements
  386. * and returns a remove listener function.
  387. *
  388. * @param {NodeList|HTMLCollection} nodeList
  389. * @param {String} type
  390. * @param {Function} callback
  391. * @return {Object}
  392. */
  393. function listenNodeList(nodeList, type, callback) {
  394. Array.prototype.forEach.call(nodeList, function(node) {
  395. node.addEventListener(type, callback);
  396. });
  397.  
  398. return {
  399. destroy: function() {
  400. Array.prototype.forEach.call(nodeList, function(node) {
  401. node.removeEventListener(type, callback);
  402. });
  403. }
  404. }
  405. }
  406.  
  407. /**
  408. * Add an event listener to a selector
  409. * and returns a remove listener function.
  410. *
  411. * @param {String} selector
  412. * @param {String} type
  413. * @param {Function} callback
  414. * @return {Object}
  415. */
  416. function listenSelector(selector, type, callback) {
  417. return delegate(document.body, selector, type, callback);
  418. }
  419.  
  420. module.exports = listen;
  421.  
  422.  
  423. /***/ }),
  424. /* 2 */
  425. /***/ (function(module, exports) {
  426.  
  427. function E () {
  428. // Keep this empty so it's easier to inherit from
  429. // (via https://github.com/lipsmack from https://github.com/scottcorgan/tiny-emitter/issues/3)
  430. }
  431.  
  432. E.prototype = {
  433. on: function (name, callback, ctx) {
  434. var e = this.e || (this.e = {});
  435.  
  436. (e[name] || (e[name] = [])).push({
  437. fn: callback,
  438. ctx: ctx
  439. });
  440.  
  441. return this;
  442. },
  443.  
  444. once: function (name, callback, ctx) {
  445. var self = this;
  446. function listener () {
  447. self.off(name, listener);
  448. callback.apply(ctx, arguments);
  449. };
  450.  
  451. listener._ = callback
  452. return this.on(name, listener, ctx);
  453. },
  454.  
  455. emit: function (name) {
  456. var data = [].slice.call(arguments, 1);
  457. var evtArr = ((this.e || (this.e = {}))[name] || []).slice();
  458. var i = 0;
  459. var len = evtArr.length;
  460.  
  461. for (i; i < len; i++) {
  462. evtArr[i].fn.apply(evtArr[i].ctx, data);
  463. }
  464.  
  465. return this;
  466. },
  467.  
  468. off: function (name, callback) {
  469. var e = this.e || (this.e = {});
  470. var evts = e[name];
  471. var liveEvents = [];
  472.  
  473. if (evts && callback) {
  474. for (var i = 0, len = evts.length; i < len; i++) {
  475. if (evts[i].fn !== callback && evts[i].fn._ !== callback)
  476. liveEvents.push(evts[i]);
  477. }
  478. }
  479.  
  480. // Remove event from queue to prevent memory leak
  481. // Suggested by https://github.com/lazd
  482. // Ref: https://github.com/scottcorgan/tiny-emitter/commit/c6ebfaa9bc973b33d110a84a307742b7cf94c953#commitcomment-5024910
  483.  
  484. (liveEvents.length)
  485. ? e[name] = liveEvents
  486. : delete e[name];
  487.  
  488. return this;
  489. }
  490. };
  491.  
  492. module.exports = E;
  493.  
  494.  
  495. /***/ }),
  496. /* 3 */
  497. /***/ (function(module, exports, __webpack_require__) {
  498.  
  499. var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;(function (global, factory) {
  500. if (true) {
  501. !(__WEBPACK_AMD_DEFINE_ARRAY__ = [module, __webpack_require__(0), __webpack_require__(2), __webpack_require__(1)], __WEBPACK_AMD_DEFINE_FACTORY__ = (factory),
  502. __WEBPACK_AMD_DEFINE_RESULT__ = (typeof __WEBPACK_AMD_DEFINE_FACTORY__ === 'function' ?
  503. (__WEBPACK_AMD_DEFINE_FACTORY__.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__)) : __WEBPACK_AMD_DEFINE_FACTORY__),
  504. __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
  505. } else if (typeof exports !== "undefined") {
  506. factory(module, require('./clipboard-action'), require('tiny-emitter'), require('good-listener'));
  507. } else {
  508. var mod = {
  509. exports: {}
  510. };
  511. factory(mod, global.clipboardAction, global.tinyEmitter, global.goodListener);
  512. global.clipboard = mod.exports;
  513. }
  514. })(this, function (module, _clipboardAction, _tinyEmitter, _goodListener) {
  515. 'use strict';
  516.  
  517. var _clipboardAction2 = _interopRequireDefault(_clipboardAction);
  518.  
  519. var _tinyEmitter2 = _interopRequireDefault(_tinyEmitter);
  520.  
  521. var _goodListener2 = _interopRequireDefault(_goodListener);
  522.  
  523. function _interopRequireDefault(obj) {
  524. return obj && obj.__esModule ? obj : {
  525. default: obj
  526. };
  527. }
  528.  
  529. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
  530. return typeof obj;
  531. } : function (obj) {
  532. return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
  533. };
  534.  
  535. function _classCallCheck(instance, Constructor) {
  536. if (!(instance instanceof Constructor)) {
  537. throw new TypeError("Cannot call a class as a function");
  538. }
  539. }
  540.  
  541. var _createClass = function () {
  542. function defineProperties(target, props) {
  543. for (var i = 0; i < props.length; i++) {
  544. var descriptor = props[i];
  545. descriptor.enumerable = descriptor.enumerable || false;
  546. descriptor.configurable = true;
  547. if ("value" in descriptor) descriptor.writable = true;
  548. Object.defineProperty(target, descriptor.key, descriptor);
  549. }
  550. }
  551.  
  552. return function (Constructor, protoProps, staticProps) {
  553. if (protoProps) defineProperties(Constructor.prototype, protoProps);
  554. if (staticProps) defineProperties(Constructor, staticProps);
  555. return Constructor;
  556. };
  557. }();
  558.  
  559. function _possibleConstructorReturn(self, call) {
  560. if (!self) {
  561. throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  562. }
  563.  
  564. return call && (typeof call === "object" || typeof call === "function") ? call : self;
  565. }
  566.  
  567. function _inherits(subClass, superClass) {
  568. if (typeof superClass !== "function" && superClass !== null) {
  569. throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
  570. }
  571.  
  572. subClass.prototype = Object.create(superClass && superClass.prototype, {
  573. constructor: {
  574. value: subClass,
  575. enumerable: false,
  576. writable: true,
  577. configurable: true
  578. }
  579. });
  580. if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
  581. }
  582.  
  583. var Clipboard = function (_Emitter) {
  584. _inherits(Clipboard, _Emitter);
  585.  
  586. /**
  587. * @param {String|HTMLElement|HTMLCollection|NodeList} trigger
  588. * @param {Object} options
  589. */
  590. function Clipboard(trigger, options) {
  591. _classCallCheck(this, Clipboard);
  592.  
  593. var _this = _possibleConstructorReturn(this, (Clipboard.__proto__ || Object.getPrototypeOf(Clipboard)).call(this));
  594.  
  595. _this.resolveOptions(options);
  596. _this.listenClick(trigger);
  597. return _this;
  598. }
  599.  
  600. /**
  601. * Defines if attributes would be resolved using internal setter functions
  602. * or custom functions that were passed in the constructor.
  603. * @param {Object} options
  604. */
  605.  
  606.  
  607. _createClass(Clipboard, [{
  608. key: 'resolveOptions',
  609. value: function resolveOptions() {
  610. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  611.  
  612. this.action = typeof options.action === 'function' ? options.action : this.defaultAction;
  613. this.target = typeof options.target === 'function' ? options.target : this.defaultTarget;
  614. this.text = typeof options.text === 'function' ? options.text : this.defaultText;
  615. this.container = _typeof(options.container) === 'object' ? options.container : document.body;
  616. }
  617. }, {
  618. key: 'listenClick',
  619. value: function listenClick(trigger) {
  620. var _this2 = this;
  621.  
  622. this.listener = (0, _goodListener2.default)(trigger, 'click', function (e) {
  623. return _this2.onClick(e);
  624. });
  625. }
  626. }, {
  627. key: 'onClick',
  628. value: function onClick(e) {
  629. var trigger = e.delegateTarget || e.currentTarget;
  630.  
  631. if (this.clipboardAction) {
  632. this.clipboardAction = null;
  633. }
  634.  
  635. this.clipboardAction = new _clipboardAction2.default({
  636. action: this.action(trigger),
  637. target: this.target(trigger),
  638. text: this.text(trigger),
  639. container: this.container,
  640. trigger: trigger,
  641. emitter: this
  642. });
  643. }
  644. }, {
  645. key: 'defaultAction',
  646. value: function defaultAction(trigger) {
  647. return getAttributeValue('action', trigger);
  648. }
  649. }, {
  650. key: 'defaultTarget',
  651. value: function defaultTarget(trigger) {
  652. var selector = getAttributeValue('target', trigger);
  653.  
  654. if (selector) {
  655. return document.querySelector(selector);
  656. }
  657. }
  658. }, {
  659. key: 'defaultText',
  660. value: function defaultText(trigger) {
  661. return getAttributeValue('text', trigger);
  662. }
  663. }, {
  664. key: 'destroy',
  665. value: function destroy() {
  666. this.listener.destroy();
  667.  
  668. if (this.clipboardAction) {
  669. this.clipboardAction.destroy();
  670. this.clipboardAction = null;
  671. }
  672. }
  673. }], [{
  674. key: 'isSupported',
  675. value: function isSupported() {
  676. var action = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ['copy', 'cut'];
  677.  
  678. var actions = typeof action === 'string' ? [action] : action;
  679. var support = !!document.queryCommandSupported;
  680.  
  681. actions.forEach(function (action) {
  682. support = support && !!document.queryCommandSupported(action);
  683. });
  684.  
  685. return support;
  686. }
  687. }]);
  688.  
  689. return Clipboard;
  690. }(_tinyEmitter2.default);
  691.  
  692. /**
  693. * Helper function to retrieve attribute value.
  694. * @param {String} suffix
  695. * @param {Element} element
  696. */
  697. function getAttributeValue(suffix, element) {
  698. var attribute = 'data-clipboard-' + suffix;
  699.  
  700. if (!element.hasAttribute(attribute)) {
  701. return;
  702. }
  703.  
  704. return element.getAttribute(attribute);
  705. }
  706.  
  707. module.exports = Clipboard;
  708. });
  709.  
  710. /***/ }),
  711. /* 4 */
  712. /***/ (function(module, exports) {
  713.  
  714. var DOCUMENT_NODE_TYPE = 9;
  715.  
  716. /**
  717. * A polyfill for Element.matches()
  718. */
  719. if (typeof Element !== 'undefined' && !Element.prototype.matches) {
  720. var proto = Element.prototype;
  721.  
  722. proto.matches = proto.matchesSelector ||
  723. proto.mozMatchesSelector ||
  724. proto.msMatchesSelector ||
  725. proto.oMatchesSelector ||
  726. proto.webkitMatchesSelector;
  727. }
  728.  
  729. /**
  730. * Finds the closest parent that matches a selector.
  731. *
  732. * @param {Element} element
  733. * @param {String} selector
  734. * @return {Function}
  735. */
  736. function closest (element, selector) {
  737. while (element && element.nodeType !== DOCUMENT_NODE_TYPE) {
  738. if (typeof element.matches === 'function' &&
  739. element.matches(selector)) {
  740. return element;
  741. }
  742. element = element.parentNode;
  743. }
  744. }
  745.  
  746. module.exports = closest;
  747.  
  748.  
  749. /***/ }),
  750. /* 5 */
  751. /***/ (function(module, exports, __webpack_require__) {
  752.  
  753. var closest = __webpack_require__(4);
  754.  
  755. /**
  756. * Delegates event to a selector.
  757. *
  758. * @param {Element} element
  759. * @param {String} selector
  760. * @param {String} type
  761. * @param {Function} callback
  762. * @param {Boolean} useCapture
  763. * @return {Object}
  764. */
  765. function _delegate(element, selector, type, callback, useCapture) {
  766. var listenerFn = listener.apply(this, arguments);
  767.  
  768. element.addEventListener(type, listenerFn, useCapture);
  769.  
  770. return {
  771. destroy: function() {
  772. element.removeEventListener(type, listenerFn, useCapture);
  773. }
  774. }
  775. }
  776.  
  777. /**
  778. * Delegates event to a selector.
  779. *
  780. * @param {Element|String|Array} [elements]
  781. * @param {String} selector
  782. * @param {String} type
  783. * @param {Function} callback
  784. * @param {Boolean} useCapture
  785. * @return {Object}
  786. */
  787. function delegate(elements, selector, type, callback, useCapture) {
  788. // Handle the regular Element usage
  789. if (typeof elements.addEventListener === 'function') {
  790. return _delegate.apply(null, arguments);
  791. }
  792.  
  793. // Handle Element-less usage, it defaults to global delegation
  794. if (typeof type === 'function') {
  795. // Use `document` as the first parameter, then apply arguments
  796. // This is a short way to .unshift `arguments` without running into deoptimizations
  797. return _delegate.bind(null, document).apply(null, arguments);
  798. }
  799.  
  800. // Handle Selector-based usage
  801. if (typeof elements === 'string') {
  802. elements = document.querySelectorAll(elements);
  803. }
  804.  
  805. // Handle Array-like based usage
  806. return Array.prototype.map.call(elements, function (element) {
  807. return _delegate(element, selector, type, callback, useCapture);
  808. });
  809. }
  810.  
  811. /**
  812. * Finds closest match and invokes callback.
  813. *
  814. * @param {Element} element
  815. * @param {String} selector
  816. * @param {String} type
  817. * @param {Function} callback
  818. * @return {Function}
  819. */
  820. function listener(element, selector, type, callback) {
  821. return function(e) {
  822. e.delegateTarget = closest(e.target, selector);
  823.  
  824. if (e.delegateTarget) {
  825. callback.call(element, e);
  826. }
  827. }
  828. }
  829.  
  830. module.exports = delegate;
  831.  
  832.  
  833. /***/ }),
  834. /* 6 */
  835. /***/ (function(module, exports) {
  836.  
  837. /**
  838. * Check if argument is a HTML element.
  839. *
  840. * @param {Object} value
  841. * @return {Boolean}
  842. */
  843. exports.node = function(value) {
  844. return value !== undefined
  845. && value instanceof HTMLElement
  846. && value.nodeType === 1;
  847. };
  848.  
  849. /**
  850. * Check if argument is a list of HTML elements.
  851. *
  852. * @param {Object} value
  853. * @return {Boolean}
  854. */
  855. exports.nodeList = function(value) {
  856. var type = Object.prototype.toString.call(value);
  857.  
  858. return value !== undefined
  859. && (type === '[object NodeList]' || type === '[object HTMLCollection]')
  860. && ('length' in value)
  861. && (value.length === 0 || exports.node(value[0]));
  862. };
  863.  
  864. /**
  865. * Check if argument is a string.
  866. *
  867. * @param {Object} value
  868. * @return {Boolean}
  869. */
  870. exports.string = function(value) {
  871. return typeof value === 'string'
  872. || value instanceof String;
  873. };
  874.  
  875. /**
  876. * Check if argument is a function.
  877. *
  878. * @param {Object} value
  879. * @return {Boolean}
  880. */
  881. exports.fn = function(value) {
  882. var type = Object.prototype.toString.call(value);
  883.  
  884. return type === '[object Function]';
  885. };
  886.  
  887.  
  888. /***/ }),
  889. /* 7 */
  890. /***/ (function(module, exports) {
  891.  
  892. function select(element) {
  893. var selectedText;
  894.  
  895. if (element.nodeName === 'SELECT') {
  896. element.focus();
  897.  
  898. selectedText = element.value;
  899. }
  900. else if (element.nodeName === 'INPUT' || element.nodeName === 'TEXTAREA') {
  901. var isReadOnly = element.hasAttribute('readonly');
  902.  
  903. if (!isReadOnly) {
  904. element.setAttribute('readonly', '');
  905. }
  906.  
  907. element.select();
  908. element.setSelectionRange(0, element.value.length);
  909.  
  910. if (!isReadOnly) {
  911. element.removeAttribute('readonly');
  912. }
  913.  
  914. selectedText = element.value;
  915. }
  916. else {
  917. if (element.hasAttribute('contenteditable')) {
  918. element.focus();
  919. }
  920.  
  921. var selection = window.getSelection();
  922. var range = document.createRange();
  923.  
  924. range.selectNodeContents(element);
  925. selection.removeAllRanges();
  926. selection.addRange(range);
  927.  
  928. selectedText = selection.toString();
  929. }
  930.  
  931. return selectedText;
  932. }
  933.  
  934. module.exports = select;
  935.  
  936.  
  937. /***/ })
  938. /******/ ]);
  939. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement