jQuery(document).ready(function($) {
var limit = 10; var offset = 0; var noMoreProducts = false; var loadingInProgress = false; var shortcode_id = 815; var ajaxurl = 'https://demo-hroffice-plugin-wordpress.nowonline.nl/wp-admin/admin-ajax.php'; var current_page_id = 854;
$(document).on('submit', '#filter-form', function(e){ e.preventDefault(); let form = $(this); let is_filtered = false; let search_ele = $('#filter-form').find('.form-group input[name="search"], .form-group select');
search_ele.each(function() { let trimmed = ( $(this).val() !== null && $(this).val() !== '' ) ? $(this).val().trim() : ''; if( trimmed !== '' ){ is_filtered = true; } });
if( true === is_filtered ){ $('.nls-rst-fltr-btn').remove(); let reset_html = ` × `; $('.btn.find-vacancy-btn').parents('.form-group.button').append(reset_html); console.log( 'filtered' ); }
$('.listdata-loader').show();
$.post(ajaxurl, { action: 'action_shortcode_listing_filters', filter_jobs_nonce: $('#filter_jobs_nonce').data('value'), formdata: $(form).serialize(), }, function (data) { $('.listdata-loader').hide(); $('#all-products').html(data);
let formQueries = {}; $.each($('#filter-form').serializeArray(), function(_, input) { formQueries[input.name] = input.value; }); $('#current-query').val(JSON.stringify(formQueries));
offset = limit; noMoreProducts = false;
const url = new URL(window.location); $.each(formQueries, function(key, value) { if( key !== 'shortcode_id' && key !== 'current_page_id' ){ url.searchParams.set(key, value); } }); window.history.pushState({}, '', url);
} )
});
$(document).on('click','.nls-rst-fltr-btn', function () { let fill_ele = $('#filter-form').find('.form-group input[name="search"], .form-group select').not('.form-group select[name="cats-Brands"]'); fill_ele.each(function() { if( 'search' === $(this).attr('name') ){ $(this).val(''); }else{ $(this).find('option:first').removeAttr('disabled'); $(this).find('option:first').attr('selected','selected'); $(this).prop("selectedIndex", 0); $(this).val(''); } }); $('.nls-rst-fltr-btn').remove(); $('#filter-form').submit(); setTimeout(() => { fill_ele.each(function() { if( 'search' !== $(this).attr('name') ){ $(this).find('option:first').attr('disabled','disabled'); } }); }, 700); });
function loadProducts( extraQueries = {}) { if (noMoreProducts) return; let is_filtered = false; let search_ele = $('#filter-form').find('.form-group input[name="search"], .form-group select').not('.form-group select[name="cats-Brands"]'); search_ele.each(function() { let trimmed = ( $(this).val() !== null && $(this).val() !== '' ) ? $(this).val().trim() : ''; if( trimmed !== '' ){ is_filtered = true; } }); if( true === is_filtered ){ $('.nls-rst-fltr-btn').remove(); let reset_html = ` × `; $('.btn.find-vacancy-btn').parents('.form-group.button').append(reset_html); console.log( 'filtered' ); }
let queries = { 'offset' : offset, 'limit' : limit, 'loadmore' : 'loadmore', 'shortcode_id' : shortcode_id, 'current_page_id' : current_page_id, };
if(location.search){ var urlvars = [], hash; var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&'); for(var i = 0; i < hashes.length; i++) { hash = hashes[i].split('='); urlvars[hash[0]] = hash[1]; } var urlvarsObject = Object.assign({}, urlvars); if( ! jQuery.isEmptyObject(urlvarsObject) ) { $.each(urlvarsObject, function(param, value){ queries[param] = value.replace(/\+/g, ' '); }); } } // Additional Queries if( ! jQuery.isEmptyObject(extraQueries) ) { $.each(extraQueries, function(param, value){ queries[param] = value; }); } $('.listdata-loader').show(); if (!loadingInProgress) { loadingInProgress = true; $.post(ajaxurl, { action: 'action_shortcode_listing_filters', filter_jobs_nonce: $('#filter_jobs_nonce').data('value'), formdata: queries, }, function (data) { if(!data) { noMoreProducts = true; $('.view-more-button').remove(); } else { offset += limit; $('.view-more-button').remove(); $('#all-products').append(data); $('.listdata-loader').hide(); } loadingInProgress = false; } ) } } $(document).on('click', '#load-more', function() { let currentQuery = {}; var loadmore_htmlval = $('#load-more').html(); $('#load-more').html(loadmore_htmlval+'...').prop('disabled', true); if($('#current-query').val().length) { currentQuery = JSON.parse($('#current-query').val()); } loadProducts( currentQuery ); }); loadProducts(); })