jQuery(function() { var loading_posts = false; var aAjax = false; reselAllFields(); jQuery("input[type='checkbox']").on("click", function(e){ parentSelector = jQuery(this).closest(".filter-box"); if( parentSelector.find(".filter-all").is(":checked") && jQuery(this).val() !== "all" ){ parentSelector.find(".filter-all").prop('checked', false); } else if( jQuery(this).val() === "all" ){ parentSelector.find("input[type='checkbox']:not(.filter-all)").prop('checked', false); } fetchFilteredPartners(); }); jQuery("input[name='search_partner']").on("input", function(e){ fetchFilteredPartners(); }); jQuery(".ap-see-more").on("click", function(e){ jQuery(this).parent().find('li.display-none').removeClass('display-none'); jQuery(this).addClass('display-none'); }); jQuery(".location-filter").on("change", ".ab-countries", function(e){ // United States can sort by states filter if(jQuery(this).val() === "United States"){ var options = ""; jQuery(locations[jQuery(this).val()]).each(function( i, k ){ options += "" }); jQuery(this).parents('.location-filter').find('.ab-states').html(options).removeClass("display-none"); }else{ jQuery(".location-filter .ab-states").addClass("display-none") } }); jQuery(window).scroll(function() { //detect page scroll height = jQuery(document).height() - 1200; if( jQuery(window).scrollTop() + jQuery(window).height() >= height && loading_posts === false ) { loadMorePartners(); } }); jQuery(".abc-partner-sort select, .location-filter select").on("change", function(e){ fetchFilteredPartners(); }); jQuery(".openLink:not(.active)").on("click", function(e){ jQuery(".partner-main-showcase iframe").attr("src", jQuery(this).attr("data-link")); jQuery(this).addClass("active"); }); function loadMorePartners(){ loading_posts = true; jQuery.post(ajax_object.ajax_url, getFilters( 'fetch_filtered_partners' ), function(response) { loading_posts = false; response = jQuery.trim(response); response = JSON.parse(response); if(response.statusCode == '200'){ if((response.partners).length != 0){ jQuery("#page_number").val(parseInt(response.page) + 1); jQuery(".abc-partners-archive-content").append(response.partners); } else { //No Partners Found } } else { // Server Error } }); } function getFilters( action ){ var type = jQuery("input[name='ap-type[]']:checked").map(function(){ if(this.value !== 'all'){ return this.value } }).get(); var services = jQuery("input[name='ap-services[]']:checked").map(function(){ if(this.value !== 'all'){ return this.value } }).get(); var technology = jQuery("input[name='ap-technology[]']:checked").map(function(){ if(this.value !== 'all'){ return this.value } }).get(); var certification = jQuery("input[name='ap-certification[]']:checked").map(function(){ if(this.value !== 'all'){ return this.value } }).get(); var data = { '_ajax_nonce': ajax_object.nonce, 'action': action, 'search': jQuery("#search_partner").val(), 'sort_by': jQuery("#sort_by").val(), 'page': jQuery("#page_number").val(), 'country' : jQuery(".ab-countries").val(), 'state' : ((jQuery(".ab-countries").val() === "all") ? "all" : jQuery(".ab-states").val()), 'services': services, 'technology': technology, 'certification': certification, 'type': type } return data; } function fetchFilteredPartners(){ jQuery("#page_number").val(0); if (aAjax) { aAjax.abort(); } aAjax = jQuery.post(ajax_object.ajax_url, getFilters( 'fetch_filtered_partners' ), function(response) { response = jQuery.trim(response); response = JSON.parse(response); if(response.statusCode == '200'){ if((response.partners).length != 0){ jQuery("#page_number").val(parseInt(response.page) + 1); jQuery(".abc-partners-archive-content").html(response.partners); jQuery(window).scrollTop(0); } else { jQuery(".abc-partners-archive-content").html("
Sorry, no results were found.
"); jQuery(window).scrollTop(0); } } else { // Server Error } }); } function reselAllFields(){ jQuery("input[name='search_partner']").val(''); jQuery("input[type=checkbox][value=all]").prop("checked" , true); jQuery('select.ab-countries').val('all'); jQuery('select.ab-states').val('all'); } });