doc.yeswiki.pro/node_modules/vitepress/dist/client/app/composables/codeGroups.js

20 lines
845 B
JavaScript
Raw Normal View History

2023-05-20 16:37:42 +00:00
import { inBrowser } from 'vitepress';
export function useCodeGroups() {
if (inBrowser) {
window.addEventListener('click', (e) => {
const el = e.target;
if (el.matches('.vp-code-group input')) {
// input <- .tabs <- .vp-code-group
const group = el.parentElement?.parentElement;
const i = Array.from(group?.querySelectorAll('input') || []).indexOf(el);
const current = group?.querySelector('div[class*="language-"].active');
const next = group?.querySelectorAll('div[class*="language-"]:not(.language-id)')?.[i];
if (current && next && current !== next) {
current.classList.remove('active');
next.classList.add('active');
}
}
});
}
}