控制台应用,yzncms本身基于tp5.1框架,里面的队列用不了,bug,坑
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

clipboard.js 29KB

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