store sort in url
This commit is contained in:
parent
cc5200fd2d
commit
57580ea9db
1 changed files with 12 additions and 5 deletions
|
@ -1,9 +1,8 @@
|
||||||
document.getElementById('sort-select').addEventListener('change', function () {
|
function selectChanged() {
|
||||||
const sortValue = this.value
|
const sortValue = document.getElementById('sort-select').value
|
||||||
const $films = [...document.querySelectorAll('.film')]
|
const $films = [...document.querySelectorAll('.film')]
|
||||||
console.log('$films', $films)
|
location.hash = sortValue
|
||||||
$films.sort((a, b) => {
|
$films.sort((a, b) => {
|
||||||
console.log('a', a)
|
|
||||||
const aVal = a.dataset[sortValue]
|
const aVal = a.dataset[sortValue]
|
||||||
const bVal = b.dataset[sortValue]
|
const bVal = b.dataset[sortValue]
|
||||||
return aVal < bVal ? -1 : 1
|
return aVal < bVal ? -1 : 1
|
||||||
|
@ -12,4 +11,12 @@ document.getElementById('sort-select').addEventListener('change', function () {
|
||||||
$films.forEach($film => {
|
$films.forEach($film => {
|
||||||
document.getElementById('films').appendChild($film)
|
document.getElementById('films').appendChild($film)
|
||||||
})
|
})
|
||||||
})
|
}
|
||||||
|
|
||||||
|
document.getElementById('sort-select').addEventListener('change', selectChanged)
|
||||||
|
|
||||||
|
const locationHash = location.hash.replace('#', '')
|
||||||
|
if (locationHash !== '') {
|
||||||
|
document.getElementById('sort-select').value = locationHash
|
||||||
|
selectChanged()
|
||||||
|
}
|
Loading…
Reference in a new issue