2024-10-11 17:32:10 +03:00
|
|
|
import { TocMobile as mobile } from './toc/toc-mobile';
|
|
|
|
import { TocDesktop as desktop } from './toc/toc-desktop';
|
|
|
|
|
|
|
|
const desktopMode = matchMedia('(min-width: 1200px)');
|
|
|
|
|
|
|
|
function refresh(e) {
|
|
|
|
if (e.matches) {
|
|
|
|
mobile.hidePopup();
|
|
|
|
desktop.refresh();
|
|
|
|
} else {
|
|
|
|
mobile.refresh();
|
2023-03-31 00:05:33 +03:00
|
|
|
}
|
2023-03-15 21:56:54 +03:00
|
|
|
}
|
2024-10-11 17:32:10 +03:00
|
|
|
|
|
|
|
function init() {
|
|
|
|
if (document.querySelector('main>article[data-toc="true"]') === null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Avoid create multiple instances of Tocbot. Ref: <https://github.com/tscanlin/tocbot/issues/203>
|
|
|
|
if (desktopMode.matches) {
|
|
|
|
desktop.init();
|
|
|
|
} else {
|
|
|
|
mobile.init();
|
|
|
|
}
|
|
|
|
|
|
|
|
desktopMode.onchange = refresh;
|
|
|
|
}
|
|
|
|
|
|
|
|
export { init as initToc };
|