diff --git a/dist/clipboard.js b/dist/clipboard.js index 97d6cd3..fc19bae 100644 --- a/dist/clipboard.js +++ b/dist/clipboard.js @@ -621,9 +621,9 @@ var Clipboard = (function (_Emitter) { _classCallCheck(this, Clipboard); _Emitter.call(this); - + this.defaultTriggerEvent = 'click'; this.resolveOptions(options); - this.listenClick(trigger); + this.listenEvent(trigger); } /** @@ -644,27 +644,28 @@ var Clipboard = (function (_Emitter) { this.action = typeof options.action === 'function' ? options.action : this.defaultAction; this.target = typeof options.target === 'function' ? options.target : this.defaultTarget; this.text = typeof options.text === 'function' ? options.text : this.defaultText; + this.triggerEvent = typeof options.triggerEvent === 'string' ? options.triggerEvent : this.defaultTriggerEvent; }; /** - * Adds a click event listener to the passed trigger. + * Adds a event listener to the passed trigger. * @param {String|HTMLElement|HTMLCollection|NodeList} trigger */ - Clipboard.prototype.listenClick = function listenClick(trigger) { + Clipboard.prototype.listenEvent = function listenEvent(trigger) { var _this = this; - this.listener = _goodListener2['default'](trigger, 'click', function (e) { - return _this.onClick(e); + this.listener = _goodListener2['default'](trigger, this.triggerEvent, function (e) { + return _this.handleEvent(e); }); }; /** - * Defines a new `ClipboardAction` on each click event. + * Defines a new `ClipboardAction` on each trigger event. * @param {Event} e */ - Clipboard.prototype.onClick = function onClick(e) { + Clipboard.prototype.handleEvent = function handleEvent(e) { if (this.clipboardAction) { this.clipboardAction = null; } diff --git a/dist/clipboard.min.js b/dist/clipboard.min.js index 4ab5cc4..0d1ee81 100644 --- a/dist/clipboard.min.js +++ b/dist/clipboard.min.js @@ -4,4 +4,4 @@ * * Licensed MIT © Zeno Rocha */ -!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var e;e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,e.Clipboard=t()}}(function(){var t,e,n;return function t(e,n,r){function o(a,c){if(!n[a]){if(!e[a]){var s="function"==typeof require&&require;if(!c&&s)return s(a,!0);if(i)return i(a,!0);var u=new Error("Cannot find module '"+a+"'");throw u.code="MODULE_NOT_FOUND",u}var l=n[a]={exports:{}};e[a][0].call(l.exports,function(t){var n=e[a][1][t];return o(n?n:t)},l,l.exports,t,e,n,r)}return n[a].exports}for(var i="function"==typeof require&&require,a=0;ar;r++)n[r].fn.apply(n[r].ctx,e);return this},off:function(t,e){var n=this.e||(this.e={}),r=n[t],o=[];if(r&&e)for(var i=0,a=r.length;a>i;i++)r[i].fn!==e&&r[i].fn._!==e&&o.push(r[i]);return o.length?n[t]=o:delete n[t],this}},e.exports=r},{}],8:[function(t,e,n){"use strict";function r(t){return t&&t.__esModule?t:{"default":t}}function o(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}n.__esModule=!0;var i=function(){function t(t,e){for(var n=0;nr;r++)n[r].fn.apply(n[r].ctx,e);return this},off:function(t,e){var n=this.e||(this.e={}),r=n[t],o=[];if(r&&e)for(var i=0,a=r.length;a>i;i++)r[i].fn!==e&&r[i].fn._!==e&&o.push(r[i]);return o.length?n[t]=o:delete n[t],this}},e.exports=r},{}],8:[function(t,e,n){"use strict";function r(t){return t&&t.__esModule?t:{"default":t}}function o(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}n.__esModule=!0;var i=function(){function t(t,e){for(var n=0;n ``` +### Use custom event trigger + +you can listen other event, the default event is 'click'. + +```html + +``` + +```javascript +var clipboard = new Clipboard('.triggerLabel', {'triggerEvent' : 'dblclick'}); +``` + ## Events There are cases where you'd like to show some user feedback or capture what has been selected after a copy/cut operation. diff --git a/src/clipboard.js b/src/clipboard.js index da513be..53762d9 100644 --- a/src/clipboard.js +++ b/src/clipboard.js @@ -13,9 +13,9 @@ class Clipboard extends Emitter { */ constructor(trigger, options) { super(); - + this.defaultTriggerEvent = 'click'; this.resolveOptions(options); - this.listenClick(trigger); + this.listenEvent(trigger); } /** @@ -27,21 +27,22 @@ class Clipboard extends Emitter { this.action = (typeof options.action === 'function') ? options.action : this.defaultAction; this.target = (typeof options.target === 'function') ? options.target : this.defaultTarget; this.text = (typeof options.text === 'function') ? options.text : this.defaultText; + this.triggerEvent = (typeof options.triggerEvent === 'string') ? options.triggerEvent : this.defaultTriggerEvent; } /** - * Adds a click event listener to the passed trigger. + * Adds a event listener to the passed trigger. * @param {String|HTMLElement|HTMLCollection|NodeList} trigger */ - listenClick(trigger) { - this.listener = listen(trigger, 'click', (e) => this.onClick(e)); + listenEvent(trigger) { + this.listener = listen(trigger, this.triggerEvent, (e) => this.handleEvent(e)); } /** - * Defines a new `ClipboardAction` on each click event. + * Defines a new `ClipboardAction` on each trigger event. * @param {Event} e */ - onClick(e) { + handleEvent(e) { if (this.clipboardAction) { this.clipboardAction = null; }