* Lint fixes. * Implement light-dark(). * Lint css with biome, remove stylelint. * Biome lint fixes. * Dark mode adjustments. * Style bug fixes. * Colour adjustments. * Move header and footer styles to base. * Site header adjustments. * Removing jQuery and umbrella libs. They where great but not needed anymore. * Add colorScheme to optionally lock light/dark. * Update README. * Biome adjustments.
28 lines
838 B
JavaScript
28 lines
838 B
JavaScript
/**
|
|
* @file
|
|
* A JavaScript file to add a copy code button to codeblocks.
|
|
*/
|
|
|
|
(function () {
|
|
async function writeClipboardText(text) {
|
|
try {
|
|
await navigator.clipboard.writeText(text);
|
|
} catch (error) {
|
|
console.error(error.message);
|
|
}
|
|
}
|
|
|
|
const copybuttons = document.querySelectorAll('[data-codebutton]');
|
|
copybuttons.forEach(function (button) {
|
|
button.addEventListener('click', function (e) {
|
|
const codeblock = e.target.parentElement;
|
|
const codesnippet = codeblock.querySelector('[data-codetext]').getAttribute('content');
|
|
const codearea = codeblock.querySelector('pre');
|
|
codearea.classList.add('flash-item');
|
|
writeClipboardText(JSON.parse(codesnippet));
|
|
setTimeout(function () {
|
|
codearea.classList.remove('flash-item');
|
|
}, 700);
|
|
});
|
|
});
|
|
})();
|