Rewrite javascript snippets to be native javascript instead of jquery
authorMagnus Hagander <magnus@hagander.net>
Mon, 16 Jun 2025 09:06:50 +0000 (11:06 +0200)
committerMagnus Hagander <magnus@hagander.net>
Mon, 16 Jun 2025 09:16:55 +0000 (11:16 +0200)
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

index d25a86a63c8485f8bbe0668d3033e3a3fd6ee307..e3d4d8eaa6b9dc91db2eec809b4681faaa92914a 100644 (file)
@@ -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;
+        }
     });
 });