updated plugin Gitium
version 1.2.1
This commit is contained in:
38
wp-content/plugins/gitium/js/copy-to-clipboard.js
Normal file
38
wp-content/plugins/gitium/js/copy-to-clipboard.js
Normal file
@ -0,0 +1,38 @@
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
const copyButton = document.getElementById('copyButton');
|
||||
|
||||
copyButton.addEventListener('click', function() {
|
||||
// Get the text to copy from the button's data attribute
|
||||
const textToCopy = copyButton.getAttribute('data-copy-text');
|
||||
|
||||
// Check if navigator.clipboard is supported
|
||||
if (navigator.clipboard && navigator.clipboard.writeText) {
|
||||
navigator.clipboard.writeText(textToCopy)
|
||||
.then(() => {
|
||||
alert('Copied to clipboard using navigator: ' + textToCopy);
|
||||
})
|
||||
.catch(err => {
|
||||
console.error('Could not copy text with navigator: ', err);
|
||||
});
|
||||
} else {
|
||||
// Deprecated fallback for older browsers
|
||||
console.warn('Using deprecated document.execCommand("copy") as a fallback. Update your browser for better clipboard support.');
|
||||
|
||||
// Fallback using document.execCommand
|
||||
const tempTextarea = document.createElement('textarea');
|
||||
tempTextarea.value = textToCopy;
|
||||
document.body.appendChild(tempTextarea);
|
||||
tempTextarea.select();
|
||||
|
||||
try {
|
||||
document.execCommand('copy');
|
||||
alert('Copied to clipboard (using fallback): ' + textToCopy);
|
||||
} catch (err) {
|
||||
console.error('Fallback copy failed: ', err);
|
||||
}
|
||||
|
||||
// Remove the temporary textarea
|
||||
document.body.removeChild(tempTextarea);
|
||||
}
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user