mirror of
https://github.com/zenorocha/clipboard.js.git
synced 2023-08-10 21:12:48 +03:00
Only fire detailed events if copy was successful
This commit is contained in:
@ -92,10 +92,10 @@ class ClipboardAction {
|
||||
let supported = document.queryCommandSupported(this.action);
|
||||
|
||||
try {
|
||||
document.execCommand(this.action);
|
||||
let successful = document.execCommand(this.action);
|
||||
if (successful) this.fireEventDetails();
|
||||
|
||||
this.fireEventDetails();
|
||||
window.getSelection().removeAllRanges();
|
||||
this.clearSelection();
|
||||
}
|
||||
catch (err) {
|
||||
supported = false;
|
||||
@ -104,6 +104,14 @@ class ClipboardAction {
|
||||
if (!supported) this.fireNoSupport();
|
||||
}
|
||||
|
||||
clearSelection() {
|
||||
if (this.target) {
|
||||
this.target.blur();
|
||||
}
|
||||
|
||||
window.getSelection().removeAllRanges();
|
||||
}
|
||||
|
||||
fireEventDetails() {
|
||||
let event = new CustomEvent(this.action, {
|
||||
detail: this.selectedText
|
||||
|
Reference in New Issue
Block a user