| 1 |
jQuery(document).ready(function($){ |
| 2 |
//wdk_ajax_loading_listings(); |
| 3 |
}); |
| 4 |
|
| 5 |
|
| 6 |
const wdk_ajax_loading_listings = ($url = '') => { |
| 7 |
var $ = jQuery, |
| 8 |
jqxhr = null; |
| 9 |
js_show_data = ($field_name, $db_value = null, $default = false) => { |
| 10 |
let output = $default; |
| 11 |
|
| 12 |
if(typeof $db_value[$field_name] !='undefined' && $db_value[$field_name] !='' ) { |
| 13 |
output = $db_value[$field_name] |
| 14 |
} |
| 15 |
return output; |
| 16 |
}; |
| 17 |
|
| 18 |
|
| 19 |
if ($url != '' && 'history' in window && 'pushState' in history) |
| 20 |
history.pushState(null, null, $url); |
| 21 |
|
| 22 |
/* ajax loading */ |
| 23 |
|
| 24 |
|
| 25 |
var data = { |
| 26 |
"action": 'wdk_public_action', |
| 27 |
"page": 'wdk_frontendajax', |
| 28 |
"function": 'loading_listings', |
| 29 |
"url": $url, |
| 30 |
}; |
| 31 |
|
| 32 |
if($('.wdk_map_results.ajax_results_enabled').length) { |
| 33 |
var el_map = $('.wdk_map_results.ajax_results_enabled').first(); |
| 34 |
data['el_map_id'] = el_map.attr("data-el_id"); |
| 35 |
data['el_map_page_id'] = el_map.attr("data-el_page_id"); |
| 36 |
data['el_map_type'] = el_map.attr("data-el_type"); |
| 37 |
} |
| 38 |
|
| 39 |
if($('.wdk-listings-results.ajax_results_enabled').length) { |
| 40 |
var el_map = $('.wdk-listings-results.ajax_results_enabled').first(); |
| 41 |
data['el_results_id'] = el_map.attr("data-el_id"); |
| 42 |
data['el_results_page_id'] = el_map.attr("data-el_page_id"); |
| 43 |
data['el_results_type'] = el_map.attr("data-el_type"); |
| 44 |
} |
| 45 |
|
| 46 |
// Assign handlers immediately after making the request, |
| 47 |
// and remember the jqxhr object for this request |
| 48 |
if (jqxhr != null) |
| 49 |
jqxhr.abort(); |
| 50 |
|
| 51 |
jqxhr = jQuery.post( script_parameters.ajax_url, data, function (data) { |
| 52 |
if(data.success) { |
| 53 |
//that.messages_list.find('.message.placeholder').remove(); |
| 54 |
|
| 55 |
/* map_results */ |
| 56 |
if($('.wdk_map_results.ajax_results_enabled').length) { |
| 57 |
$('.wdk_map_results.ajax_results_enabled').each(function(){ |
| 58 |
let self = $(this); |
| 59 |
|
| 60 |
/* clear markers */ |
| 61 |
//Loop through all the markers and remove |
| 62 |
for (var i in wdk_markers) { |
| 63 |
wdk_clusters.removeLayer(wdk_markers[i]); |
| 64 |
} |
| 65 |
wdk_markers = []; |
| 66 |
|
| 67 |
var auto_marker_size = false; |
| 68 |
var clusters_enabled = true; |
| 69 |
|
| 70 |
$.each(data.output.map_results, function(index, listing){ |
| 71 |
if(!js_show_data('lng',listing)) return true; |
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
var listing_lat = null, listing_lng = null; |
| 76 |
|
| 77 |
listing_lat = js_show_data('lat', listing); |
| 78 |
listing_lng = js_show_data('lng', listing); |
| 79 |
|
| 80 |
wdk_markers.push(wdk_generate_marker_ajax_popup(script_parameters.ajax_url, |
| 81 |
js_show_data('post_id', listing), |
| 82 |
listing_lat, |
| 83 |
listing_lng, |
| 84 |
js_show_data('inner_marker', listing), |
| 85 |
wdk_jpopup_customOptions, |
| 86 |
auto_marker_size, |
| 87 |
clusters_enabled)); |
| 88 |
}) |
| 89 |
|
| 90 |
wdk_map.addLayer(wdk_clusters); |
| 91 |
|
| 92 |
/* set center */ |
| 93 |
if(wdk_markers.length){ |
| 94 |
var limits_center = []; |
| 95 |
for (var i in wdk_markers) { |
| 96 |
var latLngs = [ wdk_markers[i].getLatLng() ]; |
| 97 |
limits_center.push(latLngs) |
| 98 |
}; |
| 99 |
var bounds = L.latLngBounds(limits_center); |
| 100 |
wdk_map.fitBounds(bounds); |
| 101 |
} |
| 102 |
}); |
| 103 |
|
| 104 |
} |
| 105 |
|
| 106 |
/* listings results */ |
| 107 |
if($('.wdk-listings-results.ajax_results_enabled').length) { |
| 108 |
$('.wdk-listings-results.ajax_results_enabled').each(function(){ |
| 109 |
let self = $(this); |
| 110 |
self.find('.wdk-inner-listings-results').html(''); |
| 111 |
|
| 112 |
self.find('.wdk-inner-listings-results').append(js_show_data('listings_result_message',data.output)); |
| 113 |
$.each(data.output.listings_result, function(index, listing){ |
| 114 |
if(!js_show_data('card_view',listing)) return true; |
| 115 |
self.find('.wdk-inner-listings-results').append('<div class="wdk-col">'+js_show_data('card_view',listing)+'</div>'); |
| 116 |
}) |
| 117 |
self.find('.filter-status').html('<span>'+js_show_data('listings_count_html',data.output)+'</span>'); |
| 118 |
self.find('.wdk-pagination').replaceWith(js_show_data('pagination_html',data.output)); |
| 119 |
}); |
| 120 |
} |
| 121 |
|
| 122 |
var html=''; |
| 123 |
if(data.output.related_message) { |
| 124 |
} |
| 125 |
|
| 126 |
if(html != '') { |
| 127 |
//that.messages_list.append(html); |
| 128 |
// that.messages_list.scrollTop(that.messages_list.prop('scrollHeight') + 250); |
| 129 |
} |
| 130 |
|
| 131 |
} |
| 132 |
}).always(function() { |
| 133 |
$("form.wdk-search-form .wdk-search-start").find('.fa-ajax-indicator').css('display', 'none'); |
| 134 |
$('.wdk-listings-results.ajax_results_enabled .wdk-pagination .page-numbers').on('click', function (e) { |
| 135 |
e.preventDefault(); |
| 136 |
wdk_ajax_loading_listings($(this).attr('href')); |
| 137 |
}) |
| 138 |
}); |
| 139 |
} |
| 140 |
|
| 141 |
|