fictioneer/js/mobile-menu.min.js
Tetrakern a70a80875e Clone main nav into mobile nav
Probably won't save queries, but it does save some microseconds render time! Yay?
2023-08-04 10:21:06 +02:00

1 line
4.2 KiB
JavaScript

const fcn_mobileMenuToggle=_$$$("mobile-menu-toggle"),fcn_mobileMenuBottom=_$(".mobile-menu__bottom"),fcn_mobileMenuUser=_$$$("mobile-menu-user-panel"),fcn_mobileMenuNav=_$$$("mobile-navigation");var fcn_mobileMenuNavElements=[],fcn_mobileMenuUserElements=[],fcn_mobileMenuBottomElements=[];function fcn_toggleMobileMenu(e){const n=_$$$("wpadminbar")?.offsetHeight??0;e?(fcn_toggleMobileMenuContent(),fcn_theBody.classList.add("mobile-menu-open","scrolling-down"),fcn_theBody.classList.remove("scrolling-up"),fcn_theSite.classList.add("transformed-scroll","transformed-site"),fcn_theSite.scrollTop=window.scrollY-n,fcn_updateThemeColor()):(fcn_theSite.classList.remove("transformed-site","transformed-scroll"),fcn_theBody.classList.remove("mobile-menu-open"),fcn_updateThemeColor(),fcn_closeMobileFrames(),fcn_openMobileFrame("main"),window.scroll(0,fcn_theSite.scrollTop+n),fcn_mobileMenuToggle.checked=!1,fcn_toggleMobileMenuContent(!1),"function"==typeof fcn_trackProgress&&fcn_trackProgress())}function fcn_toggleMobileMenuContent(e=!0){if(e)fcn_mobileMenuNavElements.forEach((e=>{fcn_mobileMenuNav.appendChild(e)})),fcn_mobileMenuNavElements=[],fcn_mobileMenuUserElements.forEach((e=>{fcn_mobileMenuUser.appendChild(e)})),fcn_mobileMenuUserElements=[],fcn_mobileMenuBottomElements.forEach((e=>{fcn_mobileMenuBottom.appendChild(e)})),fcn_mobileMenuBottomElements=[];else{for(;fcn_mobileMenuNav.firstChild;)fcn_mobileMenuNavElements.push(fcn_mobileMenuNav.removeChild(fcn_mobileMenuNav.firstChild));for(;fcn_mobileMenuUser.firstChild;)fcn_mobileMenuUserElements.push(fcn_mobileMenuUser.removeChild(fcn_mobileMenuUser.firstChild));for(;fcn_mobileMenuBottom.firstChild;)fcn_mobileMenuBottomElements.push(fcn_mobileMenuBottom.removeChild(fcn_mobileMenuBottom.firstChild))}}function fcn_copyNavIntoMobileMenu(){if(_$$$("menu-navigation")&&!_$("#mobile-navigation > ul")){const e=_$$$("menu-navigation").cloneNode(!0);e.id="mobile-menu-navigation",e.classList.remove("main-navigation__list"),e.classList.add("mobile-navigation__list"),_$$$("mobile-navigation").appendChild(e)}}function fcn_openMobileFrame(e){fcn_closeMobileFrames(),_$(`.mobile-menu__frame[data-frame="${e}"]`)?.classList.add("_active")}function fcn_closeMobileFrames(){_$$(".mobile-menu__frame._active").forEach((e=>{e.classList.remove("_active")}));const e=_$(".mobile-menu__bookmarks-panel");e&&(e.dataset.editing="false")}function fcn_appendChapterList(){const e=_$$$("mobile-menu-chapters-list");fcn_chapterList&&!e.hasChildNodes()&&e.appendChild(fcn_chapterList.cloneNode(!0))}fcn_copyNavIntoMobileMenu(),fcn_toggleMobileMenuContent(!1),_$$$("mobile-menu-toggle")?.addEventListener("change",(e=>{fcn_toggleMobileMenu(e.currentTarget.checked)})),fcn_theSite.addEventListener("click",(e=>{fcn_theBody.classList.contains("mobile-menu-open")&&(e.preventDefault(),fcn_toggleMobileMenu(!1))})),_$$$("mobile-menu-comment-jump")?.addEventListener("click",(()=>{fcn_toggleMobileMenu(!1),setTimeout((()=>{const e=_$$$("comments");e&&fcn_scrollTo(e)}),200)})),_$$$("mobile-menu-bookmark-jump")?.addEventListener("click",(()=>{fcn_toggleMobileMenu(!1),setTimeout((()=>{const e=_$(`[data-paragraph-id="${fcn_bookmarks.data[_$("article").id]["paragraph-id"]}"]`);e&&fcn_scrollTo(e)}),200)})),_$$(".button-change-lightness").forEach((e=>{e.addEventListener("click",(e=>{fcn_updateDarken(fcn_siteSettings.darken+parseFloat(e.currentTarget.value))}))})),_$$(".mobile-menu__frame-button").forEach((e=>{e.addEventListener("click",(e=>{fcn_openMobileFrame(e.currentTarget.dataset.frameTarget)}))})),_$$(".mobile-menu__back-button").forEach((e=>{e.addEventListener("click",(()=>{fcn_openMobileFrame("main")}))})),_$('.mobile-menu__frame-button[data-frame-target="chapters"]')?.addEventListener("click",(()=>{fcn_appendChapterList()}),{once:!0}),_$$$("micro-menu-label-open-chapter-list")?.addEventListener("click",(()=>{fcn_appendChapterList(),fcn_openMobileFrame("chapters")})),_$$$("button-mobile-menu-toggle-bookmarks-edit")?.addEventListener("click",(e=>{const n=e.currentTarget.closest(".mobile-menu__bookmarks-panel");n.dataset.editing="false"==n.dataset.editing?"true":"false"})),_$('.mobile-menu__frame-button[data-frame-target="bookmarks"]')?.addEventListener("click",(e=>{fcn_setMobileMenuBookmarks()}),{once:!0});