Get rid of inline javascript
authorMagnus Hagander <magnus@hagander.net>
Fri, 4 Jan 2019 14:58:55 +0000 (15:58 +0100)
committerMagnus Hagander <magnus@hagander.net>
Fri, 4 Jan 2019 14:58:55 +0000 (15:58 +0100)
This moves the javascript out to the main.js file like we already had
done for the main website.

This also removes attempts to use the selectmenu plugin for the
dropdown. This has not worked since the new design was put in place,
because the appropriate scripts were simply never loaded. As people
seems to be happy with that, stop *trying* to load them causing
javascript failures on every webpage.

django/archives/mailarchives/templates/_message.html
django/archives/mailarchives/templates/base.html
django/archives/mailarchives/templates/message.html
django/archives/mailarchives/templates/message_flat.html
django/media/js/main.js

index 0884a5afb8f8037333ca5e6a2a4cab92847c1c7d..7dea7f3d64fb86745559128fbb97f11e965bd83e 100644 (file)
@@ -39,7 +39,7 @@
    <tr>
     <th class="align-middle" scope="row">Thread:</th>
     <td>
-     <select id="thread_select" class="custom-select" onchange="onThreadSelect()">
+     <select id="thread_select" class="custom-select">
   {%for m in threadstruct%}{%if m.id%}<option value="{{m.messageid|urlencode}}"{%if m.id == msg.id%} selected="selected"{%endif%}>{{m.indent|safe}}{{m.printdate}} from {{m.mailfrom|hidemail}}{% if m.hasattachment %}        &#x1f4ce;{% endif %}</option>{%endif%}
   {%endfor%}
      </select>
index a99eee1e8221b27e1bea0a519712c45d5054eb38..282ac047155513fc3812646b778198228e33a63e 100644 (file)
     <script src="/media-archives/js/popper.min.js?{{gitrev}}"></script>
     <script src="/media-archives/js/bootstrap.min.js?{{gitrev}}"></script>
     <script src="/media-archives/js/main.js?{{gitrev}}"></script>
-    <script type="text/javascript">
-      var _gaq = _gaq || [];
-      _gaq.push(['_setAccount', 'UA-1345454-1']);
-      _gaq.push(['_trackPageview']);
-      (function() {
-        var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
-        ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
-        var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
-      })();
-    </script>
-    <script type="text/javascript">
-      var shiftWindow = function() { scrollBy(0, -80) };
-      if (location.hash) shiftWindow();
-      window.addEventListener("hashchange", shiftWindow);
-    </script>
   </body>
 </html>
index 0193acd3c1848252a68ec657ab9444513579baba..3de6998c93321525388419c69c8339bb0a5fcef1 100644 (file)
@@ -1,24 +1,6 @@
 {%extends "page.html"%}
 {%block title%}{%if not msg.hiddenstatus%}{{msg.subject}}{%endif%}{%endblock%}
 
-{%block extrahead%}
-<script type="text/javascript">
-function onThreadSelect() {
-   document.location.href = '/message-id/' + document.getElementById('thread_select').value;
-}
-
-$(function(){
-   $('select#thread_select').selectmenu({
-      style:'dropdown',
-      escapeHtml:true,
-      icons:[
-         {find:'.hasatt', icon: 'ui-icon-document'},
-      ]
-   });
-});
-</script>
-{%endblock%}
-
 {%block contents%}
 {%if not msg.hiddenstatus%}
 <h1 class="subject">{{msg.subject}}</h1>
index fd3c53046c1137e095f8df3f23f96d3cf0ac9381..c0196af4f48a2fc1e0090c3e3a3077b1b1af33b3 100644 (file)
@@ -4,20 +4,10 @@
 {%load pgfilters%}
 {%block extrahead%}
 <meta name="robots" content="noindex" />
-{%if not isfirst%}
-<script type="text/javascript">
-function load() {
-   if (document.location.href.indexOf('#') < 0) {
-      document.location.href = document.location.href + '#' + '{{msg.messageid|md5}}';
-   }
-}
-window.onload = load;
-</script>
-{%endif%}
 {%endblock%}
 {%block contents%}
 {%if not msg.hiddenstatus%}
-<h1 class="subject">{{msg.subject}}</h1>
+<h1 id="flatMsgSubject" class="subject" data-isfirst="{{isfirst}}" data-msgid="{{msg.messageid|md5}}">{{msg.subject}}</h1>
 <table class="table-sm table-responsive message-header" style="border-bottom: 0.05em solid #E7EAE8; margin-bottom: 1em;">
  <tr>
   <th scope="row" style="width: 10%">Lists:</th>
index b994d54e8327a4e4731e3df95b5a78373d7b7984..bd1093e862bbf59216e40804319fef4c96291734 100644 (file)
@@ -3,3 +3,37 @@ $(document).ready(function() {
     $(".navbar").toggleClass("compressed", $(window).scrollTop() >= 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();
+    });
+
+
+    /*
+     * 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) {
+       if (document.location.href.indexOf('#') < 0) {
+           document.location.href = document.location.href + '#' + $(e).data('msgid');
+           return;
+       }
+    });
+});
+
+
+
+/*
+ * Google analytics
+ */
+var _gaq = _gaq || [];
+_gaq.push(['_setAccount', 'UA-1345454-1']);
+_gaq.push(['_trackPageview']);
+(function() {
+    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
+    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
+    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
+})();