changeset 478:c65b81353b8f

downloads: replace inline scripts with an onload function
author Kevin Bullock <kbullock+mercurial@ringworld.org>
date Wed, 10 May 2017 12:19:45 -0500
parents aec3b193e5af
children 4b88b3c4fc80
files static/js/download.js templates/base.html
diffstat 2 files changed, 21 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/static/js/download.js	Wed May 10 11:46:48 2017 -0500
+++ b/static/js/download.js	Wed May 10 12:19:45 2017 -0500
@@ -132,3 +132,21 @@
         return out;
     }
 };
+
+(function (document, window) {
+  var load = function () {
+    Downloader.init(sources);
+    var dl = Downloader.select();
+    var versElement = document.getElementById('download-version')
+      , descElement = document.getElementById('download-description');
+    versElement.appendChild(document.createTextNode(dl.attr('version')));
+    descElement.appendChild(document.createTextNode(dl.attr('desc')));
+  }
+
+  if (document.readyState !== 'complete') {
+    document.addEventListener('DOMContentLoaded', load);
+    return;
+  }
+
+  load();
+})(document, window);
--- a/templates/base.html	Wed May 10 11:46:48 2017 -0500
+++ b/templates/base.html	Wed May 10 12:19:45 2017 -0500
@@ -7,10 +7,6 @@
         <script type="text/javascript" src="{{ url_for('static', filename='js/common.js') }}"></script>
         <script type="text/javascript" src="{{ url_for('static', filename='sources.js') }}"></script>
         <script type="text/javascript" src="{{ url_for('static', filename='js/download.js') }}"></script>
-        <script language="javascript">
-          Downloader.init(sources);
-          var dl = Downloader.select();
-        </script>
         <link rel="shortcut icon" type="image/x-icon" href="/images/favicon.ico">
 
         <title>Mercurial SCM</title>
@@ -49,10 +45,10 @@
                     </div>
                     <div class="col">
                         {% block sidebar %}
-                        <a class="download" href="/downloads" onClick="return dl.download();">
+                        <a class="download" href="/downloads" onClick="return window.dl.download();">
                             <strong>Download now</strong>
-                            Mercurial <em><script language="Javascript">dl.write('version');</script></em>
-                            <span><script language="javascript">dl.write('desc');</script></span>
+                            Mercurial <em id="download-version"></em>
+                            <span id="download-description"></span>
                         </a>
                         <dl>
                             <dt>Another OS?<br><em>Get Mercurial for:</em></dt>