@@ -478,13 +478,24 @@ function updateCategoryCounter(filterParams){
478478 }
479479 }
480480
481- for ( const [ key , value ] of container ) {
482- // for issue #4648, added this to show the sum of selected filters for both technology and language filters
483- let totalValue = 0
484- for ( const innerValue of container ) {
485- totalValue += innerValue [ 1 ]
486- }
487- document . querySelector ( `#${ key } ` ) . innerHTML = ` (${ totalValue } )` ;
481+ // Calculate total selected filters across all categories (excluding Search)
482+ let totalSelected = container . reduce ( ( sum , [ , val ] ) => sum + val , 0 ) ;
483+
484+ // Update each category counter – preserve existing behaviour of showing combined totals
485+ for ( const [ key ] of container ) {
486+ document . querySelector ( `#${ key } ` ) && ( document . querySelector ( `#${ key } ` ) . innerHTML = ` (${ totalSelected } )` ) ;
487+ }
488+
489+ // Update the new overall filters counter in the title
490+ const totalCounterSpan = document . querySelector ( '#counter_total' ) ;
491+ if ( totalCounterSpan ) {
492+ totalCounterSpan . innerHTML = totalSelected > 0 ? ` (${ totalSelected } )` : '' ;
493+ }
494+
495+ // Show/hide Clear All link
496+ const clearAllLink = document . getElementById ( 'clear-all-filters' ) ;
497+ if ( clearAllLink ) {
498+ clearAllLink . style . display = totalSelected > 0 ? 'inline' : 'none' ;
488499 }
489500
490501}
@@ -621,13 +632,14 @@ function attachEventListenerToFilterTags(){
621632 button . addEventListener ( 'click' , filterTagOnClickEventHandler )
622633 } )
623634
624- // If there exist a filter-tag button on the page add a clear all button after the last filter tag button
625- if ( ! document . querySelector ( '.clear-filter-tags' ) ) {
626- document . querySelector ( '.filter-tag:last-of-type' ) . insertAdjacentHTML ( 'afterend' , `<a class="clear-filter-tags" tabindex="0" aria-label="Clear All Filters" style="white-space: nowrap;">Clear All</a>` ) ;
635+ // No longer inserting bottom Clear All link; top link exists.
636+ }
627637
628- //Attach an event handler to the clear all button
629- document . querySelector ( '.clear-filter-tags' ) . addEventListener ( 'click' , clearAllEventHandler ) ;
630- }
638+ // Attach event to top Clear All link once (after DOM ready)
639+ const clearAllTop = document . getElementById ( 'clear-all-filters' ) ;
640+ if ( clearAllTop && ! clearAllTop . dataset . listenerAdded ) {
641+ clearAllTop . addEventListener ( 'click' , function ( e ) { e . preventDefault ( ) ; clearAllEventHandler ( ) ; } ) ;
642+ clearAllTop . dataset . listenerAdded = 'true' ;
631643 }
632644}
633645
@@ -647,12 +659,16 @@ function noUrlParameterUpdate(){
647659
648660 // Clear all number of checkbox counters
649661 document . querySelectorAll ( '.number-of-checked-boxes' ) . forEach ( checkBoxCounter => { checkBoxCounter . innerHTML = '' } ) ;
662+ const totalCounterSpan = document . querySelector ( '#counter_total' ) ;
663+ if ( totalCounterSpan ) { totalCounterSpan . innerHTML = '' ; }
650664
651- // Clear all filter tags
652- document . querySelectorAll ( '.filter-tag' ) && document . querySelectorAll ( '.filter-tag' ) . forEach ( filterTag => filterTag . remove ( ) ) ;
665+ const clearAllLink = document . getElementById ( 'clear-all-filters' ) ;
666+ if ( clearAllLink ) { clearAllLink . style . display = 'none' ; }
653667
654- // Remove Clear All Button
655- document . querySelector ( '.clear-filter-tags' ) && document . querySelector ( '.clear-filter-tags' ) . remove ( ) ;
668+ // Remove any legacy bottom Clear All links if present
669+ document . querySelectorAll ( '.clear-filter-tags' ) . forEach ( el => {
670+ if ( el . id !== 'clear-all-filters' ) el . remove ( ) ;
671+ } ) ;
656672 return ;
657673}
658674
0 commit comments