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) {
|
2024-10-19 16:13:21 +03:00
|
|
|
if (mobile.popupOpened) {
|
|
|
|
mobile.hidePopup();
|
|
|
|
}
|
|
|
|
|
2024-10-11 17:32:10 +03:00
|
|
|
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 };
|