File tree Expand file tree Collapse file tree 1 file changed +28
-5
lines changed
Expand file tree Collapse file tree 1 file changed +28
-5
lines changed Original file line number Diff line number Diff line change 180180 }
181181 } ) ;
182182
183+ // Update URL hash to reflect active filter
184+ const activeFilter = pill . classList . contains ( 'active' ) ? category : null ;
185+ if ( activeFilter && activeFilter !== 'all' ) {
186+ history . replaceState ( null , '' , '#' + activeFilter ) ;
187+ } else {
188+ history . replaceState ( null , '' , window . location . pathname + window . location . search ) ;
189+ }
190+
183191 // Update view toggle button state
184192 if ( window . updateViewToggleState ) {
185193 window . updateViewToggleState ( ) ;
186194 }
187195 } ) ;
188196 } ) ;
189197
190- // Auto-click "All" button on page load to show all cards
191- const allButton = document . querySelector ( '.filter-pill[data-filter="all"]' ) ;
192- if ( allButton ) {
193- allButton . click ( ) ;
194- }
198+ // Apply filter from a given category string (or "all" / empty for no filter)
199+ const applyHashFilter = ( category ) => {
200+ const target = category
201+ ? document . querySelector ( `.filter-pill[data-filter="${ category } "]` )
202+ : null ;
203+ if ( target ) {
204+ target . click ( ) ;
205+ } else {
206+ const allButton = document . querySelector ( '.filter-pill[data-filter="all"]' ) ;
207+ if ( allButton ) allButton . click ( ) ;
208+ }
209+ } ;
210+
211+ // On load, apply filter from URL hash or default to "All"
212+ applyHashFilter ( window . location . hash . slice ( 1 ) ) ;
213+
214+ // Also react to browser back/forward hash changes
215+ window . addEventListener ( 'hashchange' , ( ) => {
216+ applyHashFilter ( window . location . hash . slice ( 1 ) ) ;
217+ } ) ;
195218 } ;
196219
197220 /* ==========================================================
You can’t perform that action at this time.
0 commit comments