|
|
|
|
@ -12,9 +12,12 @@ moment.locale('ru'); |
|
|
|
|
const history = createHistory(); |
|
|
|
|
|
|
|
|
|
$(document).ready(function () { |
|
|
|
|
const currentCategory = $('div.js-select-option.active[data-category-option]').attr('data-category-name'); |
|
|
|
|
if(currentCategory) { |
|
|
|
|
$('.js-select[data-category-select] .js-select-head').text(currentCategory); |
|
|
|
|
const categoryName = $('div.js-select-option.active[data-category-option]').attr('data-category-name'); |
|
|
|
|
let category = $('div.js-select-option.active[data-category-option]').attr('data-category'); |
|
|
|
|
let age = $('div.js-select-option.active[data-age-option]').data('age'); |
|
|
|
|
let page = 1; |
|
|
|
|
if(category) { |
|
|
|
|
$('.js-select[data-category-select] .js-select-head').text(categoryName); |
|
|
|
|
} |
|
|
|
|
// Обработчик отложенных курсов
|
|
|
|
|
setInterval(() => { |
|
|
|
|
@ -29,17 +32,30 @@ $(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(); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
// Обработчик выбора категории
|
|
|
|
|
$('div.js-select-option[data-category-option]').on('click', function (e) { |
|
|
|
|
e.preventDefault(); |
|
|
|
|
const currentCategory = $(this).attr('data-category-name'); |
|
|
|
|
const categoryName = $(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); |
|
|
|
|
$(`[data-category-name='${categoryName}']`).addClass('active'); |
|
|
|
|
category = $(this).attr('data-category'); |
|
|
|
|
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); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
// Обработчик лайков
|
|
|
|
|
@ -95,42 +111,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'); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|