1
0
Fork 0
mirror of synced 2024-07-06 15:11:21 +12:00
appwrite/public/scripts/views/general/copy.js
2021-08-16 00:09:40 +03:00

44 lines
1.3 KiB
JavaScript

(function(window) {
"use strict";
window.ls.view.add({
selector: 'data-general-copy',
repeat: false,
controller: function(document, element, alerts) {
let button = document.createElement("i");
button.type = "button";
button.title = "Copy to Clipboard";
button.className = element.getAttribute("data-class") || "icon-docs note copy";
button.style.cursor = "pointer";
element.parentNode.insertBefore(button, element.nextSibling);
let copy = function(event) {
window.getSelection().removeAllRanges();
let range = document.createRange();
range.selectNode(element);
window.getSelection().addRange(range);
try {
document.execCommand("copy");
alerts.add({
text: "Copied to clipboard",
class: ""
}, 3000);
} catch (err) {
alerts.add({
text: "Failed to copy text ",
class: "error"
}, 3000);
}
window.getSelection().removeAllRanges();
};
button.addEventListener("click", copy);
}
});
})(window);