This commit is contained in:
parent
dacdc533da
commit
3ab1c0c119
21 changed files with 2244 additions and 0 deletions
40
theme/default/js/copy.js
Normal file
40
theme/default/js/copy.js
Normal file
|
@ -0,0 +1,40 @@
|
|||
/**
|
||||
* https://github.com/uiwjs/copy-to-clipboard/blob/master/src/main.js
|
||||
*/
|
||||
function copyTextToClipboard(text, cb) {
|
||||
const el = document.createElement('textarea');
|
||||
el.value = text;
|
||||
el.setAttribute('readonly', '');
|
||||
el.style = {
|
||||
position: 'absolute',
|
||||
left: '-9999px',
|
||||
};
|
||||
document.body.appendChild(el);
|
||||
const selected = document.getSelection().rangeCount > 0 ? document.getSelection().getRangeAt(0) : false;
|
||||
el.select();
|
||||
let isCopy = false;
|
||||
try {
|
||||
const successful = document.execCommand('copy');
|
||||
isCopy = !!successful;
|
||||
} catch (err) {
|
||||
isCopy = false;
|
||||
}
|
||||
document.body.removeChild(el);
|
||||
if (selected && document.getSelection) {
|
||||
document.getSelection().removeAllRanges();
|
||||
document.getSelection().addRange(selected);
|
||||
}
|
||||
cb && cb(isCopy);
|
||||
}
|
||||
|
||||
function copied(target, str) {
|
||||
target.classList.add('active');
|
||||
const input = target.parentElement.querySelector('input');
|
||||
if (input) {
|
||||
copyTextToClipboard(input.value || '', function () {
|
||||
setTimeout(() => {
|
||||
target.classList.remove('active');
|
||||
}, 2000);
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue