mirror of
https://github.com/GuerillaStudio/now-playing
synced 2025-01-02 09:21:57 +00:00
add random album feature
This commit is contained in:
parent
9bcc17751c
commit
6b8bd255e6
2 changed files with 33 additions and 0 deletions
|
@ -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()
|
|
@ -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" }}
|
||||
|
|
Loading…
Reference in a new issue