remove component-event dep in #42

This commit is contained in:
arve0 2015-10-05 19:13:52 +02:00
parent 08c79891cf
commit 4cc0f7a77e
3 changed files with 12 additions and 16 deletions

View File

@ -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",

View File

@ -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

View File

@ -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));
});
});