[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

/wp-includes/js/ -> clipboard.js (source)

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


Generated: Thu Oct 1 01:00:03 2020 Cross-referenced by PHPXref 0.7.1