var ms = $('.catalog_lattice');
var params = mSearch2.Hash.get();
params['action'] = 'filter';
params['pageId'] = mse2Config.pageId;
params['key'] = mse2Config.key;
ms.miniScroll({
limit: 5,
controllerUrl: 'assets/components/msearch2/action.php',
responceType: 'json',
dop: params,
preloderPath: 'assets/templates/ikeds/img/loader.gif',
success: function (responce, elm) {
if (responce.data.results) {
elm.find('.pager').before(responce.data.results);
}
}
});
(function(){
var xhr_is_sent = false, //флаг отправки
page_counter = 1,
total_node,
total = 0,
last_page = false,
url = '/assets/components/msearch2/action.php',
param_1 = 'tv|area',
param_2 = 'tv|price',
param_3 = 'tv|metro',
area_min,
area_max,
price_min,
price_max,
loader,
items_per_page = 10,
anim_time = 100;
// оборачиваем в jQ для DOM ready
$(function(){
area_min = $('#area_0');
area_max = $('#area_1');
price_min = $('#price_0');
price_max = $('#price_1');
total_node = $('#mse2_total')
loader = $('.loader-content').css({opacity: '0', height: '0px', overflow: 'hidden'});
$('#mse2_results').on('resultsLoaded', function(){
page_counter = 1;
total = total_node.text()|0;
last_page = total > items_per_page ? false : true;
});
total = total_node.text()|0;
last_page = total > items_per_page ? false : true;
});
function showLoader(){
loader.stop(true).css({height: 'auto'}).animate({opacity: '1'}, anim_time, 'linear');
}
function hideLoader(){
loader.stop(true).animate({opacity: '0'}, anim_time, 'linear', function(){
loader.css({height: '0px'});
});
}
$(window).scroll(function() {
var data = {},
url_params = window.location.search.slice(1),
i, max;
if ($(window).scrollTop() == $(document).height() - $(window).height()) {
//отправляем запрос только если завершился предыдущий
if (!xhr_is_sent && !last_page) {
data.action = 'filter';
data.pageId = window.mse2Config.pageId;
data.key = window.mse2Config.key;
data.page = ++page_counter;
xhr_is_sent = true;
last_page = total > items_per_page * page_counter ? false : true;
if (url_params.length > 0) {
url_params = url_params.split('&');
for(i = 0, max = url_params.length; i < max; i++) {
url_params[i] = url_params[i].split('=');
if (url_params[i][0] === param_1) {
data[param_1] = decodeURIComponent(url_params[i][1]);
}
if (url_params[i][0] === param_2) {
data[param_2] = decodeURIComponent(url_params[i][1]);
}
if (url_params[i][0] === param_3) {
data[param_3] = decodeURIComponent(url_params[i][1]);
}
}
}
showLoader();
$.post(url, data, function(data){
$('#mse2_results').append($.parseJSON(data).data.results);
xhr_is_sent = false;
hideLoader();
$(window).trigger('ajax_loaded');
});
}
}
});
})();