44 Copyright 2013-2016 Blackrock Digital LLC
55 MIT License
66 Modified by Raphael Michel
7+ Modified by eventyay team to add sidebar toggle functionality
78 */
89//Loads the correct sidebar on window load,
910//collapses the sidebar on window resize.
1011// Sets the min-height of #page-wrapper to window size
1112$ ( function ( ) {
1213 'use strict' ;
14+
15+ const $body = $ ( 'body' ) ;
16+ const $sidebar = $ ( '.sidebar' ) ;
17+ const $sidebarToggleButton = $ ( '#sidebar-toggle' ) ;
18+
19+ function isMobileView ( ) {
20+ return window . matchMedia ( "(max-width: 767px)" ) . matches ;
21+ }
22+
23+ function isTabletView ( ) {
24+ return window . matchMedia ( "(min-width: 768px) and (max-width: 1024px)" ) . matches ;
25+ }
26+
27+ function isDesktopView ( ) {
28+ return window . matchMedia ( "(min-width: 1025px)" ) . matches ;
29+ }
30+
31+ function isTabletOrDesktop ( ) {
32+ return window . matchMedia ( "(min-width: 768px)" ) . matches ;
33+ }
34+
35+ function toggleSidebar ( ) {
36+ if ( isMobileView ( ) ) {
37+ // Mobile: Simple toggle without localStorage
38+ $body . toggleClass ( 'sidebar-minimized' ) ;
39+ } else if ( isTabletOrDesktop ( ) ) {
40+ // Desktop/Tablet: Toggle with localStorage persistence
41+ $body . toggleClass ( 'sidebar-minimized' ) ;
42+ localStorage . setItem ( 'sidebar-minimized' , $body . hasClass ( 'sidebar-minimized' ) ) ;
43+ }
44+ }
45+
46+ function initializeSidebar ( ) {
47+ // Initialize metisMenu with toggle: false to allow multiple menus to be open
48+ $ ( '#side-menu' ) . metisMenu ( {
49+ toggle : false
50+ } ) ;
51+
52+ if ( isMobileView ( ) ) {
53+ // Mobile: Always start minimized, no localStorage
54+ $body . addClass ( 'sidebar-minimized' ) ;
55+ } else {
56+ // Desktop/Tablet: Start minimized by default, but allow localStorage override
57+ if ( localStorage . getItem ( 'sidebar-minimized' ) === null ) {
58+ // First time visit - set to minimized by default
59+ $body . addClass ( 'sidebar-minimized' ) ;
60+ localStorage . setItem ( 'sidebar-minimized' , 'true' ) ;
61+ } else if ( localStorage . getItem ( 'sidebar-minimized' ) === 'true' ) {
62+ $body . addClass ( 'sidebar-minimized' ) ;
63+ } else {
64+ $body . removeClass ( 'sidebar-minimized' ) ;
65+ }
66+ }
67+ }
68+
69+ // Remove the replaceNavbarCollapseWithSidebarToggle function entirely
70+ // since we're removing the navbar collapse button
71+
72+ initializeSidebar ( ) ;
73+
74+ // SIDEBAR TOGGLE: Handle the sidebar burger button specifically (LEFT BUTTON)
75+ $sidebarToggleButton . on ( 'click' , function ( e ) {
76+ e . preventDefault ( ) ;
77+ e . stopPropagation ( ) ;
78+ toggleSidebar ( ) ;
79+ } ) ;
80+
81+ // DESKTOP-ONLY: Hover functionality
82+ $sidebar . on ( 'mouseenter' , function ( ) {
83+ if ( isDesktopView ( ) && $body . hasClass ( 'sidebar-minimized' ) ) {
84+ $body . addClass ( 'sidebar-hover' ) ;
85+ }
86+ } ) . on ( 'mouseleave' , function ( ) {
87+ if ( isDesktopView ( ) ) {
88+ $body . removeClass ( 'sidebar-hover' ) ;
89+ }
90+ } ) ;
91+
92+ // REMOVE the submenu collapse functionality since we want to allow multiple submenus to stay open
93+ // The metisMenu with toggle: false will handle this correctly
94+
95+ // UNIVERSAL: Window resize handler
96+ let resizeTimeout ;
97+ $ ( window ) . on ( 'resize' , function ( ) {
98+ clearTimeout ( resizeTimeout ) ;
99+ resizeTimeout = setTimeout ( function ( ) {
100+ // Re-initialize based on current screen size
101+ if ( isMobileView ( ) ) {
102+ // Mobile: Force minimized state
103+ $body . addClass ( 'sidebar-minimized' ) ;
104+ $body . removeClass ( 'sidebar-hover' ) ;
105+ } else {
106+ // Desktop/Tablet: Restore from localStorage
107+ if ( localStorage . getItem ( 'sidebar-minimized' ) === 'true' ) {
108+ $body . addClass ( 'sidebar-minimized' ) ;
109+ } else {
110+ $body . removeClass ( 'sidebar-minimized' ) ;
111+ }
112+ }
113+ } , 250 ) ;
114+ } ) ;
115+
13116 $ ( window ) . bind ( "load resize" , function ( ) {
14117 var topOffset = 50 ,
15118 width = ( this . window . innerWidth > 0 ) ? this . window . innerWidth : this . screen . width ;
@@ -29,7 +132,8 @@ $(function () {
29132 } ) ;
30133
31134 $ ( 'ul.nav ul.nav-second-level a.active' ) . parent ( ) . parent ( ) . addClass ( 'in' ) . parent ( ) . addClass ( 'active' ) ;
135+ // Initialize metisMenu with toggle: false to allow multiple menus to be open
32136 $ ( '#side-menu' ) . metisMenu ( {
33137 'toggle' : false ,
34138 } ) ;
35- } ) ;
139+ } ) ;
0 commit comments