22 lines
No EOL
746 B
JavaScript
22 lines
No EOL
746 B
JavaScript
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()
|
|
} |