diff --git a/devplacepy/static/js/VoteManager.js b/devplacepy/static/js/VoteManager.js index 2692cc3d..fb86a2b0 100644 --- a/devplacepy/static/js/VoteManager.js +++ b/devplacepy/static/js/VoteManager.js @@ -5,18 +5,21 @@ import { OptimisticAction } from "./OptimisticAction.js"; export class VoteManager extends OptimisticAction { constructor() { super(); - this.initVoteButtons(); + document.addEventListener("click", (event) => this.onClick(event)); } - initVoteButtons() { - document.querySelectorAll('form[action^="/votes/"] button[type="submit"]').forEach((button) => { - const form = button.closest("form"); - button.addEventListener("click", (event) => { - event.preventDefault(); - event.stopPropagation(); - this.cast(form, button); - }); - }); + onClick(event) { + const button = event.target.closest('form[action^="/votes/"] button[type="submit"]'); + if (!button) { + return; + } + const form = button.closest("form"); + if (!form) { + return; + } + event.preventDefault(); + event.stopPropagation(); + this.cast(form, button); } cast(form, button) { diff --git a/devplacepy/templating.py b/devplacepy/templating.py index 4e328b68..1fa42b56 100644 --- a/devplacepy/templating.py +++ b/devplacepy/templating.py @@ -29,7 +29,7 @@ def is_self(user, uid) -> bool: def guest_disabled(user) -> Markup: if user: return Markup("") - return Markup(' disabled aria-disabled="true"') + return Markup(' disabled aria-disabled="true" title="Log in to vote"') def static_url(path) -> str: