Removes "no-support" event in favor of "error" and "copy/cut" in favor of "success"

This commit is contained in:
Zeno Rocha
2015-09-21 10:19:41 -07:00
parent 23b20d6006
commit c92c4e545a
3 changed files with 25 additions and 23 deletions

View File

@ -89,17 +89,26 @@ class ClipboardAction {
}
copy() {
let successful = false;
let succeeded;
try {
successful = document.execCommand(this.action);
this.clearSelection();
succeeded = document.execCommand(this.action);
}
catch (err) {
succeeded = false;
}
if (successful) this.fireEventDetails();
else this.fireNoSupport();
if (succeeded) {
this.fireEvent('success', {
action: this.action,
text: this.selectedText
});
}
else {
this.fireEvent('error', 'Cannot complete ' + this.action + ' operation');
}
this.clearSelection();
}
clearSelection() {
@ -110,18 +119,13 @@ class ClipboardAction {
window.getSelection().removeAllRanges();
}
fireEventDetails() {
let event = new CustomEvent(this.action, {
detail: this.selectedText
fireEvent(type, detail) {
let event = new CustomEvent(type, {
detail: detail
});
this.trigger.dispatchEvent(event);
}
fireNoSupport() {
let event = new CustomEvent('no-support');
this.trigger.dispatchEvent(event);
}
}
global.Clipboard = Clipboard;