mirror of
https://github.com/zenorocha/clipboard.js.git
synced 2023-08-10 21:12:48 +03:00
Removes "no-support" event in favor of "error" and "copy/cut" in favor of "success"
This commit is contained in:
@ -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;
|
||||
|
Reference in New Issue
Block a user