Merge pull request 'Sort films on film page' (#36) from sort-films into main
Reviewed-on: 0x2620/aab21#36
This commit is contained in:
commit
f520d837d6
3 changed files with 67 additions and 13 deletions
|
@ -6,8 +6,15 @@
|
||||||
color: #ee0;
|
color: #ee0;
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
select {
|
||||||
|
font-size: 18px;
|
||||||
|
font-family: "noto_sans", sans-serif;
|
||||||
|
padding: calc(var(--spacing) /4) var(--spacing);
|
||||||
|
}
|
||||||
|
|
||||||
.film {
|
.film {
|
||||||
margin-bottom: var(--spacing-2);
|
margin-top: var(--spacing-2);
|
||||||
h1 {
|
h1 {
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
font-size: 20px;
|
font-size: 20px;
|
||||||
|
|
22
app/static/js/films.js
Normal file
22
app/static/js/films.js
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
function selectChanged() {
|
||||||
|
const sortValue = document.getElementById('sort-select').value
|
||||||
|
const $films = [...document.querySelectorAll('.film')]
|
||||||
|
location.hash = sortValue
|
||||||
|
$films.sort((a, b) => {
|
||||||
|
const aVal = a.dataset[sortValue]
|
||||||
|
const bVal = b.dataset[sortValue]
|
||||||
|
return aVal < bVal ? -1 : 1
|
||||||
|
})
|
||||||
|
document.getElementById('films-list').innerHTML = ''
|
||||||
|
$films.forEach($film => {
|
||||||
|
document.getElementById('films-list').appendChild($film)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
document.getElementById('sort-select').addEventListener('change', selectChanged)
|
||||||
|
|
||||||
|
const locationHash = location.hash.replace('#', '')
|
||||||
|
if (locationHash !== '') {
|
||||||
|
document.getElementById('sort-select').value = locationHash
|
||||||
|
selectChanged()
|
||||||
|
}
|
49
app/templates/films.html
Normal file → Executable file
49
app/templates/films.html
Normal file → Executable file
|
@ -1,19 +1,44 @@
|
||||||
{% extends "base.html" %}
|
{% extends "base.html" %}
|
||||||
{% block body_class%}animated animated-text{% endblock %}
|
{% block body_class%}animated animated-text{% endblock %}
|
||||||
{% block main %}
|
{% block main %}
|
||||||
|
|
||||||
<div class="films">
|
<div class="films">
|
||||||
{% for film in films %}
|
<div>
|
||||||
<div class="film">
|
<strong>Sort:</strong>
|
||||||
<h1><a href="{{ film.get_absolute_url }}">
|
<select id="sort-select">
|
||||||
<span>{{ film.data.title | safe }}</span>
|
<option value="position" selected>Default</option>
|
||||||
<span>{{ film.data.title_zh | safe }}</span>
|
<option value="title">Title</option>
|
||||||
</a></h1>
|
<option value="duration">Duration</option>
|
||||||
<h2>
|
<option value="hue">Hue</option>
|
||||||
{% for director in film.data.director %}
|
<option value="saturation">Saturation</option>
|
||||||
<span>{{ director|safe }}</span>
|
<option value="lightness">Lightness</option>
|
||||||
{% endfor %}
|
</select>
|
||||||
</h2>
|
</div>
|
||||||
|
<div id="films-list">
|
||||||
|
{% for film in films %}
|
||||||
|
<div class="film"
|
||||||
|
data-position="{{ film.position }}"
|
||||||
|
data-title="{{ film.data.title }}"
|
||||||
|
data-duration="{{ film.data.duration }}"
|
||||||
|
data-hue="{{ film.data.hue }}"
|
||||||
|
data-saturation="{{ film.data.saturation }}"
|
||||||
|
data-lightness="{{ film.data.lightness }}"
|
||||||
|
>
|
||||||
|
<h1><a href="{{ film.get_absolute_url }}">
|
||||||
|
<span>{{ film.data.title | safe }}</span>
|
||||||
|
<span>{{ film.data.title_zh | safe }}</span>
|
||||||
|
</a></h1>
|
||||||
|
<h2>
|
||||||
|
{% for director in film.data.director %}
|
||||||
|
<span>{{ director|safe }}</span>
|
||||||
|
{% endfor %}
|
||||||
|
</h2>
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block end %}
|
||||||
|
<script src="{% static 'js/films.js' %}"></script>
|
||||||
|
{% endblock %}
|
Loading…
Reference in a new issue