Browse code

Merge branch 'staging'

* staging:
Do not use onchange=<inline script>, instead add listeners in init
Move Debian sources.list generator JS into its own file (re: #21769)

Peter Palfrader authored on 19/03/2017 18:37:14
Showing 3 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,163 @@
1
+// This code is based on the http://mozilla.debian.net sources.list
2
+// generator as originally written by Mike Hommey. It is licensed under
3
+// the terms of the GNU GPLv2, http://www.gnu.org/licenses/gpl-2.0.html.
4
+var sources = {};
5
+var software = {
6
+'tor': { '_stable': {
7
+                     'wheezy':  [ 'wheezy' ],
8
+                     'jessie':  [ 'jessie' ],
9
+                     'stretch': [ 'stretch' ],
10
+                     'sid':     [ 'sid' ],
11
+                     'precise': [ 'precise'],
12
+                     'trusty':  [ 'trusty'],
13
+                     'xenial':  [ 'xenial'],
14
+                     'yakkety': [ 'yakkety'],
15
+                     },
16
+         'experimental-0.3.0.x': {
17
+                     'wheezy':  [ 'wheezy' ],
18
+                     'jessie':  [ 'jessie' ],
19
+                     'stretch': [ 'stretch' ],
20
+                     'sid':     [ 'sid' ],
21
+                     'precise': [ 'precise'],
22
+                     'trusty':  [ 'trusty'],
23
+                     'xenial':  [ 'xenial'],
24
+                     'yakkety': [ 'yakkety'],
25
+                     },
26
+       },
27
+'tor (from source)': {
28
+         '_stable': {
29
+                     'wheezy':  [ 'wheezy' ],
30
+                     'jessie':  [ 'jessie' ],
31
+                     'stretch': [ 'stretch' ],
32
+                     'sid':     [ 'sid' ],
33
+                     'precise': [ 'precise'],
34
+                     'trusty':  [ 'trusty'],
35
+                     'xenial':  [ 'xenial'],
36
+                     'yakkety': [ 'yakkety'],
37
+                     },
38
+         'experimental-0.3.0.x': {
39
+                     'wheezy':  [ 'wheezy' ],
40
+                     'jessie':  [ 'jessie' ],
41
+                     'stretch': [ 'stretch' ],
42
+                     'sid':     [ 'sid' ],
43
+                     'precise': [ 'precise'],
44
+                     'trusty':  [ 'trusty'],
45
+                     'xenial':  [ 'xenial'],
46
+                     'yakkety': [ 'yakkety'],
47
+                     },
48
+       },
49
+};
50
+
51
+function init() {
52
+    document.getElementById("distrib").addEventListener("change", update);
53
+    document.getElementById("package").addEventListener("change", update);
54
+    document.getElementById("version").addEventListener("change", update);
55
+
56
+    pkg = document.getElementById('package');
57
+    for (soft in software) {
58
+        if (soft != pkg.value) {
59
+            option = document.createElement('option');
60
+            option.value = soft;
61
+            option.appendChild(document.createTextNode(soft.charAt(0).toUpperCase() + soft.slice(1)));
62
+            pkg.appendChild(option);
63
+        }
64
+    }
65
+
66
+    apt_get = document.getElementById('apt-get');
67
+    para = document.createElement('p');
68
+    para.id = 'sorry';
69
+    para.style.display = 'none';
70
+    apt_get.parentNode.insertBefore(para, apt_get);
71
+    para.appendChild(document.createTextNode("Sorry, this version is not available.\n"));
72
+
73
+    document.getElementById('selector').style.display = 'block';
74
+
75
+    update();
76
+}
77
+
78
+function replaceText(src, txt) {
79
+    while (src.firstChild)
80
+        src.removeChild(src.firstChild);
81
+    src.appendChild(document.createTextNode(txt));
82
+}
83
+
84
+function update() {
85
+    pkg = document.getElementById('package');
86
+    ver = document.getElementById('version');
87
+    package = pkg.value;
88
+    version = ver.value;
89
+    distrib = document.getElementById('distrib').value;
90
+    if (package != pkg.prev) {
91
+        while (ver.firstChild)
92
+            ver.removeChild(ver.firstChild);
93
+        var selected;
94
+        for (version in software[package]) {
95
+            option = document.createElement('option');
96
+            if (version[0] == '_') {
97
+                version = version.slice(1);
98
+                selected = version;
99
+            }
100
+            option.appendChild(document.createTextNode(version));
101
+            option.value = version = version.replace(/ \(.*\)/,'');
102
+//alert(version);
103
+            ver.appendChild(option);
104
+        }
105
+        ver.value = version = selected || version;
106
+        pkg.prev = package
107
+    }
108
+    try {
109
+        keys = software[package][version][distrib];
110
+    } catch (e) {
111
+        try {
112
+            keys = software[package]['_' + version][distrib];
113
+        } catch (e) { };
114
+    }
115
+    src = document.getElementById('sources');
116
+    txt = '';
117
+    need_signed = false;
118
+    source_install = false;
119
+    target = '';
120
+    for (i = 0; keys && (i < keys.length); i++) {
121
+//alert(keys[i]);
122
+        if (keys[i] in sources) {
123
+            txt += sources[keys[i]];
124
+            target = keys[i];
125
+        } else {
126
+            if (package.slice(-7, -1) == 'source') {
127
+                package = package.split(' ')[0];
128
+                source_install = true;
129
+            }
130
+            txt += "http://deb.torproject.org/torproject.org";
131
+            txt += " ";
132
+            txt += keys[i];
133
+            txt += " main";
134
+            need_signed = true;
135
+            target = keys[i];
136
+            txt = "deb " + txt + "\ndeb-src " + txt;
137
+            if (version != 'stable') {
138
+                txt2 = "http://deb.torproject.org/torproject.org";
139
+                txt2 += " ";
140
+                txt2 += package;
141
+                txt2 += "-";
142
+                txt2 += version;
143
+                txt2 += "-";
144
+                txt2 += keys[i];
145
+                txt2 += " main";
146
+                txt = txt + "\ndeb " + txt2 + "\ndeb-src " + txt2;
147
+            }
148
+        }
149
+        txt += "\n";
150
+    }
151
+    replaceText(src, txt);
152
+    document.getElementById('regular-install').style.display = source_install ? 'none' : 'block';
153
+    document.getElementById('source-install').style.display = source_install ? 'block' : 'none';
154
+    document.getElementById('source-install2').style.display = source_install ? 'block' : 'none';
155
+    replaceText(document.getElementById('apt-package'), package);
156
+    document.getElementById('apt-source').style.display = (keys && keys.length) ? 'block' : 'none';
157
+    document.getElementById('apt-get').style.display = keys ? 'block' : 'none';
158
+    document.getElementById('sorry').style.display = keys ? 'none' : 'block';
159
+}
160
+
161
+document.addEventListener('DOMContentLoaded', function () {
162
+  init();
163
+});
... ...
@@ -3,171 +3,9 @@
3 3
 # Translation-Priority: 3-low
4 4
 
5 5
 #include "head.wmi" TITLE="Tor Project: Debian/Ubuntu Instructions" CHARSET="UTF-8"
6
-
7
-<script>
8
-<!--
9
-// This code is based on the http://mozilla.debian.net sources.list
10
-// generator as originally written by Mike Hommey. It is licensed under
11
-// the terms of the GNU GPLv2, http://www.gnu.org/licenses/gpl-2.0.html.
12
-var sources = {};
13
-var software = {
14
-'tor': { '_stable': {
15
-                     'wheezy':  [ 'wheezy' ],
16
-                     'jessie':  [ 'jessie' ],
17
-                     'stretch': [ 'stretch' ],
18
-                     'sid':     [ 'sid' ],
19
-                     'precise': [ 'precise'],
20
-                     'trusty':  [ 'trusty'],
21
-                     'xenial':  [ 'xenial'],
22
-                     'yakkety': [ 'yakkety'],
23
-                     },
24
-         'experimental-0.3.0.x': {
25
-                     'wheezy':  [ 'wheezy' ],
26
-                     'jessie':  [ 'jessie' ],
27
-                     'stretch': [ 'stretch' ],
28
-                     'sid':     [ 'sid' ],
29
-                     'precise': [ 'precise'],
30
-                     'trusty':  [ 'trusty'],
31
-                     'xenial':  [ 'xenial'],
32
-                     'yakkety': [ 'yakkety'],
33
-                     },
34
-       },
35
-'tor (from source)': {
36
-         '_stable': {
37
-                     'wheezy':  [ 'wheezy' ],
38
-                     'jessie':  [ 'jessie' ],
39
-                     'stretch': [ 'stretch' ],
40
-                     'sid':     [ 'sid' ],
41
-                     'precise': [ 'precise'],
42
-                     'trusty':  [ 'trusty'],
43
-                     'xenial':  [ 'xenial'],
44
-                     'yakkety': [ 'yakkety'],
45
-                     },
46
-         'experimental-0.3.0.x': {
47
-                     'wheezy':  [ 'wheezy' ],
48
-                     'jessie':  [ 'jessie' ],
49
-                     'stretch': [ 'stretch' ],
50
-                     'sid':     [ 'sid' ],
51
-                     'precise': [ 'precise'],
52
-                     'trusty':  [ 'trusty'],
53
-                     'xenial':  [ 'xenial'],
54
-                     'yakkety': [ 'yakkety'],
55
-                     },
56
-       },
57
-};
58
-
59
-function init() {
60
-    pkg = document.getElementById('package');
61
-    for (soft in software) {
62
-        if (soft != pkg.value) {
63
-            option = document.createElement('option');
64
-            option.value = soft;
65
-            option.appendChild(document.createTextNode(soft.charAt(0).toUpperCase() + soft.slice(1)));
66
-            pkg.appendChild(option);
67
-        }
68
-    }
69
-
70
-    apt_get = document.getElementById('apt-get');
71
-    para = document.createElement('p');
72
-    para.id = 'sorry';
73
-    para.style.display = 'none';
74
-    apt_get.parentNode.insertBefore(para, apt_get);
75
-    para.appendChild(document.createTextNode("Sorry, this version is not available.\n"));
76
-
77
-    document.getElementById('selector').style.display = 'block';
78
-
79
-    update();
80
-}
81
-
82
-function replaceText(src, txt) {
83
-    while (src.firstChild)
84
-        src.removeChild(src.firstChild);
85
-    src.appendChild(document.createTextNode(txt));
86
-}
87
-
88
-function update() {
89
-    pkg = document.getElementById('package');
90
-    ver = document.getElementById('version');
91
-    package = pkg.value;
92
-    version = ver.value;
93
-    distrib = document.getElementById('distrib').value;
94
-    if (package != pkg.prev) {
95
-        while (ver.firstChild)
96
-            ver.removeChild(ver.firstChild);
97
-        var selected;
98
-        for (version in software[package]) {
99
-            option = document.createElement('option');
100
-            if (version[0] == '_') {
101
-                version = version.slice(1);
102
-                selected = version;
103
-            }
104
-            option.appendChild(document.createTextNode(version));
105
-            option.value = version = version.replace(/ \(.*\)/,'');
106
-//alert(version);
107
-            ver.appendChild(option);
108
-        }
109
-        ver.value = version = selected || version;
110
-        pkg.prev = package
111
-    }
112
-    try {
113
-        keys = software[package][version][distrib];
114
-    } catch (e) {
115
-        try {
116
-            keys = software[package]['_' + version][distrib];
117
-        } catch (e) { };
118
-    }
119
-    src = document.getElementById('sources');
120
-    txt = '';
121
-    need_signed = false;
122
-    source_install = false;
123
-    target = '';
124
-    for (i = 0; keys && (i < keys.length); i++) {
125
-//alert(keys[i]);
126
-        if (keys[i] in sources) {
127
-            txt += sources[keys[i]];
128
-            target = keys[i];
129
-        } else {
130
-            if (package.slice(-7, -1) == 'source') {
131
-                package = package.split(' ')[0];
132
-                source_install = true;
133
-            }
134
-            txt += "http://deb.torproject.org/torproject.org";
135
-            txt += " ";
136
-            txt += keys[i];
137
-            txt += " main";
138
-            need_signed = true;
139
-            target = keys[i];
140
-            txt = "deb " + txt + "\ndeb-src " + txt;
141
-            if (version != 'stable') {
142
-                txt2 = "http://deb.torproject.org/torproject.org";
143
-                txt2 += " ";
144
-                txt2 += package;
145
-                txt2 += "-";
146
-                txt2 += version;
147
-                txt2 += "-";
148
-                txt2 += keys[i];
149
-                txt2 += " main";
150
-                txt = txt + "\ndeb " + txt2 + "\ndeb-src " + txt2;
151
-            }
152
-        }
153
-        txt += "\n";
154
-    }
155
-    replaceText(src, txt);
156
-    document.getElementById('regular-install').style.display = source_install ? 'none' : 'block';
157
-    document.getElementById('source-install').style.display = source_install ? 'block' : 'none';
158
-    document.getElementById('source-install2').style.display = source_install ? 'block' : 'none';
159
-    replaceText(document.getElementById('apt-package'), package);
160
-    document.getElementById('apt-source').style.display = (keys && keys.length) ? 'block' : 'none';
161
-    document.getElementById('apt-get').style.display = keys ? 'block' : 'none';
162
-    document.getElementById('sorry').style.display = keys ? 'none' : 'block';
163
-}
164
-
165
-window.onload = init;
166
-
167
-</script>
168
-
169
-
6
+{#meta#:
7
+<script type="text/javascript" src="debian-selector.js"></script>
8
+:#meta#}
170 9
 
171 10
 <div id="content" class="clearfix">
172 11
   <div id="breadcrumbs">
... ...
@@ -232,7 +70,7 @@ For Ubuntu, ask <a href="https://en.wikipedia.org/wiki/List_of_Ubuntu_releases#T
232 70
 <div id="selector" style="display: none;">
233 71
 <blockquote>
234 72
 I run
235
-<select id="distrib" onchange="update()">
73
+<select id="distrib">
236 74
 <option value="wheezy">Debian oldstable (wheezy)</option>
237 75
 <option value="jessie" selected="selected">Debian stable (jessie)</option>
238 76
 <option value="stretch">Debian testing (stretch)</option>
... ...
@@ -242,9 +80,9 @@ I run
242 80
 <option value="xenial">Ubuntu Xenial Xerus</option>
243 81
 </select>
244 82
 and want
245
-<select id="package" onchange="update()"></select>
83
+<select id="package"></select>
246 84
 version
247
-<select id="version" onchange="update()"></select>
85
+<select id="version"></select>
248 86
 </blockquote>
249 87
 
250 88
 
... ...
@@ -17,6 +17,7 @@
17 17
    <meta name="description" content="Tor is a free software that prevents people from learning your location or browsing habits by letting you communicate anonymously on the Internet. It also helps you bypass censorship online. If you can't open the website, email gettor@torproject.org for instruction on how to get Tor Browser.">
18 18
    <meta name="keywords" content="anonymity online, tor, tor project, censorship circumvention, traffic analysis, anonymous communications research">
19 19
    <meta property="og:image" content="https://www.torproject.org/images/tor-logo.jpg">
20
+{#meta#}
20 21
 
21 22
    <title>$(TITLE)</title>
22 23