diff options
| author | Danilo M. <danix@danix.xyz> | 2026-04-22 12:43:22 +0200 |
|---|---|---|
| committer | Danilo M. <danix@danix.xyz> | 2026-04-22 12:43:22 +0200 |
| commit | 5b476f8905f411768e23cb01d577a60e5a5fd725 (patch) | |
| tree | 0a08cc83d809dbea714f52826e822501ee7c0165 /themes/danix-xyz-hacker/assets/js/code-copy.js | |
| parent | 082e9246ffe453031894d32d3cee9d5d1bf2b67a (diff) | |
| download | danixxyz-5b476f8905f411768e23cb01d577a60e5a5fd725.tar.gz danixxyz-5b476f8905f411768e23cb01d577a60e5a5fd725.zip | |
chore: extract theme into git submodule (danix2-hugo-theme)
Diffstat (limited to 'themes/danix-xyz-hacker/assets/js/code-copy.js')
| -rw-r--r-- | themes/danix-xyz-hacker/assets/js/code-copy.js | 79 |
1 files changed, 0 insertions, 79 deletions
diff --git a/themes/danix-xyz-hacker/assets/js/code-copy.js b/themes/danix-xyz-hacker/assets/js/code-copy.js deleted file mode 100644 index 8591436..0000000 --- a/themes/danix-xyz-hacker/assets/js/code-copy.js +++ /dev/null @@ -1,79 +0,0 @@ -(function () { - var LANG_NAMES = { - bash: 'Shell', sh: 'Shell', shell: 'Shell', zsh: 'Shell', - js: 'JavaScript', javascript: 'JavaScript', - ts: 'TypeScript', typescript: 'TypeScript', - go: 'Go', - py: 'Python', python: 'Python', - rs: 'Rust', rust: 'Rust', - html: 'HTML', - css: 'CSS', - toml: 'TOML', - yaml: 'YAML', yml: 'YAML', - json: 'JSON', - sql: 'SQL', - md: 'Markdown', markdown: 'Markdown', - c: 'C', - cpp: 'C++', 'c++': 'C++', - java: 'Java', - php: 'PHP', - ruby: 'Ruby', rb: 'Ruby', - swift: 'Swift', - kotlin: 'Kotlin', kt: 'Kotlin', - dockerfile: 'Dockerfile', - makefile: 'Makefile', - text: 'Text', txt: 'Text', - }; - - function prettyName(lang) { - if (!lang) return ''; - var key = lang.toLowerCase(); - return LANG_NAMES[key] || (lang.charAt(0).toUpperCase() + lang.slice(1)); - } - - function getCodeText(wrapper) { - var el = wrapper.querySelector('.lntd:last-child code') - || wrapper.querySelector('.code-body code') - || wrapper.querySelector('.code-body pre'); - return el ? el.innerText : ''; - } - - function initBlock(wrapper) { - var header = wrapper.querySelector('.code-header'); - if (header) { - var label = wrapper.querySelector('.code-lang-label'); - if (label) label.textContent = prettyName(header.getAttribute('data-lang') || ''); - } - - var btn = wrapper.querySelector('[data-copy-target]'); - if (!btn) return; - - btn.addEventListener('click', function () { - var text = getCodeText(wrapper); - if (!text) return; - - navigator.clipboard.writeText(text).then(function () { - var copyIcon = btn.querySelector('.icon-copy'); - var checkIcon = btn.querySelector('.icon-check'); - var liveRegion = wrapper.querySelector('.code-copy-status'); - if (copyIcon) copyIcon.classList.add('hidden'); - if (checkIcon) checkIcon.classList.remove('hidden'); - btn.classList.add('is-copied'); - if (liveRegion) liveRegion.textContent = 'Code copied to clipboard.'; - - setTimeout(function () { - if (copyIcon) copyIcon.classList.remove('hidden'); - if (checkIcon) checkIcon.classList.add('hidden'); - btn.classList.remove('is-copied'); - if (liveRegion) liveRegion.textContent = ''; - }, 2000); - }).catch(function () { - // silent fail for insecure contexts - }); - }); - } - - document.addEventListener('DOMContentLoaded', function () { - document.querySelectorAll('.code-block-wrapper').forEach(initBlock); - }); -})(); |
