| @@ -67,8 +67,9 @@ | ||
| 67 | 67 | getFormState(); |
| 68 | 68 | |
| 69 | 69 | // Initialize sidebar toggle |
| 70 | 70 | initSidebarToggle(); |
| 71 | + initSidebarSubMenus(); | |
| 71 | 72 | initHeaderMoreActions(); |
| 72 | 73 | } catch ( e ) { |
| 73 | 74 | console.error( 'Error initializing builder components:', e ); |
| 74 | 75 | } |
| @@ -107,8 +108,39 @@ | ||
| 107 | 108 | } |
| 108 | 109 | |
| 109 | 110 | // Save state |
| 110 | 111 | localStorage.setItem( storageKey, willCollapse ? 'true' : 'false' ); |
| 112 | + } ); | |
| 113 | +}; | |
| 114 | + | |
| 115 | +/** | |
| 116 | + * Initialize nested sidebar submenu toggles. | |
| 117 | + */ | |
| 118 | +const initSidebarSubMenus = () => { | |
| 119 | + const sidebar = document.getElementById( 'lp-course-builder-sidebar' ); | |
| 120 | + | |
| 121 | + if ( ! sidebar || sidebar.dataset.subMenusInitialized === 'true' ) { | |
| 122 | + return; | |
| 123 | + } | |
| 124 | + | |
| 125 | + sidebar.dataset.subMenusInitialized = 'true'; | |
| 126 | + | |
| 127 | + sidebar.addEventListener( 'click', ( e ) => { | |
| 128 | + const toggleBtn = e.target.closest( '.lp-cb-sidebar__sub-menu-toggle' ); | |
| 129 | + | |
| 130 | + if ( ! toggleBtn || ! sidebar.contains( toggleBtn ) ) { | |
| 131 | + return; | |
| 132 | + } | |
| 133 | + | |
| 134 | + const item = toggleBtn.closest( '.lp-cb-sidebar__item.has-sub-menu' ); | |
| 135 | + if ( ! item ) { | |
| 136 | + return; | |
| 137 | + } | |
| 138 | + | |
| 139 | + e.preventDefault(); | |
| 140 | + | |
| 141 | + const isExpanded = item.classList.toggle( 'is-expanded' ); | |
| 142 | + toggleBtn.setAttribute( 'aria-expanded', isExpanded ? 'true' : 'false' ); | |
| 111 | 143 | } ); |
| 112 | 144 | }; |
| 113 | 145 | |
| 114 | 146 | /** |