2021-10-28 16:31:08 +00:00
|
|
|
function selectChanged() {
|
|
|
|
const sortValue = document.getElementById('sort-select').value
|
2021-10-28 16:19:16 +00:00
|
|
|
const $films = [...document.querySelectorAll('.film')]
|
2021-10-28 16:31:08 +00:00
|
|
|
location.hash = sortValue
|
2021-10-28 16:19:16 +00:00
|
|
|
$films.sort((a, b) => {
|
|
|
|
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)
|
|
|
|
})
|
2021-10-28 16:31:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
document.getElementById('sort-select').addEventListener('change', selectChanged)
|
|
|
|
|
|
|
|
const locationHash = location.hash.replace('#', '')
|
|
|
|
if (locationHash !== '') {
|
|
|
|
document.getElementById('sort-select').value = locationHash
|
|
|
|
selectChanged()
|
|
|
|
}
|