Hide and Show Div based on Filter | Jetsmartfilters

PHOTO EMBED

Mon Apr 15 2024 19:02:38 GMT+0000 (Coordinated Universal Time)

Saved by @Y@sir #jetsmartfilters #filter

<style>

    body:not(.elementor-editor-active) .hide-listing {
        display: none;
        height: 0;
    }
    
</style>

<script>

	document.addEventListener( 'jet-smart-filters/inited', function( initEvent ) {
		
		function hideProvider( $provider, parentSelector ) {
			$provider.closest( parentSelector ).addClass( 'hide-listing' );
		}
		
		function showProvider( $provider, parentSelector ) {
			$provider.closest( parentSelector ).removeClass( 'hide-listing' );
		}
		
		jQuery( function( $ ) {
			
			for ( const groupName in window.JetSmartFilters.filterGroups ) {
				
				const filterGroup = window.JetSmartFilters.filterGroups[ groupName ],
				      $provider   = filterGroup?.$provider,
				      query       = filterGroup?.currentQuery || {};
					
				if ( ! $provider.closest('.hide-before-filter')?.length ) {
					return;
				}
				
				if ( ! Object.keys( query ).length ) {
					hideProvider( $provider, '.hide-before-filter' );
				} else {
					showProvider( $provider, '.hide-before-filter' );
				}
				
			}
			
			window.JetSmartFilters.events.subscribe( 'ajaxFilters/updated', function( provider, queryId ) {
				
				const filterGroup = window.JetSmartFilters.filterGroups[ provider + '/' + queryId ],
				      $provider   = filterGroup.$provider,
				      query       = filterGroup.currentQuery || {};
				
				if ( ! Object.keys( query ).length ) {
					hideProvider( $provider, '.hide-before-filter.hide-on-reset' );
				} else {
					showProvider( $provider, '.hide-before-filter' );
				}
				
			} );
		
		} );
	
	} );
	
</script>
content_copyCOPY