From 2a74077d8edad5d45fb56fcb14456967d678232b Mon Sep 17 00:00:00 2001 From: Magnus Hagander Date: Mon, 16 Jun 2025 11:06:50 +0200 Subject: [PATCH] Rewrite javascript snippets to be native javascript instead of jquery Unfortunately at this time we still cannot drop the jquery dependency as it's needed by the menubar from bootstrap. --- django/media/js/main.js | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/django/media/js/main.js b/django/media/js/main.js index d25a86a..e3d4d8e 100644 --- a/django/media/js/main.js +++ b/django/media/js/main.js @@ -1,15 +1,20 @@ -$(function(){ - /* Callback from main message view when a message is picked in dropdown */ - $('#thread_select').change(function(e) { - document.location.href = '/message-id/' + $(this).val(); - }); +document.addEventListener('DOMContentLoaded', (event) => { + const threadselect = document.getElementById('thread_select'); + if (threadselect) { + threadselect.addEventListener('change', (event) => { + document.location.href = '/message-id/' + event.target.value; + event.preventDefault(); + }); + } /* Callback for viewing protected versions */ - $('a.post-link').click(function(e) { - if ($(this).data('ref')) { - $('#mail_other_options_form').attr('action', $(this).data('ref')); - $('#mail_other_options_form').submit(); - } + const postlinkform = document.getElementById('mail_other_options_form'); + document.querySelectorAll('a.post-link').forEach((link) => { + link.addEventListener('click', (event) => { + postlinkform.action = event.target.dataset.ref; + postlinkform.submit(); + event.preventDefault(); + }); }); @@ -17,11 +22,10 @@ $(function(){ * For flat message view, redirect to the anchor of the messageid we're watching, * unless we happen to be the first one. */ - $('#flatMsgSubject[data-isfirst=False]').each(function(i, e) { + document.querySelectorAll('#flatMsgSubject[data-isfirst=False]').forEach((e) => { if (document.location.href.indexOf('#') < 0) { - document.location.href = document.location.href + '#' + $(e).data('msgid'); - return; - } + document.location.href = document.location.href + '#' + e.dataset.msgid; + } }); }); -- 2.39.5