Skip to content
This repository was archived by the owner on Jan 13, 2025. It is now read-only.

Commit ab32526

Browse files
committed
Improve Copy to Clipboard button with popup
1 parent 7b0bfef commit ab32526

1 file changed

Lines changed: 22 additions & 1 deletion

File tree

src/main/web/app/Ui.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,16 @@ export default class Ui {
2727
on: "click",
2828
target: Ui.urlType
2929
});
30-
new Clipboard("#copy-ontology-to-clipboard-button");
30+
31+
let clipboard = new Clipboard(Ui.copyToClipboardButton[0]);
32+
clipboard.on("success", e => {
33+
e.clearSelection();
34+
Ui.showCopyToClipboardResult();
35+
});
36+
clipboard.on("error", e => {
37+
Ui.showCopyToClipboardResult(false);
38+
});
39+
Ui.copyToClipboardButton.on("mouseleave", () => Ui.copyToClipboardButton.popup("hide"));
3140
}
3241

3342
static displayFormats(formats) {
@@ -137,6 +146,14 @@ export default class Ui {
137146
}
138147
}
139148

149+
static showCopyToClipboardResult(success = true) {
150+
Ui.copyToClipboardButton.popup({
151+
content: success ? "Copied!" : "Press Ctrl+C to copy",
152+
position: "bottom center",
153+
on: "manual"
154+
}).popup("show");
155+
}
156+
140157
static _initializeSelectionButtons(container) {
141158
container.on("click", ".select-all-button", function () {
142159
$(this).parent().parent().parent().find(":checkbox").prop("checked", true)
@@ -209,4 +226,8 @@ export default class Ui {
209226
static get webvowlButton() {
210227
return $("#webvowl-button");
211228
}
229+
230+
static get copyToClipboardButton() {
231+
return $("#copy-ontology-to-clipboard-button");
232+
}
212233
}

0 commit comments

Comments
 (0)