window.Project = (function (window, document, $, undefined) {
'use strict';
var app = {
initialize: function () {
app.initFeatureSlider('.feature-slider-inner');
$('.search-btn').on('click', app.ajax_directory_search);
app.makeFilter();
$(document).on('click', '.listing-category', function () {
var type = $(this).data('type');
var value = $(this).data('value');
$('.'+type+'_listing_select').val(value).trigger('change');
});
$('.directory-filter-form select,.directory-filter-form input').on('change', function () {
$('#listing-filter-form').submit();
});
},
makeFilter:function(){
//listing categories
var categories = $('.category_listing_select option');
var category_lists = app.makeList(categories, 'category');
$('ul.listing-categories').html(category_lists);
},
makeList:function(options, type){
console.log('makeList');
var html = '';
options.each(function (index, option) {
var value = $(option).attr('value');
var text = $(option).text();
html += '<li data-type="'+type+'"data-value="'+value+'" class="listing-category">'+text+'</li>';
});
return html;
},
initFeatureSlider: function ($selector) {
$($selector).owlCarousel({
items: 1,
loop: true,
margin: 10,
nav: true,
dots: false,
navText: ['<i class="fa fa-angle-left"></i>', '<i class="fa fa-angle-right"></i>']
});
},
ajax_directory_search: function (e) {
e.preventDefault();
var keywords = $('.search-input').val();
if (!keywords) {
console.log('search input is empty');
return;
}
wp.ajax.send({
data: {
action: 'directory_search',
keyword: keywords
},
success: function (response) {
console.log(response);
$('.site-main').find('.directory-list-wrap').append(response.list);
},
error: {}
});
console.log(keywords);
}
};
$(document).ready(app.initialize);
return app;
})(window, document, jQuery);