diff --git a/dist/clipboard.js b/dist/clipboard.js index d54de7e..419e0a4 100644 --- a/dist/clipboard.js +++ b/dist/clipboard.js @@ -30,9 +30,6 @@ __webpack_require__.d(__webpack_exports__, { // EXTERNAL MODULE: ./node_modules/tiny-emitter/index.js var tiny_emitter = __webpack_require__(279); var tiny_emitter_default = /*#__PURE__*/__webpack_require__.n(tiny_emitter); -// EXTERNAL MODULE: ./node_modules/good-listener/src/listen.js -var listen = __webpack_require__(370); -var listen_default = /*#__PURE__*/__webpack_require__.n(listen); // EXTERNAL MODULE: ./node_modules/select/src/select.js var src_select = __webpack_require__(817); var select_default = /*#__PURE__*/__webpack_require__.n(src_select); @@ -311,7 +308,6 @@ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.g - /** * Helper function to retrieve attribute value. * @param {String} suffix @@ -381,9 +377,25 @@ var Clipboard = /*#__PURE__*/function (_Emitter) { value: function listenClick(trigger) { var _this2 = this; - this.listener = listen_default()(trigger, 'click', function (e) { + if (typeof trigger === 'string') { + trigger = document.querySelectorAll(trigger); + } + + var listener = function listener(e) { return _this2.onClick(e); - }); + }; + + for (var i = 0; i < trigger.length; i++) { + trigger.addEventListener('click', listener); + } + + this.listener = { + destroy: function destroy() { + for (var _i = 0; _i < trigger.length; _i++) { + trigger.removeEventListener('click', listener); + } + } + }; } /** * Defines a new `ClipboardAction` on each click event. @@ -480,289 +492,6 @@ var Clipboard = /*#__PURE__*/function (_Emitter) { /* harmony default export */ var clipboard = (Clipboard); -/***/ }), - -/***/ 828: -/***/ (function(module) { - -var DOCUMENT_NODE_TYPE = 9; - -/** - * A polyfill for Element.matches() - */ -if (typeof Element !== 'undefined' && !Element.prototype.matches) { - var proto = Element.prototype; - - proto.matches = proto.matchesSelector || - proto.mozMatchesSelector || - proto.msMatchesSelector || - proto.oMatchesSelector || - proto.webkitMatchesSelector; -} - -/** - * Finds the closest parent that matches a selector. - * - * @param {Element} element - * @param {String} selector - * @return {Function} - */ -function closest (element, selector) { - while (element && element.nodeType !== DOCUMENT_NODE_TYPE) { - if (typeof element.matches === 'function' && - element.matches(selector)) { - return element; - } - element = element.parentNode; - } -} - -module.exports = closest; - - -/***/ }), - -/***/ 438: -/***/ (function(module, __unused_webpack_exports, __webpack_require__) { - -var closest = __webpack_require__(828); - -/** - * Delegates event to a selector. - * - * @param {Element} element - * @param {String} selector - * @param {String} type - * @param {Function} callback - * @param {Boolean} useCapture - * @return {Object} - */ -function _delegate(element, selector, type, callback, useCapture) { - var listenerFn = listener.apply(this, arguments); - - element.addEventListener(type, listenerFn, useCapture); - - return { - destroy: function() { - element.removeEventListener(type, listenerFn, useCapture); - } - } -} - -/** - * Delegates event to a selector. - * - * @param {Element|String|Array} [elements] - * @param {String} selector - * @param {String} type - * @param {Function} callback - * @param {Boolean} useCapture - * @return {Object} - */ -function delegate(elements, selector, type, callback, useCapture) { - // Handle the regular Element usage - if (typeof elements.addEventListener === 'function') { - return _delegate.apply(null, arguments); - } - - // Handle Element-less usage, it defaults to global delegation - if (typeof type === 'function') { - // Use `document` as the first parameter, then apply arguments - // This is a short way to .unshift `arguments` without running into deoptimizations - return _delegate.bind(null, document).apply(null, arguments); - } - - // Handle Selector-based usage - if (typeof elements === 'string') { - elements = document.querySelectorAll(elements); - } - - // Handle Array-like based usage - return Array.prototype.map.call(elements, function (element) { - return _delegate(element, selector, type, callback, useCapture); - }); -} - -/** - * Finds closest match and invokes callback. - * - * @param {Element} element - * @param {String} selector - * @param {String} type - * @param {Function} callback - * @return {Function} - */ -function listener(element, selector, type, callback) { - return function(e) { - e.delegateTarget = closest(e.target, selector); - - if (e.delegateTarget) { - callback.call(element, e); - } - } -} - -module.exports = delegate; - - -/***/ }), - -/***/ 879: -/***/ (function(__unused_webpack_module, exports) { - -/** - * Check if argument is a HTML element. - * - * @param {Object} value - * @return {Boolean} - */ -exports.node = function(value) { - return value !== undefined - && value instanceof HTMLElement - && value.nodeType === 1; -}; - -/** - * Check if argument is a list of HTML elements. - * - * @param {Object} value - * @return {Boolean} - */ -exports.nodeList = function(value) { - var type = Object.prototype.toString.call(value); - - return value !== undefined - && (type === '[object NodeList]' || type === '[object HTMLCollection]') - && ('length' in value) - && (value.length === 0 || exports.node(value[0])); -}; - -/** - * Check if argument is a string. - * - * @param {Object} value - * @return {Boolean} - */ -exports.string = function(value) { - return typeof value === 'string' - || value instanceof String; -}; - -/** - * Check if argument is a function. - * - * @param {Object} value - * @return {Boolean} - */ -exports.fn = function(value) { - var type = Object.prototype.toString.call(value); - - return type === '[object Function]'; -}; - - -/***/ }), - -/***/ 370: -/***/ (function(module, __unused_webpack_exports, __webpack_require__) { - -var is = __webpack_require__(879); -var delegate = __webpack_require__(438); - -/** - * Validates all params and calls the right - * listener function based on its target type. - * - * @param {String|HTMLElement|HTMLCollection|NodeList} target - * @param {String} type - * @param {Function} callback - * @return {Object} - */ -function listen(target, type, callback) { - if (!target && !type && !callback) { - throw new Error('Missing required arguments'); - } - - if (!is.string(type)) { - throw new TypeError('Second argument must be a String'); - } - - if (!is.fn(callback)) { - throw new TypeError('Third argument must be a Function'); - } - - if (is.node(target)) { - return listenNode(target, type, callback); - } - else if (is.nodeList(target)) { - return listenNodeList(target, type, callback); - } - else if (is.string(target)) { - return listenSelector(target, type, callback); - } - else { - throw new TypeError('First argument must be a String, HTMLElement, HTMLCollection, or NodeList'); - } -} - -/** - * Adds an event listener to a HTML element - * and returns a remove listener function. - * - * @param {HTMLElement} node - * @param {String} type - * @param {Function} callback - * @return {Object} - */ -function listenNode(node, type, callback) { - node.addEventListener(type, callback); - - return { - destroy: function() { - node.removeEventListener(type, callback); - } - } -} - -/** - * Add an event listener to a list of HTML elements - * and returns a remove listener function. - * - * @param {NodeList|HTMLCollection} nodeList - * @param {String} type - * @param {Function} callback - * @return {Object} - */ -function listenNodeList(nodeList, type, callback) { - Array.prototype.forEach.call(nodeList, function(node) { - node.addEventListener(type, callback); - }); - - return { - destroy: function() { - Array.prototype.forEach.call(nodeList, function(node) { - node.removeEventListener(type, callback); - }); - } - } -} - -/** - * Add an event listener to a selector - * and returns a remove listener function. - * - * @param {String} selector - * @param {String} type - * @param {Function} callback - * @return {Object} - */ -function listenSelector(selector, type, callback) { - return delegate(document.body, selector, type, callback); -} - -module.exports = listen; - - /***/ }), /***/ 817: diff --git a/dist/clipboard.min.js b/dist/clipboard.min.js index 95f55d7..1a21647 100644 --- a/dist/clipboard.min.js +++ b/dist/clipboard.min.js @@ -4,4 +4,4 @@ * * Licensed MIT © Zeno Rocha */ -!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.ClipboardJS=e():t.ClipboardJS=e()}(this,function(){return n={134:function(t,e,n){"use strict";n.d(e,{default:function(){return r}});var e=n(279),i=n.n(e),e=n(370),a=n.n(e),e=n(817),o=n.n(e);function c(t){return(c="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function u(t,e){for(var n=0;n this.onClick(e)); + const listener = (e) => this.onClick(e); + if (typeof trigger === 'string') { + this.listener = delegate(document, trigger, 'click', listener); + return; + } + + for (let i = 0; i < trigger.length; i++) { + trigger.addEventListener('click', listener); + } + + this.listener = { + destroy() { + for (let i = 0; i < trigger.length; i++) { + trigger.removeEventListener('click', listener); + } + } + } } /**