2019-09-13 22:47:07 +12:00
|
|
|
(function(window) {
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
window.ls.container.get("view").add({
|
|
|
|
selector: "data-forms-copy",
|
|
|
|
controller: function(element, alerts, document, window) {
|
|
|
|
var button = window.document.createElement("i");
|
|
|
|
|
|
|
|
button.type = "button";
|
|
|
|
button.className = "icon-docs note copy";
|
|
|
|
button.style.cursor = "pointer";
|
|
|
|
|
|
|
|
element.parentNode.insertBefore(button, element.nextSibling);
|
|
|
|
|
|
|
|
var copy = function(event) {
|
2020-03-13 20:21:09 +13:00
|
|
|
let disabled = element.disabled;
|
|
|
|
|
2019-09-13 22:47:07 +12:00
|
|
|
element.disabled = false;
|
|
|
|
|
|
|
|
element.focus();
|
|
|
|
element.select();
|
|
|
|
|
|
|
|
document.execCommand("Copy");
|
|
|
|
|
|
|
|
if (document.selection) {
|
|
|
|
document.selection.empty();
|
|
|
|
} else if (window.getSelection) {
|
|
|
|
window.getSelection().removeAllRanges();
|
2019-05-09 18:54:39 +12:00
|
|
|
}
|
|
|
|
|
2020-03-13 20:21:09 +13:00
|
|
|
element.disabled = disabled;
|
2019-09-13 22:47:07 +12:00
|
|
|
|
2020-03-15 17:54:55 +13:00
|
|
|
element.blur();
|
|
|
|
|
2019-09-13 22:47:07 +12:00
|
|
|
alerts.add({ text: "Copied to clipboard", class: "" }, 3000);
|
|
|
|
};
|
|
|
|
|
|
|
|
button.addEventListener("click", copy);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
})(window);
|