@@ -83,5 +83,63 @@ window.addEventListener('load', () => {
8383 $item . checked = e . detail === 'dark'
8484 } )
8585 } )
86+
87+ // Custom dropdown implementation (Preline has a bug with the close logic)
88+ const dropdown = document . querySelector ( '.custom-dropdown' )
89+ const dropdownToggle = document . querySelector ( '.custom-dropdown-toggle' )
90+ const dropdownMenu = document . querySelector ( '.custom-dropdown-menu' )
91+
92+ if ( dropdown && dropdownToggle && dropdownMenu ) {
93+
94+ // Toggle dropdown on button click
95+ dropdownToggle . addEventListener ( 'click' , function ( e ) {
96+ e . preventDefault ( )
97+ e . stopPropagation ( )
98+
99+ if ( dropdown . classList . contains ( 'open' ) ) {
100+ closeDropdown ( )
101+ } else {
102+ openDropdown ( )
103+ }
104+ } )
105+
106+ // Close dropdown when clicking outside
107+ document . addEventListener ( 'click' , function ( e ) {
108+ // Don't close if clicking the toggle button (it handles itself)
109+ if ( dropdownToggle . contains ( e . target ) ) {
110+ return
111+ }
112+
113+ // Close if clicking outside the dropdown
114+ if ( ! dropdown . contains ( e . target ) ) {
115+ closeDropdown ( )
116+ }
117+ } )
118+
119+ // Close dropdown when clicking a menu item
120+ dropdownMenu . querySelectorAll ( 'a' ) . forEach ( function ( link ) {
121+ link . addEventListener ( 'click' , function ( ) {
122+ closeDropdown ( )
123+ } )
124+ } )
125+
126+ function openDropdown ( ) {
127+ dropdown . classList . add ( 'open' )
128+
129+ // Calculate position for fixed positioning
130+ const rect = dropdownToggle . getBoundingClientRect ( )
131+ dropdownMenu . style . top = rect . bottom + 'px'
132+ dropdownMenu . style . left = rect . left + 'px'
133+
134+ dropdownMenu . classList . remove ( 'hidden' )
135+ dropdownMenu . classList . add ( 'block' )
136+ }
137+
138+ function closeDropdown ( ) {
139+ dropdown . classList . remove ( 'open' )
140+ dropdownMenu . classList . remove ( 'block' )
141+ dropdownMenu . classList . add ( 'hidden' )
142+ }
143+ }
86144} )
87145
0 commit comments