From daf42a30dac35b9c8e34da6721c9697a41dd9d9a Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Fri, 10 Sep 2021 14:27:08 -0700 Subject: [PATCH] Adds javascript for half star ratings --- bookwyrm/static/js/status_cache.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/bookwyrm/static/js/status_cache.js b/bookwyrm/static/js/status_cache.js index 659011856..a6eaf0341 100644 --- a/bookwyrm/static/js/status_cache.js +++ b/bookwyrm/static/js/status_cache.js @@ -14,6 +14,9 @@ let StatusCache = new class { 'submit', this.submitStatus.bind(this)) ); + + document.querySelectorAll('.form-rate-stars label.icon') + .forEach(button => button.addEventListener('click', this.toggleStar.bind(this))); } /** @@ -198,5 +201,24 @@ let StatusCache = new class { menu.click(); } } + + /** + * Reveal half-stars + * + * @param {Event} event + * @return {undefined} + */ + toggleStar(event) { + const label = event.currentTarget; + let wholeStar = document.getElementById(label.getAttribute("for")); + + if (wholeStar.checked) { + event.preventDefault(); + let halfStar = document.getElementById(label.dataset.forHalf); + + wholeStar.checked = null; + halfStar.checked = "checked"; + } + } }();