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