From 6b8bd255e6b784eaa909855f527b474e5ee1a123 Mon Sep 17 00:00:00 2001 From: Tixie Date: Tue, 3 Dec 2019 22:18:10 +0100 Subject: [PATCH] add random album feature --- assets/js/random.js | 25 +++++++++++++++++++++++++ layouts/_default/baseof.html | 8 ++++++++ 2 files changed, 33 insertions(+) diff --git a/assets/js/random.js b/assets/js/random.js index e69de29..c242dfa 100644 --- a/assets/js/random.js +++ b/assets/js/random.js @@ -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() diff --git a/layouts/_default/baseof.html b/layouts/_default/baseof.html index 8e298b0..c5d553d 100644 --- a/layouts/_default/baseof.html +++ b/layouts/_default/baseof.html @@ -48,6 +48,14 @@ {{ partial "footer" . }} + + {{ $mobilemenu := resources.Get "js/menu.js" }} {{ $randomizer := resources.Get "js/random.js" }} {{ $js := slice $mobilemenu $randomizer | resources.Concat "js/bundle.js" }}