Remove mobile menu copy/paste shenanigans

Copying the main nav into the mobile nav to reduce the page load might technically make sense, but the trouble vastly outweighs the benefit.
This commit is contained in:
Tetrakern 2024-06-12 12:06:26 +02:00
parent c25e83880b
commit 1a814ac0a8
5 changed files with 38 additions and 37 deletions

View File

@ -257,13 +257,38 @@ add_action( 'fictioneer_mobile_menu_center', 'fictioneer_mobile_chapters_frame',
*/
function fictioneer_mobile_navigation_panel() {
if ( ! has_nav_menu( 'nav_menu' ) ) {
return;
}
// Start HTML ---> ?>
<nav id="mobile-navigation" class="mobile-navigation mobile-menu__panel"><?php
// Cloned from the main navigation via JS
if ( has_nav_menu( 'nav_menu' ) ) {
$menu = null;
if ( FICTIONEER_ENABLE_MENU_TRANSIENTS ) {
$menu = get_transient( 'fictioneer_mobile_nav_menu_html' );
}
if ( empty( $menu ) ) {
$menu = wp_nav_menu(
array(
'theme_location' => 'nav_menu',
'menu_class' => 'mobile-navigation__list',
'container' => '',
'menu_id' => 'mobile-menu-navigation',
'items_wrap' => '<ul id="%1$s" data-menu-id="mobile" class="%2$s">%3$s</ul>',
'echo' => false
)
);
if ( $menu !== false ) {
$menu = str_replace( ['current_page_item', 'current-menu-item', 'aria-current="page"'], '', $menu );
}
if ( FICTIONEER_ENABLE_MENU_TRANSIENTS ) {
set_transient( 'fictioneer_mobile_nav_menu_html', $menu );
}
}
echo $menu;
}
?></nav>
<?php // <--- End HTML
}

8
js/complete.min.js vendored

File diff suppressed because one or more lines are too long

View File

@ -1 +1 @@
function fcn_toggleMobileMenu(e){fcn_copyNavIntoMobileMenu(),_$(".mobile-menu._advanced-mobile-menu")?fcn_toggleAdvancedMobileMenu(e):fcn_toggleSimpleMobileMenu(e)}function fcn_toggleSimpleMobileMenu(e){e?(fcn_theBody.classList.add("mobile-menu-open","scrolling-down"),fcn_theBody.classList.remove("scrolling-up")):(fcn_theBody.classList.remove("mobile-menu-open"),fcn_closeMobileFrames(),fcn_openMobileFrame("main"),_$$$("mobile-menu-toggle").checked=!1)}function fcn_toggleAdvancedMobileMenu(e){const n=_$$$("wpadminbar")?.offsetHeight??0,o=window.scrollY,t=fcn_theSite.scrollTop;e?(fcn_theBody.classList.add("mobile-menu-open","scrolling-down","scrolled-to-top"),fcn_theBody.classList.remove("scrolling-up"),fcn_theSite.classList.add("transformed-scroll","transformed-site"),fcn_theSite.scrollTop=o-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"),fcn_theRoot.style.scrollBehavior="auto",window.scroll(0,t+n),fcn_theRoot.style.scrollBehavior="",_$$$("mobile-menu-toggle").checked=!1,"function"==typeof fcn_trackProgress&&fcn_trackProgress())}function fcn_copyNavIntoMobileMenu(){const e=_$('[data-menu-id="main"]'),n=_$$$("mobile-navigation");if(e&&n&&!n.querySelector("ul")){const o=e.cloneNode(!0);o.id="mobile-menu-navigation",o.classList.replace("main-navigation__list","mobile-navigation__list"),o.dataset.menuId="mobile",n.appendChild(o)}}function fcn_setupMobileJumpButton(e,n){const o=_$(e);o&&o.addEventListener("click",(()=>{fcn_toggleMobileMenu(!1),setTimeout((()=>{const e=n();e&&fcn_scrollTo(e)}),200)}))}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))}_$$$("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))})),fcn_setupMobileJumpButton("#mobile-menu-comment-jump",(()=>_$$$("comments"))),fcn_setupMobileJumpButton("#mobile-menu-bookmark-jump",(()=>_$(`[data-paragraph-id="${fcn_bookmarks.data[_$("article").id]["paragraph-id"]}"]`))),_$$(".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",(()=>{fcn_setMobileMenuBookmarks()}),{once:!0});
function fcn_toggleMobileMenu(e){_$(".mobile-menu._advanced-mobile-menu")?fcn_toggleAdvancedMobileMenu(e):fcn_toggleSimpleMobileMenu(e)}function fcn_toggleSimpleMobileMenu(e){e?(fcn_theBody.classList.add("mobile-menu-open","scrolling-down"),fcn_theBody.classList.remove("scrolling-up")):(fcn_theBody.classList.remove("mobile-menu-open"),fcn_closeMobileFrames(),fcn_openMobileFrame("main"),_$$$("mobile-menu-toggle").checked=!1)}function fcn_toggleAdvancedMobileMenu(e){const n=_$$$("wpadminbar")?.offsetHeight??0,t=window.scrollY,o=fcn_theSite.scrollTop;e?(fcn_theBody.classList.add("mobile-menu-open","scrolling-down","scrolled-to-top"),fcn_theBody.classList.remove("scrolling-up"),fcn_theSite.classList.add("transformed-scroll","transformed-site"),fcn_theSite.scrollTop=t-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"),fcn_theRoot.style.scrollBehavior="auto",window.scroll(0,o+n),fcn_theRoot.style.scrollBehavior="",_$$$("mobile-menu-toggle").checked=!1,"function"==typeof fcn_trackProgress&&fcn_trackProgress())}function fcn_setupMobileJumpButton(e,n){const t=_$(e);t&&t.addEventListener("click",(()=>{fcn_toggleMobileMenu(!1),setTimeout((()=>{const e=n();e&&fcn_scrollTo(e)}),200)}))}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))}_$$$("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))})),fcn_setupMobileJumpButton("#mobile-menu-comment-jump",(()=>_$$$("comments"))),fcn_setupMobileJumpButton("#mobile-menu-bookmark-jump",(()=>_$(`[data-paragraph-id="${fcn_bookmarks.data[_$("article").id]["paragraph-id"]}"]`))),_$$(".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",(()=>{fcn_setMobileMenuBookmarks()}),{once:!0});

View File

@ -71,16 +71,14 @@ if ( $header_style === 'wide' ) {
'theme_location' => 'nav_menu',
'menu_class' => 'main-navigation__list',
'container' => '',
'items_wrap' => '<ul id="%1$s" class="%2$s">%3$s</ul>',
'menu_id' => 'menu-navigation',
'items_wrap' => '<ul id="%1$s" data-menu-id="main" class="%2$s">%3$s</ul>',
'echo' => false
)
);
if ( $menu !== false ) {
$menu = str_replace( 'class="', 'data-menu-id="main" class="', $menu );
$menu = str_replace( 'current_page_item', '', $menu );
$menu = str_replace( 'current-menu-item', '', $menu );
$menu = str_replace( 'aria-current="page"', '', $menu );
$menu = str_replace( ['current_page_item', 'current-menu-item', 'aria-current="page"'], '', $menu );
}
if ( FICTIONEER_ENABLE_MENU_TRANSIENTS ) {

View File

@ -11,7 +11,6 @@
function fcn_toggleMobileMenu(isOpened) {
// Clone main navigation into mobile menu
fcn_copyNavIntoMobileMenu();
if (_$('.mobile-menu._advanced-mobile-menu')) {
fcn_toggleAdvancedMobileMenu(isOpened);
@ -103,27 +102,6 @@ fcn_theSite.addEventListener('click', event => {
}
});
/**
* Copy and adjust navigation to mobile menu.
*
* @since 5.4.2
*/
function fcn_copyNavIntoMobileMenu() {
const mainMenu = _$('[data-menu-id="main"]');
const mobileNav = _$$$('mobile-navigation');
if (mainMenu && mobileNav && !mobileNav.querySelector('ul')) {
const clone = mainMenu.cloneNode(true);
clone.id = 'mobile-menu-navigation';
clone.classList.replace('main-navigation__list', 'mobile-navigation__list');
clone.dataset.menuId = 'mobile';
mobileNav.appendChild(clone);
}
}
// =============================================================================
// JUMP BUTTONS
// =============================================================================