mirror of
https://github.com/zenorocha/clipboard.js.git
synced 2023-08-10 21:12:48 +03:00
Merge pull request #120 from pawlufelice/fix_event_target
use event's currentTarget instead of target
This commit is contained in:
commit
5efcdf2810
@ -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
|
||||
});
|
||||
}
|
||||
|
@ -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', {
|
||||
|
Loading…
Reference in New Issue
Block a user