1
0
Fork 0
mirror of synced 2024-07-06 07:00:56 +12:00
appwrite/public/scripts/views/forms/copy.js

40 lines
1.2 KiB
JavaScript
Raw Normal View History

2019-05-09 18:54:39 +12:00
(function (window) {
"use strict";
2019-05-09 20:01:51 +12:00
window.ls.container.get('view').add(
2019-05-09 18:54:39 +12:00
{
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) {
window.getSelection().removeAllRanges();
var range = document.createRange();
range.selectNode(element);
window.getSelection().addRange(range);
try {
document.execCommand('copy');
2019-08-08 08:35:20 +12:00
alerts.add({text: 'Copied to clipboard', class: ''}, 3000);
2019-05-09 18:54:39 +12:00
} catch (err) {
2019-08-08 08:35:20 +12:00
alerts.add({text: "Failed to copy text ", class: 'error'}, 3000);
2019-05-09 18:54:39 +12:00
}
window.getSelection().removeAllRanges();
};
button.addEventListener('click', copy);
}
}
);
})(window);