parent
7f3fb2b4b4
commit
4cd4930da7
1 changed files with 39 additions and 0 deletions
@ -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'); |
||||
} |
||||
}); |
||||
} |
||||
Loading…
Reference in new issue