diff --git a/web/src/js/modules/courses.js b/web/src/js/modules/courses.js new file mode 100644 index 00000000..ce7eebe3 --- /dev/null +++ b/web/src/js/modules/courses.js @@ -0,0 +1,39 @@ +import $ from 'jquery'; + +$(document).ready(function () { + // Обработчик кнопки "Подгрузить еще" + $('.courses__list').on('click', 'button.load__btn', function () { + load_courses($(this).attr('data-next-page-url'), $(this)); + }); + + // Обработчик выбора категории + $('div.js-select-option[data-category-option]').on('click', function (e) { + e.preventDefault(); + load_courses($(this).attr('data-category-url'), null); + }); +}); + +function load_courses(coursesUrl, buttonElement) { + if (buttonElement) { + buttonElement.addClass('loading'); + } else { + $('.courses__list').css('opacity', '0.9'); + } + $.ajax(coursesUrl, { + method: 'GET', + dataType: 'html', + }) + .done(function (data) { + $('.courses__list').html(data); + }) + .fail(function (xhr) { + if (buttonElement) { + buttonElement.removeClass('loading'); + } + }) + .always(function () { + if (!buttonElement) { + $('.courses__list').css('opacity', '1'); + } + }); +} \ No newline at end of file