107107 gap : 5px ;
108108 }
109109
110- .nav-center .nav-link : hover , .nav-center .dropdown : hover > .nav-link {
110+ .nav-center .nav-link : hover ,
111+ .nav-center .nav-link .active-page ,
112+ .nav-center .dropdown : hover > .nav-link {
111113 color : var (--accent-blue );
112114 }
113115
347349 < a href ="/homelab " class ="nav-link {% if page.url contains 'homelab' %}active-page{% endif %} "> HomeLab</ a >
348350 < a href ="/sponsors " class ="nav-link {% if page.url contains 'sponsors' %}active-page{% endif %} "> Sponsors</ a >
349351
350- < div class ="dropdown nav-link " style ="padding: 0; ">
352+ < div class ="dropdown nav-link {% if page.url contains 'orbit' or page.url contains 'homelab-cc' or page.url contains 'phone' or page.url contains 'apps' %}active-page{% endif %} " style ="padding: 0; ">
351353 < a href ="# " class ="nav-link dropbtn " onclick ="return false; "> Apps ▾</ a >
352354 < div class ="dropdown-content ">
353355 < div class ="dropdown-links-wrapper ">
@@ -457,13 +459,16 @@ <h4>Follow DevLabStudy</h4>
457459 < script >
458460 const navCenter = document . getElementById ( 'navCenter' ) ;
459461 const indicator = document . getElementById ( 'navIndicator' ) ;
460- const navLinks = navCenter . querySelectorAll ( ':scope > .nav-link' ) ;
461- const activeLink = navCenter . querySelector ( '.active-page' ) || navLinks [ 0 ] ;
462+ // Pobieramy wyłącznie bezpośrednie elementy nawigacyjne poziomu pierwszego
463+ const topNavItems = Array . from ( navCenter . querySelectorAll ( ':scope > .nav-link, :scope > .dropdown' ) ) ;
464+ const activeItem = navCenter . querySelector ( '.active-page' ) || topNavItems [ 0 ] ;
462465
463466 function moveIndicator ( el ) {
464467 if ( ! el ) return ;
465- indicator . style . width = el . offsetWidth + 'px' ;
466- indicator . style . left = el . offsetLeft + 'px' ;
468+ // Pobieramy element przycisku wewnątrz .dropdown lub sam el
469+ const targetEl = el . classList . contains ( 'dropdown' ) ? el . querySelector ( '.dropbtn' ) || el : el ;
470+ indicator . style . width = targetEl . offsetWidth + 'px' ;
471+ indicator . style . left = targetEl . offsetLeft + 'px' ;
467472 }
468473
469474 const savedLeft = sessionStorage . getItem ( 'nav_indicator_left' ) ;
@@ -475,24 +480,32 @@ <h4>Follow DevLabStudy</h4>
475480 indicator . style . width = savedWidth ;
476481 void indicator . offsetHeight ;
477482 indicator . style . transition = '' ;
478- moveIndicator ( activeLink ) ;
483+ moveIndicator ( activeItem ) ;
479484 } else {
480- moveIndicator ( activeLink ) ;
485+ moveIndicator ( activeItem ) ;
481486 }
482487
483- navLinks . forEach ( link => {
484- link . addEventListener ( 'click' , ( ) => {
485- sessionStorage . setItem ( 'nav_indicator_left ', link . offsetLeft + 'px' ) ;
486- sessionStorage . setItem ( 'nav_indicator_width' , link . offsetWidth + 'px' ) ;
488+ topNavItems . forEach ( item => {
489+ // Reagujemy na najechanie na element górnego menu (w tym całe rozwijane menu .dropdown)
490+ item . addEventListener ( 'mouseenter ', ( ) => {
491+ moveIndicator ( item ) ;
487492 } ) ;
488493
489- link . addEventListener ( 'mouseenter' , ( ) => {
490- moveIndicator ( link ) ;
494+ // Rejestrujemy kliknięcie na wszystkie linki (zarówno z głównego paska jak i rozwijanego menu)
495+ const linksInItem = item . querySelectorAll ( 'a' ) ;
496+ linksInItem . forEach ( link => {
497+ link . addEventListener ( 'click' , ( e ) => {
498+ if ( link . getAttribute ( 'href' ) === '#' ) return ;
499+ const targetToSave = item . classList . contains ( 'dropdown' ) ? ( item . querySelector ( '.dropbtn' ) || item ) : item ;
500+ sessionStorage . setItem ( 'nav_indicator_left' , targetToSave . offsetLeft + 'px' ) ;
501+ sessionStorage . setItem ( 'nav_indicator_width' , targetToSave . offsetWidth + 'px' ) ;
502+ } ) ;
491503 } ) ;
492504 } ) ;
493505
506+ // Wskaźnik wraca do aktywnej zakładki dopiero gdy kursor opuści cały navCenter
494507 navCenter . addEventListener ( 'mouseleave' , ( ) => {
495- moveIndicator ( activeLink ) ;
508+ moveIndicator ( activeItem ) ;
496509 } ) ;
497510 </ script >
498511</ body >
0 commit comments