|
|
|
|
@ -12,6 +12,8 @@ moment.locale('ru'); |
|
|
|
|
const history = createHistory(); |
|
|
|
|
|
|
|
|
|
$(document).ready(function () { |
|
|
|
|
var category = $('div.js-select-option.active[data-category-option]').data('category-name'), |
|
|
|
|
age = $('div.js-select-option.active[data-age-option]').data('age'), page = 1; |
|
|
|
|
// Обработчик отложенных курсов
|
|
|
|
|
setInterval(() => { |
|
|
|
|
$('div[data-future-course]').each((_, element) => { |
|
|
|
|
@ -25,7 +27,8 @@ $(document).ready(function () { |
|
|
|
|
|
|
|
|
|
// Обработчик кнопки "Подгрузить еще"
|
|
|
|
|
$('.courses').on('click', 'button.load__btn', function () { |
|
|
|
|
load_courses($(this).attr('data-next-page-url'), false); |
|
|
|
|
page = $(this).attr('data-next-page'); |
|
|
|
|
loadCourses(); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
// Обработчик выбора категории
|
|
|
|
|
@ -34,8 +37,20 @@ $(document).ready(function () { |
|
|
|
|
const currentCategory = $(this).attr('data-category-name'); |
|
|
|
|
$('[data-category-name]').removeClass('active'); |
|
|
|
|
$(`[data-category-name='${currentCategory}']`).addClass('active'); |
|
|
|
|
history.replace($(this).attr('data-category-url')); |
|
|
|
|
load_courses($(this).attr('data-category-url'), true); |
|
|
|
|
category = $(this).attr('data-category-name'); |
|
|
|
|
page = 1; |
|
|
|
|
loadCourses(true); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
// Обработчик выбора возраста
|
|
|
|
|
$('div.js-select-option[data-age-option]').on('click', function (e) { |
|
|
|
|
e.preventDefault(); |
|
|
|
|
const currentAge = $(this).attr('data-age-name'); |
|
|
|
|
$('[data-age-name]').removeClass('active'); |
|
|
|
|
$(`[data-age-name='${currentAge}']`).addClass('active'); |
|
|
|
|
age = $(this).attr('data-age'); |
|
|
|
|
page = 1; |
|
|
|
|
loadCourses(true); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
// Обработчик лайков
|
|
|
|
|
@ -91,42 +106,50 @@ $(document).ready(function () { |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
}) |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
function load_courses(coursesUrl, fromStart) { |
|
|
|
|
$('.courses__list').css('opacity', '0.9'); |
|
|
|
|
const buttonElement = $('.courses').find('button.load__btn'); |
|
|
|
|
if (!fromStart) { |
|
|
|
|
buttonElement.addClass('loading'); |
|
|
|
|
} |
|
|
|
|
$.ajax(coursesUrl, { |
|
|
|
|
method: 'GET' |
|
|
|
|
}) |
|
|
|
|
.done(function (data) { |
|
|
|
|
if (data.success === true) { |
|
|
|
|
if (!fromStart) { |
|
|
|
|
$('.courses__list').append(data.content); |
|
|
|
|
} else { |
|
|
|
|
$('.courses__list').html(data.content); |
|
|
|
|
function loadCourses(replaceHistory) { |
|
|
|
|
$('.courses__list').css('opacity', '0.9'); |
|
|
|
|
const buttonElement = $('.courses').find('button.load__btn'); |
|
|
|
|
let coursesUrl = window.LIL_STORE.urls.courses + '?' + $.param({ |
|
|
|
|
category: category, |
|
|
|
|
age: age, |
|
|
|
|
}); |
|
|
|
|
if (page > 1) { |
|
|
|
|
buttonElement.addClass('loading'); |
|
|
|
|
} |
|
|
|
|
else{ |
|
|
|
|
history.replace(coursesUrl); |
|
|
|
|
} |
|
|
|
|
coursesUrl += `&page=${page}`; |
|
|
|
|
$.ajax(coursesUrl, { |
|
|
|
|
method: 'GET' |
|
|
|
|
}) |
|
|
|
|
.done(function (data) { |
|
|
|
|
if (data.success === true) { |
|
|
|
|
if (page > 1) { |
|
|
|
|
$('.courses__list').append(data.content); |
|
|
|
|
} else { |
|
|
|
|
$('.courses__list').html(data.content); |
|
|
|
|
} |
|
|
|
|
if (data.next_url) { |
|
|
|
|
buttonElement.attr('data-next-page-url', data.next_url); |
|
|
|
|
buttonElement.show(); |
|
|
|
|
} else { |
|
|
|
|
buttonElement.hide() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (data.next_url) { |
|
|
|
|
buttonElement.attr('data-next-page-url', data.next_url); |
|
|
|
|
buttonElement.show(); |
|
|
|
|
} else { |
|
|
|
|
buttonElement.hide() |
|
|
|
|
}) |
|
|
|
|
.fail(function (xhr) { |
|
|
|
|
if (xhr.status === 404) { |
|
|
|
|
// Нет результатов, скрываем кнопку
|
|
|
|
|
buttonElement.hide(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
.fail(function (xhr) { |
|
|
|
|
if (xhr.status === 404) { |
|
|
|
|
// Нет результатов, скрываем кнопку
|
|
|
|
|
buttonElement.hide(); |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
.always(function () { |
|
|
|
|
$('.courses__list').css('opacity', '1'); |
|
|
|
|
if (buttonElement) { |
|
|
|
|
buttonElement.removeClass('loading'); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
.always(function () { |
|
|
|
|
$('.courses__list').css('opacity', '1'); |
|
|
|
|
if (buttonElement) { |
|
|
|
|
buttonElement.removeClass('loading'); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|