Answer the question
In order to leave comments, you need to log in
How to make ajax feed with mFilter2?
Good afternoon, please tell me how to use infinite scroll instead of pagination of mFilter2 results, how to do it with getResources or pdoResources I know how to write a snippet that will process the pdoResources result, output it in json format, and then just pull the right amount through post, but here's how it is I can’t figure out how to screw something to mFilter2, thanks in advance
Answer the question
In order to leave comments, you need to log in
Everything is pretty simple. mFilter writes values for filtering to url in the form of get - parameters, and pdoPage is used as a snippet for pagination. mFilter sends requests for filtering and pagination to the assets/components/msearch2/action.php connector.
As a result, you need to take any js plugin that implements an infinite scroll, or write it yourself. When you reach the end of the page, you take the url, break it into parameters (you can use the mSearch2.Hash.get() function, it is part of the mSearch js api) and feed them to the script. That's all.
Once I wrote a similar implementation for scrolling using my miniScroll plugin . For it, the implementation will look like this:
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);
}
}
});
thank you very much for the answer, I asked the question for a long time, and I figured it out myself, my version looks like this
(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');
});
}
}
});
})();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question