// JavaScript Document var soil = 1; // номер страницы let firstContent = true; let lastData = false; function newsOnLoad() { //коррекция url //window.history.replaceState(null, null, window.location.pathname); $('a[data-filter]').each(function(i,a){ if (a.dataset.filter == catId) { $(a).addClass('active'); $(a).prev().prop('style', 'visibility: hidden'); $(a).next().prop('style', 'visibility: hidden'); excavate(true, catId); } else { $(a).removeClass('active'); } }); // Привязываемся к кнопке $('#loadMore').click(function () { excavate(false, catId); }); // Привязываем фильтр $('a[data-filter]').on('click', function () { catId = $(this).attr('data-filter'); $('a[data-filter]').each(function(i,a){ $(a).removeClass('active'); $(a).prev().prop('style', ''); $(a).next().prop('style', ''); if (a.dataset.filter == catId) { $(a).addClass('active'); $(a).prev().prop('style', 'visibility: hidden'); $(a).next().prop('style', 'visibility: hidden'); } }); excavate(true, catId); }); } // Достаем следующие function excavate(clear, catId) { if (clear) { $('#firstContent').html(''); $('#secondContent').html(''); $('#loadMore').prop('style', ''); soil = 1; firstContent = true; lastData = false; }; $.ajax({ url: 'https://rpo.logycom.kz/tm/threemen.dll/srv', type: 'POST', data: { 'srv': 'news', "module": 7, "category": catId, 'page': soil }, dataType: 'text', success: function () { }, error: function () { }, complete: function (data) { var msg = uparams(data.responseText), news; if (msg['status'] !== 'OK') { showError(msg['msg'] ? msg['msg'] : 'Что-то пошло не так'); forRet = false; return } news = JSON.parse(atob(msg['msg'])); let result = ''; news.forEach((i) => { let template = `
${i.newsDate}
${i.newsTitle}
` result += template; if (i.lastData == true) { $('#loadMore').prop('style', 'display: none'); return; } }); soil++; if (firstContent) { $('#firstContent').append(result); firstContent = false; } else { $('#secondContent').append(result) } } }); }