From 4cd4930da7c4e202ef01be7d73ae2761e53a6713 Mon Sep 17 00:00:00 2001 From: Vitaly Baev Date: Fri, 26 Jan 2018 10:55:25 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=BE=D0=B4=D0=B3=D1=80=D1=83=D0=B7?= =?UTF-8?q?=D0=BA=D0=B0=20=D0=BA=D1=83=D1=80=D1=81=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/src/js/modules/courses.js | 39 +++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 web/src/js/modules/courses.js 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