mirror of
https://github.com/zenorocha/clipboard.js.git
synced 2023-08-10 21:12:48 +03:00
Handles browsers that do not support this API
This commit is contained in:
@ -88,26 +88,35 @@ class Clipboard {
|
||||
}
|
||||
|
||||
copy(actionAttr, selectedText, currentTrigger) {
|
||||
let supported = document.queryCommandSupported(actionAttr);
|
||||
|
||||
try {
|
||||
let successful = document.execCommand(actionAttr);
|
||||
|
||||
if (!successful) throw 'Invalid "data-action" attribute';
|
||||
if (!successful) throw new Error('Invalid "data-action" attribute');
|
||||
|
||||
this.dispatchEvent(actionAttr, selectedText, currentTrigger);
|
||||
window.getSelection().removeAllRanges();
|
||||
}
|
||||
catch (err) {
|
||||
throw new Error(err);
|
||||
supported = false;
|
||||
}
|
||||
|
||||
if (!supported) this.notSupported(currentTrigger);
|
||||
}
|
||||
|
||||
dispatchEvent(actionAttr, selectedText, currentTrigger) {
|
||||
var event = new CustomEvent(actionAttr, {
|
||||
let event = new CustomEvent(actionAttr, {
|
||||
detail: selectedText
|
||||
});
|
||||
|
||||
currentTrigger.dispatchEvent(event);
|
||||
}
|
||||
|
||||
notSupported(currentTrigger) {
|
||||
let event = new CustomEvent('no-support');
|
||||
currentTrigger.dispatchEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
global.Clipboard = Clipboard;
|
||||
|
Reference in New Issue
Block a user