Destroys the previous ClipboardAction instance whenever a new click is triggered

This commit is contained in:
Zeno Rocha 2015-09-24 21:24:21 -07:00
parent 3610bfa08c
commit 076e3b8a64

View File

@ -14,8 +14,8 @@ class Clipboard extends Emitter {
constructor(selector) { constructor(selector) {
super(); super();
let delegate = new Delegate(document.body); this.delegate = new Delegate(document.body);
delegate.on('click', selector, (e) => this.initialize(e)); this.delegate.on('click', selector, (e) => this.initialize(e));
} }
/** /**
@ -23,7 +23,11 @@ class Clipboard extends Emitter {
* @param {Event} e * @param {Event} e
*/ */
initialize(e) { initialize(e) {
new ClipboardAction({ if (this.clipboardAction) {
this.clipboardAction = null;
}
this.clipboardAction = new ClipboardAction({
action : e.target.getAttribute('data-action'), action : e.target.getAttribute('data-action'),
target : e.target.getAttribute('data-target'), target : e.target.getAttribute('data-target'),
text : e.target.getAttribute('data-text'), text : e.target.getAttribute('data-text'),