diff --git a/app/static/js/films.js b/app/static/js/films.js new file mode 100644 index 0000000..42185dd --- /dev/null +++ b/app/static/js/films.js @@ -0,0 +1,15 @@ +document.getElementById('sort-select').addEventListener('change', function () { + const sortValue = this.value + const $films = [...document.querySelectorAll('.film')] + console.log('$films', $films) + $films.sort((a, b) => { + console.log('a', a) + const aVal = a.dataset[sortValue] + const bVal = b.dataset[sortValue] + return aVal < bVal ? -1 : 1 + }) + document.getElementById('films').innerHTML = '' + $films.forEach($film => { + document.getElementById('films').appendChild($film) + }) +}) \ No newline at end of file diff --git a/app/templates/films.html b/app/templates/films.html index 3b1b15a..2e85e2d 100644 --- a/app/templates/films.html +++ b/app/templates/films.html @@ -1,9 +1,28 @@ {% extends "base.html" %} {% block body_class%}animated animated-text{% endblock %} {% block main %} -