parent
55ee199364
commit
5bed4a0379
7 changed files with 1286 additions and 353 deletions
@ -1,5 +1,5 @@ |
||||
{% for category in category_items %} |
||||
<div class="select__option js-select-option"> |
||||
<div class="select__option js-select-option" data-category-option data-category-url="{% url 'courses' %}?category={{ category.title }}"> |
||||
<div class="select__title">{{ category.title }}</div> |
||||
</div> |
||||
{% endfor %} |
||||
File diff suppressed because it is too large
Load Diff
@ -1,39 +1,53 @@ |
||||
import $ from 'jquery'; |
||||
import createHistory from 'history/createBrowserHistory'; |
||||
|
||||
// Создаем объект history API
|
||||
const history = createHistory(); |
||||
|
||||
$(document).ready(function () { |
||||
// Обработчик кнопки "Подгрузить еще"
|
||||
$('.courses__list').on('click', 'button.load__btn', function () { |
||||
load_courses($(this).attr('data-next-page-url'), $(this)); |
||||
$('.courses').on('click', 'button.load__btn', function () { |
||||
load_courses($(this).attr('data-next-page-url'), false); |
||||
}); |
||||
|
||||
// Обработчик выбора категории
|
||||
$('div.js-select-option[data-category-option]').on('click', function (e) { |
||||
e.preventDefault(); |
||||
load_courses($(this).attr('data-category-url'), null); |
||||
history.replace($(this).attr('data-category-url')); |
||||
load_courses($(this).attr('data-category-url'), true); |
||||
}); |
||||
}); |
||||
|
||||
function load_courses(coursesUrl, buttonElement) { |
||||
if (buttonElement) { |
||||
function load_courses(coursesUrl, fromStart) { |
||||
$('.courses__list').css('opacity', '0.9'); |
||||
const buttonElement = $('.courses').find('button.load__btn'); |
||||
if (!fromStart) { |
||||
buttonElement.addClass('loading'); |
||||
} else { |
||||
$('.courses__list').css('opacity', '0.9'); |
||||
} |
||||
$.ajax(coursesUrl, { |
||||
method: 'GET', |
||||
dataType: 'html', |
||||
method: 'GET' |
||||
}) |
||||
.done(function (data) { |
||||
$('.courses__list').html(data); |
||||
if (data.success === true) { |
||||
if (!fromStart) { |
||||
$('.courses__list').append(data.content); |
||||
} else { |
||||
$('.courses__list').html(data.content); |
||||
} |
||||
if (data.next_url) { |
||||
buttonElement.attr('data-next-page-url', data.next_url) |
||||
} else { |
||||
buttonElement.hide() |
||||
} |
||||
} |
||||
}) |
||||
.fail(function (xhr) { |
||||
if (buttonElement) { |
||||
buttonElement.removeClass('loading'); |
||||
} |
||||
|
||||
}) |
||||
.always(function () { |
||||
if (!buttonElement) { |
||||
$('.courses__list').css('opacity', '1'); |
||||
$('.courses__list').css('opacity', '1'); |
||||
if (buttonElement) { |
||||
buttonElement.removeClass('loading'); |
||||
} |
||||
}); |
||||
} |
||||
Loading…
Reference in new issue