1jQuery( document ).ready( function( $ ) { 2 function showLoader() { 3 $( '.loader' ).show(); 4 } 5 6 function hideLoader() { 7 $( '.loader' ).hide(); 8 } 9 10 function loadCompany( category, paged = 1 ) { 11 const action = category === 'all' ? 'sciencepark_fetch_all_company' : 'sciencepark_filter_company'; 12 showLoader(); 13 14 const data = { 15 action, 16 nonce: templateCompanyObject.nonce, 17 paged, 18 }; 19 20 if ( category !== 'all' ) { 21 data.category = category; 22 } 23 24 if ( window.location.href.indexOf( '/wp-admin/' ) === -1 ) { 25 const urlParams = new URLSearchParams( window.location.search ); 26 const searchQuery = urlParams.get( 's' ); 27 const searchQueryParam = searchQuery ? '?s=' + encodeURIComponent( searchQuery ) : ''; 28 if ( category === 'all' ) { 29 if ( ! history.state || history.state.path !== window.location.pathname ) { 30 window.history.replaceState( {}, document.title, window.location.pathname + searchQueryParam ); 31 } 32 } else if ( category !== 'all' ) { 33 const newUrl = `?category=${ category }` + searchQueryParam; 34 if ( ! history.state || history.state.path !== newUrl ) { 35 window.history.replaceState( { path: newUrl }, '', newUrl ); 36 } 37 } 38 } 39 40 $.ajax( { 41 url: templateCompanyObject.ajax_url, 42 type: 'post', 43 data, 44 success( response ) { 45 $( '.company-grid' ).html( response ); 46 hideLoader(); 47 48 // Update active-tag class after AJAX success 49 $( '.filter-item' ).removeClass( 'active-tag' ); 50 $( `.filter-item[category='${ category }']` ).addClass( 'active-tag' ); 51 52 $( '.company-grid .post-card' ).css( 'opacity', 0 ); 53 54 $( '.company-grid .post-card' ).each( function( index ) { 55 const card = $( this ); 56 setTimeout( function() { 57 card.animate( { opacity: 1 }, 150 ); 58 }, 50 * index ); 59 } ); 60 }, 61 complete() { 62 hideLoader(); 63 }, 64 } ); 65 } 66 67 const urlParams = new URLSearchParams( window.location.search ); 68 const category = urlParams.get( 'category' ) || 'all'; 69 const initialPaged = urlParams.get( 'paged' ) || 1; 70 71 loadCompany( category, initialPaged ); 72 73 $( '.filter-item' ).on( 'click', function( e ) { 74 e.preventDefault(); 75 76 const clickedCategory = $( this ).attr( 'category' ); 77 78 loadCompany( clickedCategory ); 79 } ); 80 81 $( '.company-grid' ).on( 'click', '.pagination a', function( e ) { 82 e.preventDefault(); 83 84 const clickedPaged = $( this ).attr( 'href' ).split( 'paged=' )[ 1 ]; 85 const clickedCategory = $( '.filter-item.active-tag' ).attr( 'category' ); 86 87 loadCompany( clickedCategory, clickedPaged ); 88 89 let offset; 90 if ( $( window ).width() <= 768 ) { 91 offset = 235; 92 } else { 93 offset = 340; 94 } 95 $( 'html, body' ).animate( { 96 scrollTop: $( '.company-grid' ).offset().top - offset, 97 }, 'slow' ); 98 } ); 99} );
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.