diff --git a/package.json b/package.json index 32aa185..d15d8b4 100644 --- a/package.json +++ b/package.json @@ -25,8 +25,7 @@ "babelify": "^6.3.0", "browserify": "^11.2.0", "delegate-events": "^1.1.1", - "tiny-emitter": "^1.0.0", - "component-event": "^0.1.4" + "tiny-emitter": "^1.0.0" }, "devDependencies": { "karma": "^0.13.10", diff --git a/src/clipboard.js b/src/clipboard.js index 7868db5..4e2290c 100644 --- a/src/clipboard.js +++ b/src/clipboard.js @@ -1,6 +1,5 @@ import ClipboardAction from './clipboard-action'; import Delegate from 'delegate-events'; -import event from 'component-event'; import Emitter from 'tiny-emitter'; /** @@ -44,20 +43,12 @@ class Clipboard extends Emitter { this.binding = Delegate.bind(document.body, selector, 'click', (e) => this.onClick(e)); } - /** - * Undelegates a click event on body. - * @param {String} selector - */ - undelegateClick() { - Delegate.unbind(document.body, 'click', this.binding); - } - /** * Delegates a click event on the passed element. * @param {Object} element */ delegateClickToElement(element) { - event.bind(document.body, 'click', (e) => { + element.addEventListener('click', (e) => { e.delegateTarget = element; if (e.delegateTarget) { (e) => this.onClick(e); @@ -65,6 +56,14 @@ class Clipboard extends Emitter { }); } + /** + * Undelegates a click event on body. + * @param {String} selector + */ + undelegateClick() { + Delegate.unbind(document.body, 'click', this.binding); + } + /** * Defines a new `ClipboardAction` on each click event. * @param {Event} e diff --git a/test/clipboard.js b/test/clipboard.js index 4acc0b1..cf132e9 100644 --- a/test/clipboard.js +++ b/test/clipboard.js @@ -1,7 +1,6 @@ import Clipboard from '../src/clipboard'; import ClipboardAction from '../src/clipboard-action'; import Delegate from 'delegate-events'; -import Event from 'component-event'; describe('Clipboard', () => { before(() => { @@ -93,7 +92,7 @@ describe('Clipboard', () => { describe('#delegateClickToElement', function() { before(() => { - global.spy = sinon.spy(Event, 'bind'); + global.spy = sinon.spy(global.button, 'addEventListener'); }); after(() => { @@ -101,13 +100,12 @@ describe('Clipboard', () => { }); it('should delegate a click event to the passed element', () => { - let element = document.body; let event = 'click'; let clipboard = new Clipboard(global.button); assert.ok(global.spy.calledOnce); - assert.ok(global.spy.calledWith(element, event)); + assert.ok(global.spy.calledWith(event)); }); });