mirror of
https://codeberg.org/PostERG/xamxam.git
synced 2026-06-25 16:19:19 +02:00
31 lines
993 B
JavaScript
31 lines
993 B
JavaScript
/**
|
|
* acces-password.js — copy text to clipboard helper.
|
|
*
|
|
* Usage:
|
|
* copyTextToClipboard('some text')
|
|
*
|
|
* Provides visual feedback on the originating button.
|
|
*/
|
|
(function () {
|
|
'use strict';
|
|
|
|
window.copyTextToClipboard = function (text) {
|
|
if (!text) return;
|
|
navigator.clipboard.writeText(text).then(function () {
|
|
var btn = window.event && window.event.target ? window.event.target.closest('button') : null;
|
|
if (btn) {
|
|
var origTitle = btn.getAttribute('title') || '';
|
|
var origHTML = btn.innerHTML;
|
|
btn.setAttribute('title', '\u2713 Copi\u00e9');
|
|
btn.innerHTML = '\u2713';
|
|
setTimeout(function () {
|
|
btn.setAttribute('title', origTitle);
|
|
btn.innerHTML = origHTML;
|
|
}, 1200);
|
|
}
|
|
}).catch(function () {
|
|
// Clipboard write failed — silently ignore
|
|
});
|
|
};
|
|
})();
|