no inline function calls pls

This commit is contained in:
Evert Prants 2018-10-07 19:29:04 +03:00
parent 52e4810a1f
commit 396ab27aaa
Signed by: evert
GPG Key ID: 1688DA83D222D0B5
2 changed files with 181 additions and 134 deletions

View File

@ -24,11 +24,11 @@
</table> </table>
</div> </div>
<div class="pages flex-row"> <div class="pages flex-row">
<div class="paging btn" id="jump-first" onclick="showTracks(1)"><<</div> <div class="paging btn" id="jump-first"><<</div>
<div class="paging btn inner" id="jump-prev" onclick="showTracks(pageNum - 1)"><</div> <div class="paging btn inner" id="jump-prev"><</div>
<div class="paging bg" id="pagenum">0 / 0</div> <div class="paging bg" id="pagenum">0 / 0</div>
<div class="paging btn inner" id="jump-next" onclick="showTracks(pageNum + 1)">></div> <div class="paging btn inner" id="jump-next">></div>
<div class="paging btn" id="jump-last" onclick="showTracks(pages)">>></div> <div class="paging btn" id="jump-last">>></div>
</div> </div>
<div class="player flex-row"> <div class="player flex-row">
<div id="playing">Nothing playing</div> <div id="playing">Nothing playing</div>

View File

@ -1,3 +1,4 @@
(function () {
var table = document.querySelector('#ttable') var table = document.querySelector('#ttable')
var input = document.querySelector('#search') var input = document.querySelector('#search')
var audio = document.querySelector('#player') var audio = document.querySelector('#player')
@ -72,7 +73,7 @@ function constructList (tracks) {
for (let i in tracks) { for (let i in tracks) {
let track = tracks[i] let track = tracks[i]
let title = window.mobilecheck() ? shortTitle(track.title, track.artist) : track.title let title = window.mobilecheck() ? shortTitle(track.title, track.artist) : track.title
let htmlAdder = '<tr onclick="play(' + track.id + ')">' let htmlAdder = '<tr class="track">'
htmlAdder += '<td>' + track.id + '</td>' htmlAdder += '<td>' + track.id + '</td>'
htmlAdder += '<td>' + title + '</td>' htmlAdder += '<td>' + title + '</td>'
htmlAdder += '<td>' + (track.artist || '') + '</td>' htmlAdder += '<td>' + (track.artist || '') + '</td>'
@ -82,6 +83,18 @@ function constructList (tracks) {
htmlAdder += '</tr>' htmlAdder += '</tr>'
table.innerHTML += htmlAdder table.innerHTML += htmlAdder
} }
let trid = document.querySelectorAll('table .track')
for (let e in trid) {
let trelem = trid[e]
if (!(trelem instanceof Element)) continue
let tride = trelem.querySelector('td')
let id = parseInt(tride.innerHTML)
trelem.addEventListener('click', function (e) {
play(id)
}, false)
}
} }
function updatePaging () { function updatePaging () {
@ -151,6 +164,40 @@ prev.addEventListener('click', function (e) {
play(nowPlaying - 1) play(nowPlaying - 1)
}) })
document.getElementById('jump-first').addEventListener('click', function (e) {
showTracks(1)
}, false)
document.getElementById('jump-prev').addEventListener('click', function (e) {
showTracks(pageNum - 1)
}, false)
document.getElementById('jump-next').addEventListener('click', function (e) {
showTracks(pageNum + 1)
}, false)
document.getElementById('jump-last').addEventListener('click', function (e) {
showTracks(pages)
}, false)
showTracks(1) showTracks(1)
window.play = play function handleHash (hash) {
if (hash.indexOf('#') === 0) hash = hash.substr(1)
if (hash.length === 0) return
window.location.hash = ''
if (hash.indexOf('track-') === 0) {
let trackNr = parseInt(hash.substr(6))
if (!isNaN(trackNr)) return play(trackNr)
}
}
window.addEventListener('hashchange', function (e) {
e.preventDefault()
handleHash(window.location.hash)
}, false)
handleHash(window.location.hash)
})()