Bug 22357: Move download lang drop-down code to external .js file
Arthur Edelstein

Arthur Edelstein commited on 2017-05-24 08:21:38
Zeige 3 geänderte Dateien mit 34 Einfügungen und 36 Löschungen.

... ...
@@ -26,6 +26,7 @@ body {
26 26
 .toptwenty { margin-top: 20px; }
27 27
 .topforty { margin-top: 40px; }
28 28
 
29
+.hidden { display: none; }
29 30
 
30 31
 /* HEADER ------------*/
31 32
 
... ...
@@ -54,44 +54,15 @@
54 54
    Source: http://www.stemkoski.com/stupid-simple-jquery-accordion-menu/
55 55
    License: Public Domain (http://www.stemkoski.com/stupid-simple-jquery-accordion-menu/#comment-32882) */
56 56
   </script>
57
-  <script async type="text/javascript">
58
-# /* switches package links depending on selection */
59
-  function updateLang() {
60
-    var caller = $( this );
61
-    var pkg = caller.attr('id');
62
-    var lang = caller.val();
63
-    var wintbb = '../dist/torbrowser/<version-torbrowserbundledir>/torbrowser-install-<version-torbrowserbundle>_'+lang+'.exe';
64
-    var osxtbb = '../dist/torbrowser/<version-torbrowserbundledir>/TorBrowser-<version-torbrowserbundleosx64>-osx64_'+lang+'.dmg';
65
-    var osxtbb64 = '../dist/torbrowser/<version-torbrowserbundledir>/TorBrowser-<version-torbrowserbundleosx64>-osx64_'+lang+'.dmg';
66
-    var lintbb32 = '../dist/torbrowser/<version-torbrowserbundledir>/tor-browser-linux32-<version-torbrowserbundlelinux32>_'+lang+'.tar.xz';
67
-    var lintbb64 = '../dist/torbrowser/<version-torbrowserbundledir>/tor-browser-linux64-<version-torbrowserbundlelinux64>_'+lang+'.tar.xz';
68
-    if(pkg == 'win-tbb'){
69
-      $('.'+pkg).replaceWith('<a class="button win-tbb" href="'+wintbb+'"><span class="strong">Download</span><span class="normal"><button-win-tbb32></span></a>');
70
-      $('.'+pkg+'-sig').replaceWith('<a class="win-tbb-sig" href="'+wintbb+'.asc">sig</a>');
71
-    }else if(pkg == 'osx-tbb'){
72
-      $('.'+pkg).replaceWith('<a class="button osx-tbb" href="'+osxtbb+'"><span class="strong">Download</span><span class="normal"><button-osx-tbb32></span></a>');
73
-      $('.'+pkg+'-sig').replaceWith('<a class="osx-tbb-sig" href="'+osxtbb+'.asc">sig</a>');
74
-    }else if(pkg == 'osx-tbb64'){
75
-      $('.'+pkg).replaceWith('<a class="button osx-tbb64" href="'+osxtbb64+'"><span class="strong">Download</span><span class="normal"><button-osx-tbb64></span></a>');
76
-      $('.'+pkg+'-sig').replaceWith('<a class="osx-tbb64-sig" href="'+osxtbb64+'.asc">sig</a>');
77
-    }else if(pkg == 'lin-tbb32'){
78
-      $('.'+pkg).replaceWith('<a class="button lin-tbb32" href="'+lintbb32+'"><span class="strong">Download</span><span class="normal"><button-lin-tbb32></span></a>');
79
-      $('.'+pkg+'-sig').replaceWith('<a class="lin-tbb32-sig" href="'+lintbb32+'.asc">sig</a>');
80
-    }else if(pkg == 'lin-tbb64'){
81
-      $('.'+pkg).replaceWith('<a class="button lin-tbb64" href="'+lintbb64+'"><span class="strong">Download</span><span class="normal"><button-lin-tbb64></span></a>');
82
-      $('.'+pkg+'-sig').replaceWith('<a class="lin-tbb64-sig" href="'+lintbb64+'.asc">sig</a>');
83
-    }
84
-  }
85
-
86
-  $(function(){
87
-    $('.lang').ready(updateLang);
88
-    $('.lang').change(updateLang);
89
-    /* Only show language selector if javascript is enabled */
90
-    $('.lang').css('display', 'block');
91
-  });
92
-  </script>
93 57
 </head>
94 58
 <body onload="resetAll()" onunload="">
59
+    <span class="hidden" id="version-data">
60
+        { "torbrowserbundledir" : "<version-torbrowserbundledir>",
61
+          "torbrowserbundle" : "<version-torbrowserbundle>",
62
+          "torbrowserbundleosx64" : "<version-torbrowserbundleosx64>",
63
+          "torbrowserbundlelinux32" : "<version-torbrowserbundlelinux32>",
64
+          "torbrowserbundlelinux64" : "<version-torbrowserbundlelinux64>"  }
65
+    </span>
95 66
 <div id="wrap">
96 67
   <div id="header">
97 68
     <h1 id="logo"><a href="<page index>">Tor</a></h1>
... ...
@@ -36,6 +36,32 @@ function resetAll() {
36 36
   }
37 37
 }
38 38
 
39
+/* switches package links depending on selection */
40
+function updateLang() {
41
+  var caller = $( this );
42
+  var pkg = caller.attr('id');
43
+  var lang = caller.val();
44
+  var versions = JSON.parse($("#version-data").text());
45
+  var rootDir = '../dist/torbrowser/' + versions.torbrowserbundledir + '/';
46
+  var bundles = {
47
+    'win-tbb' : rootDir + 'torbrowser-install-' + versions.torbrowserbundle + '_' + lang + '.exe',
48
+    'osx-tbb' : rootDir + 'TorBrowser-' + versions.torbrowserbundleosx64 + '-osx64_' + lang +'.dmg',
49
+    'osx-tbb64' : rootDir + 'TorBrowser-' + versions.torbrowserbundleosx64 + '-osx64_' + lang + '.dmg',
50
+    'lin-tbb32' : rootDir + 'tor-browser-linux32-' + versions.torbrowserbundlelinux32 + '_' + lang + '.tar.xz',
51
+    'lin-tbb64' : rootDir + 'tor-browser-linux64-' + versions.torbrowserbundlelinux64 + '_' + lang + '.tar.xz'
52
+  };
53
+
54
+  $('.'+pkg).attr("href", bundles[pkg]);
55
+  $('.'+pkg+'-sig').attr("href", bundles[pkg] + '.asc');
56
+}
57
+
58
+$(function(){
59
+  $('.lang').ready(updateLang);
60
+  $('.lang').change(updateLang);
61
+  /* Only show language selector if javascript is enabled */
62
+  $('.lang').css('display', 'block');
63
+});
64
+
39 65
 $(document).ready(function () {
40 66
 
41 67
     $('.jump').click(function(event){
42 68