1
0
Fork 0
mirror of https://github.com/GuerillaHQ/now-playing synced 2024-06-27 14:01:35 +00:00

add random album feature

This commit is contained in:
Tixie 2019-12-03 22:18:10 +01:00
parent 9bcc17751c
commit 6b8bd255e6
2 changed files with 33 additions and 0 deletions

View file

@ -0,0 +1,25 @@
class GoRandomAlbum {
constructor () {
this.urls = window.albumsUrls
this.btn = document.querySelector('[data-random="btn"]')
}
init () {
this.bindEvents()
}
bindEvents () {
if (this.btn && this.urls) {
this.btn.addEventListener('click', () => {
this.getRandomUrl()
})
}
}
getRandomUrl() {
const index = Math.floor(Math.random()*(this.urls.length+1));
window.location.href = this.urls[index]
}
}
new GoRandomAlbum().init()

View file

@ -48,6 +48,14 @@
{{ partial "footer" . }}
<script>
window.albumsUrls = [
{{ range where .Site.RegularPages "Type" "in" "musics" }}
"{{ .Permalink}}",
{{ end }}
]
</script>
{{ $mobilemenu := resources.Get "js/menu.js" }}
{{ $randomizer := resources.Get "js/random.js" }}
{{ $js := slice $mobilemenu $randomizer | resources.Concat "js/bundle.js" }}