phantasma/app/static/js/films.js

44 lines
1.5 KiB
JavaScript
Raw Normal View History

2021-10-28 17:17:34 +00:00
// FIXME: move to utils
// From: https://stackoverflow.com/a/175787
function isNumeric (str) {
return !isNaN(str) && // use type coercion to parse the _entirety_ of the string (`parseFloat` alone does not do this)...
!isNaN(parseFloat(str)) // ...and ensure strings of whitespace fail
}
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) => {
2021-10-28 17:17:34 +00:00
let aVal = a.dataset[sortValue]
let bVal = b.dataset[sortValue]
if (isNumeric(aVal) && isNumeric(bVal)) {
aVal = parseFloat(aVal)
bVal = parseFloat(bVal)
}
2021-10-28 16:19:16 +00:00
return aVal < bVal ? -1 : 1
})
2021-10-28 16:33:47 +00:00
document.getElementById('films-list').innerHTML = ''
2021-10-28 16:19:16 +00:00
$films.forEach($film => {
2021-10-28 16:33:47 +00:00
document.getElementById('films-list').appendChild($film)
2021-10-28 16:19:16 +00:00
})
2021-10-28 16:31:08 +00:00
}
2021-11-12 10:21:00 +00:00
//document.getElementById('sort-select').addEventListener('change', selectChanged)
2021-10-28 16:31:08 +00:00
const locationHash = location.hash.replace('#', '')
if (locationHash !== '') {
document.getElementById('sort-select').value = locationHash
selectChanged()
2021-11-12 10:21:00 +00:00
}
document.querySelectorAll('.films .film figure').forEach(figure => {
var imgs = figure.querySelectorAll('img')
if (imgs.length > 1) {
setInterval(() => {
var img = figure.querySelector('img')
img.parentElement.appendChild(img)
2021-11-12 13:02:02 +00:00
}, 5000 + Math.random() * 1000)
2021-11-12 10:21:00 +00:00
}
})