Merge pull request #120 from pawlufelice/fix_event_target

use event's currentTarget instead of target
This commit is contained in:
Zeno Rocha 2015-11-13 00:20:20 -08:00
commit 5efcdf2810
2 changed files with 19 additions and 5 deletions

View File

@ -47,10 +47,10 @@ class Clipboard extends Emitter {
}
this.clipboardAction = new ClipboardAction({
action : this.action(e.target),
target : this.target(e.target),
text : this.text(e.target),
trigger : e.target,
action : this.action(e.currentTarget),
target : this.target(e.currentTarget),
text : this.text(e.currentTarget),
trigger : e.currentTarget,
emitter : this
});
}

View File

@ -9,8 +9,14 @@ describe('Clipboard', () => {
global.button.setAttribute('data-clipboard-text', 'foo');
document.body.appendChild(global.button);
global.span = document.createElement('span');
global.span.innerHTML = 'bar';
global.button.appendChild(span);
global.event = {
target: global.button
target: global.button,
currentTarget: global.button
};
});
@ -63,6 +69,14 @@ describe('Clipboard', () => {
assert.instanceOf(clipboard.clipboardAction, ClipboardAction);
});
it('should use an event\'s currentTarget when not equal to target', () => {
let clipboard = new Clipboard('.btn');
let bubbledEvent = { target: global.span, currentTarget: global.button };
clipboard.onClick(bubbledEvent);
assert.instanceOf(clipboard.clipboardAction, ClipboardAction);
});
it('should throws exception target', done => {
try {
var clipboard = new Clipboard('.btn', {