Adds javascript for half star ratings

This commit is contained in:
Mouse Reeve 2021-09-10 14:27:08 -07:00
parent 0be53f9133
commit daf42a30da

View file

@ -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";
}
}
}();