Skip to content

Commit 287adcf

Browse files
committed
refactor(clipboard): enhanced csk.ui.clipboard()
Also bumped version to `1.5.9`.
1 parent dcabe23 commit 287adcf

3 files changed

Lines changed: 16 additions & 7 deletions

File tree

js/admin.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -328,13 +328,22 @@
328328
* Copy to clipboard.
329329
* @since 2.18
330330
*/
331-
clipboard: function(el) {
332-
var copyText = el.getAttribute("data-text");
331+
clipboard: function (el) {
332+
const copyText = el.getAttribute("data-text");
333333
if (!copyText?.length) {
334-
return false;
334+
csk.ui.alert(csk.i18n.default.clipboard_copy_error, "error");
335+
return;
336+
}
337+
338+
if (!navigator.clipboard?.writeText) {
339+
csk.ui.alert(csk.i18n.default.clipboard_copy_error, "error");
340+
return;
335341
}
336-
navigator.clipboard.writeText(copyText);
337-
csk.ui.alert(csk.i18n.media.copied, "success");
342+
343+
navigator.clipboard
344+
.writeText(copyText)
345+
.then(() => csk.ui.alert(csk.i18n.default.clipboard_copy_success, "success"))
346+
.catch(() => csk.ui.alert(csk.i18n.default.clipboard_copy_error, "error"));
338347
},
339348

340349
/**

0 commit comments

Comments
 (0)