From e6dbd1f6e8bf5cab6a218b0a05b0a6c4d9e42dd2 Mon Sep 17 00:00:00 2001 From: Isaac Janzen <50783505+janzenisaac@users.noreply.github.com> Date: Wed, 14 Aug 2024 11:55:29 -0500 Subject: [PATCH] DEV: Remove jquery from votes (#206) --- assets/javascripts/discourse/widgets/vote-button.js | 8 ++++---- assets/javascripts/discourse/widgets/vote-count.js | 13 +++++++++---- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/assets/javascripts/discourse/widgets/vote-button.js b/assets/javascripts/discourse/widgets/vote-button.js index eb93687..e46cf9e 100644 --- a/assets/javascripts/discourse/widgets/vote-button.js +++ b/assets/javascripts/discourse/widgets/vote-button.js @@ -1,5 +1,5 @@ -import $ from "jquery"; import { h } from "virtual-dom"; +import cookie from "discourse/lib/cookie"; import { createWidget } from "discourse/widgets/widget"; import I18n from "I18n"; @@ -73,7 +73,7 @@ export default createWidget("vote-button", { click() { if (!this.currentUser) { this.sendWidgetAction("showLogin"); - $.cookie("destination_url", window.location.href); + cookie("destination_url", window.location.href, { path: "/" }); return; } if ( @@ -87,12 +87,12 @@ export default createWidget("vote-button", { this.sendWidgetAction("addVote"); } if (this.attrs.user_voted || this.currentUser.votes_exceeded) { - $(".vote-options").toggleClass("hidden"); + document.querySelector(".vote-options").classList.toggle("hidden"); } }, clickOutside() { - $(".vote-options").addClass("hidden"); + document.querySelector(".vote-options").classList.add("hidden"); this.parentWidget.state.initialVote = false; }, }); diff --git a/assets/javascripts/discourse/widgets/vote-count.js b/assets/javascripts/discourse/widgets/vote-count.js index a896cb1..82aae24 100644 --- a/assets/javascripts/discourse/widgets/vote-count.js +++ b/assets/javascripts/discourse/widgets/vote-count.js @@ -1,6 +1,6 @@ -import $ from "jquery"; import { h } from "virtual-dom"; import { ajax } from "discourse/lib/ajax"; +import cookie from "discourse/lib/cookie"; import { createWidget } from "discourse/widgets/widget"; import getURL from "discourse-common/lib/get-url"; @@ -43,7 +43,7 @@ export default createWidget("vote-count", { click() { if (!this.currentUser) { this.sendWidgetAction("showLogin"); - $.cookie("destination_url", window.location.href); + cookie("destination_url", window.location.href, { path: "/" }); return; } @@ -54,13 +54,18 @@ export default createWidget("vote-count", { if (this.state.whoVotedUsers === null) { return this.getWhoVoted(); } else { - $(".who-voted").toggle(); + const whoVotedElement = document.querySelector(".who-voted"); + whoVotedElement.style.display = + whoVotedElement.style.display === "none" ? "block" : "none"; } } }, clickOutside() { - $(".who-voted").hide(); + const whoVotedElement = document.querySelector(".who-voted"); + if (whoVotedElement) { + whoVotedElement.style.display = "none"; + } }, getWhoVoted() {