Mercurial > hg-website
annotate static/js/download.js @ 397:29d4b5e45423
Use flask to render site and get rid of submodules
We don't want to use statically generated html files anymore. We are using
flask to do the routing and render the templates for now. This means we also
get rid of the submoduels and put everything together in templates/.
author | David Soria Parra <davidsp@fb.com> |
---|---|
date | Fri, 07 Mar 2014 14:47:13 -0800 |
parents | 8e3b10220bb9 |
children | c65b81353b8f |
rev | line source |
---|---|
349
fb3ce83c1a48
download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents:
314
diff
changeset
|
1 function Download (source) { |
fb3ce83c1a48
download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents:
314
diff
changeset
|
2 this.version = source[0]; |
fb3ce83c1a48
download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents:
314
diff
changeset
|
3 this.regex = source[1]; |
fb3ce83c1a48
download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents:
314
diff
changeset
|
4 this.url = source[2]; |
fb3ce83c1a48
download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents:
314
diff
changeset
|
5 this.desc = source[3]; |
360
8e3b10220bb9
Mercurial version x.y.z, z=0 is always incorrect; disregard.
David Champion <dgc@uchicago.edu>
parents:
356
diff
changeset
|
6 |
8e3b10220bb9
Mercurial version x.y.z, z=0 is always incorrect; disregard.
David Champion <dgc@uchicago.edu>
parents:
356
diff
changeset
|
7 // Strip '.0' version suffix, unless it is for a minor version. |
8e3b10220bb9
Mercurial version x.y.z, z=0 is always incorrect; disregard.
David Champion <dgc@uchicago.edu>
parents:
356
diff
changeset
|
8 // It is always incorrect for Mercurial releases. |
8e3b10220bb9
Mercurial version x.y.z, z=0 is always incorrect; disregard.
David Champion <dgc@uchicago.edu>
parents:
356
diff
changeset
|
9 var points = this.version.split('.'); |
8e3b10220bb9
Mercurial version x.y.z, z=0 is always incorrect; disregard.
David Champion <dgc@uchicago.edu>
parents:
356
diff
changeset
|
10 if (points.length > 2 && points[points.length-1] == "0") { |
8e3b10220bb9
Mercurial version x.y.z, z=0 is always incorrect; disregard.
David Champion <dgc@uchicago.edu>
parents:
356
diff
changeset
|
11 points.pop(); |
8e3b10220bb9
Mercurial version x.y.z, z=0 is always incorrect; disregard.
David Champion <dgc@uchicago.edu>
parents:
356
diff
changeset
|
12 this.version = points.join("."); |
8e3b10220bb9
Mercurial version x.y.z, z=0 is always incorrect; disregard.
David Champion <dgc@uchicago.edu>
parents:
356
diff
changeset
|
13 } |
255
4a52186008ee
Add a first version of the sidebar
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
14 } |
4a52186008ee
Add a first version of the sidebar
David Soria Parra <dsp@php.net>
parents:
diff
changeset
|
15 |
260
dd7fababf8b6
Working version of the download button with simple OS detection
David Soria Parra <dsp@php.net>
parents:
255
diff
changeset
|
16 Download.prototype = { |
349
fb3ce83c1a48
download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents:
314
diff
changeset
|
17 matches: function (ua) { |
fb3ce83c1a48
download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents:
314
diff
changeset
|
18 if (ua.match(this.regex)) |
fb3ce83c1a48
download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents:
314
diff
changeset
|
19 return true; |
fb3ce83c1a48
download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents:
314
diff
changeset
|
20 return false; |
fb3ce83c1a48
download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents:
314
diff
changeset
|
21 }, |
260
dd7fababf8b6
Working version of the download button with simple OS detection
David Soria Parra <dsp@php.net>
parents:
255
diff
changeset
|
22 |
349
fb3ce83c1a48
download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents:
314
diff
changeset
|
23 download: function () { |
fb3ce83c1a48
download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents:
314
diff
changeset
|
24 document.location.href = this.url; |
fb3ce83c1a48
download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents:
314
diff
changeset
|
25 return false; |
fb3ce83c1a48
download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents:
314
diff
changeset
|
26 }, |
260
dd7fababf8b6
Working version of the download button with simple OS detection
David Soria Parra <dsp@php.net>
parents:
255
diff
changeset
|
27 |
349
fb3ce83c1a48
download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents:
314
diff
changeset
|
28 attr: function (key) { |
fb3ce83c1a48
download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents:
314
diff
changeset
|
29 return this[key]; |
260
dd7fababf8b6
Working version of the download button with simple OS detection
David Soria Parra <dsp@php.net>
parents:
255
diff
changeset
|
30 }, |
dd7fababf8b6
Working version of the download button with simple OS detection
David Soria Parra <dsp@php.net>
parents:
255
diff
changeset
|
31 |
349
fb3ce83c1a48
download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents:
314
diff
changeset
|
32 write: function (key) { |
fb3ce83c1a48
download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents:
314
diff
changeset
|
33 document.write(this[key]); |
fb3ce83c1a48
download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents:
314
diff
changeset
|
34 } |
fb3ce83c1a48
download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents:
314
diff
changeset
|
35 } |
fb3ce83c1a48
download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents:
314
diff
changeset
|
36 |
fb3ce83c1a48
download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents:
314
diff
changeset
|
37 |
fb3ce83c1a48
download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents:
314
diff
changeset
|
38 var Downloader = { |
355
e4d31654a9d3
downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents:
350
diff
changeset
|
39 // maximum number of versions to display (0 to display all available) |
356
a71e03f5edde
downloads: only show the last 2 versions of mercurial
David Soria Parra <dsp@php.net>
parents:
355
diff
changeset
|
40 maxversions: 2, |
355
e4d31654a9d3
downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents:
350
diff
changeset
|
41 |
349
fb3ce83c1a48
download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents:
314
diff
changeset
|
42 downloads: [], |
fb3ce83c1a48
download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents:
314
diff
changeset
|
43 |
fb3ce83c1a48
download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents:
314
diff
changeset
|
44 init: function (sources) { |
fb3ce83c1a48
download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents:
314
diff
changeset
|
45 for (i in sources) { |
fb3ce83c1a48
download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents:
314
diff
changeset
|
46 var source = new Download(sources[i]); |
fb3ce83c1a48
download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents:
314
diff
changeset
|
47 this.downloads.push(source); |
fb3ce83c1a48
download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents:
314
diff
changeset
|
48 } |
260
dd7fababf8b6
Working version of the download button with simple OS detection
David Soria Parra <dsp@php.net>
parents:
255
diff
changeset
|
49 }, |
dd7fababf8b6
Working version of the download button with simple OS detection
David Soria Parra <dsp@php.net>
parents:
255
diff
changeset
|
50 |
349
fb3ce83c1a48
download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents:
314
diff
changeset
|
51 select: function () { |
fb3ce83c1a48
download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents:
314
diff
changeset
|
52 var ua = navigator.userAgent; |
fb3ce83c1a48
download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents:
314
diff
changeset
|
53 for (i in this.downloads) { |
fb3ce83c1a48
download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents:
314
diff
changeset
|
54 if (this.downloads[i].matches(ua)) { |
fb3ce83c1a48
download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents:
314
diff
changeset
|
55 return this.downloads[i]; |
fb3ce83c1a48
download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents:
314
diff
changeset
|
56 } |
313
1de4a7a49d94
Link to download page when javascript disabled or OS not detected. (issue2192)
Laurens Holst <laurens.hg@grauw.nl>
parents:
308
diff
changeset
|
57 } |
349
fb3ce83c1a48
download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents:
314
diff
changeset
|
58 return null; |
260
dd7fababf8b6
Working version of the download button with simple OS detection
David Soria Parra <dsp@php.net>
parents:
255
diff
changeset
|
59 }, |
dd7fababf8b6
Working version of the download button with simple OS detection
David Soria Parra <dsp@php.net>
parents:
255
diff
changeset
|
60 |
355
e4d31654a9d3
downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents:
350
diff
changeset
|
61 versions: function () { |
e4d31654a9d3
downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents:
350
diff
changeset
|
62 var uniq = new Object(); |
e4d31654a9d3
downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents:
350
diff
changeset
|
63 for (i in this.downloads) { |
e4d31654a9d3
downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents:
350
diff
changeset
|
64 uniq[this.downloads[i].version] = 1; |
e4d31654a9d3
downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents:
350
diff
changeset
|
65 } |
e4d31654a9d3
downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents:
350
diff
changeset
|
66 var versions = new Array(); |
e4d31654a9d3
downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents:
350
diff
changeset
|
67 for (key in uniq) { |
e4d31654a9d3
downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents:
350
diff
changeset
|
68 versions.push(key); |
e4d31654a9d3
downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents:
350
diff
changeset
|
69 } |
e4d31654a9d3
downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents:
350
diff
changeset
|
70 versions.sort(function (a, b) { |
e4d31654a9d3
downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents:
350
diff
changeset
|
71 a = a.toLowerCase(); |
e4d31654a9d3
downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents:
350
diff
changeset
|
72 b = b.toLowerCase(); |
e4d31654a9d3
downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents:
350
diff
changeset
|
73 return (a < b) - (b < a); |
e4d31654a9d3
downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents:
350
diff
changeset
|
74 }); |
e4d31654a9d3
downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents:
350
diff
changeset
|
75 return versions; |
e4d31654a9d3
downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents:
350
diff
changeset
|
76 }, |
e4d31654a9d3
downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents:
350
diff
changeset
|
77 |
e4d31654a9d3
downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents:
350
diff
changeset
|
78 listall: function (selector) { |
e4d31654a9d3
downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents:
350
diff
changeset
|
79 if (selector == null) |
e4d31654a9d3
downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents:
350
diff
changeset
|
80 selector = function (o) { return true; } |
e4d31654a9d3
downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents:
350
diff
changeset
|
81 |
e4d31654a9d3
downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents:
350
diff
changeset
|
82 // copy the download list, selecting only wanted nodes |
e4d31654a9d3
downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents:
350
diff
changeset
|
83 var downloads = new Array(); |
e4d31654a9d3
downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents:
350
diff
changeset
|
84 for (i in this.downloads) { |
e4d31654a9d3
downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents:
350
diff
changeset
|
85 if (selector(this.downloads[i])) { |
e4d31654a9d3
downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents:
350
diff
changeset
|
86 downloads.push(this.downloads[i]); |
e4d31654a9d3
downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents:
350
diff
changeset
|
87 } |
e4d31654a9d3
downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents:
350
diff
changeset
|
88 } |
e4d31654a9d3
downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents:
350
diff
changeset
|
89 |
349
fb3ce83c1a48
download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents:
314
diff
changeset
|
90 // alpha-sort it by description (case-folded) |
fb3ce83c1a48
download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents:
314
diff
changeset
|
91 downloads.sort(function (a, b) { |
fb3ce83c1a48
download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents:
314
diff
changeset
|
92 a = a.desc.toLowerCase(); |
fb3ce83c1a48
download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents:
314
diff
changeset
|
93 b = b.desc.toLowerCase(); |
fb3ce83c1a48
download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents:
314
diff
changeset
|
94 return (b < a) - (a < b); |
fb3ce83c1a48
download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents:
314
diff
changeset
|
95 }); |
fb3ce83c1a48
download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents:
314
diff
changeset
|
96 |
350
987caba84824
downloads: highlight preferred options with <em>
David Champion <dgc@uchicago.edu>
parents:
349
diff
changeset
|
97 var desc; |
355
e4d31654a9d3
downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents:
350
diff
changeset
|
98 var out = '' |
349
fb3ce83c1a48
download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents:
314
diff
changeset
|
99 for (i in downloads) { |
fb3ce83c1a48
download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents:
314
diff
changeset
|
100 var dl = downloads[i]; |
350
987caba84824
downloads: highlight preferred options with <em>
David Champion <dgc@uchicago.edu>
parents:
349
diff
changeset
|
101 var ua = navigator.userAgent; |
987caba84824
downloads: highlight preferred options with <em>
David Champion <dgc@uchicago.edu>
parents:
349
diff
changeset
|
102 if (dl.matches(ua)) |
987caba84824
downloads: highlight preferred options with <em>
David Champion <dgc@uchicago.edu>
parents:
349
diff
changeset
|
103 desc = '<em>' + dl.desc + '</em>'; |
987caba84824
downloads: highlight preferred options with <em>
David Champion <dgc@uchicago.edu>
parents:
349
diff
changeset
|
104 else |
987caba84824
downloads: highlight preferred options with <em>
David Champion <dgc@uchicago.edu>
parents:
349
diff
changeset
|
105 desc = dl.desc; |
355
e4d31654a9d3
downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents:
350
diff
changeset
|
106 out += '<tr>\n<td>' + desc + '</td>' + |
e4d31654a9d3
downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents:
350
diff
changeset
|
107 '<td></td>' + |
e4d31654a9d3
downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents:
350
diff
changeset
|
108 '<td><a href="' + dl.url + '">download</a></td>' + |
e4d31654a9d3
downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents:
350
diff
changeset
|
109 '</tr>'; |
349
fb3ce83c1a48
download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents:
314
diff
changeset
|
110 } |
355
e4d31654a9d3
downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents:
350
diff
changeset
|
111 return out; |
e4d31654a9d3
downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents:
350
diff
changeset
|
112 }, |
e4d31654a9d3
downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents:
350
diff
changeset
|
113 |
e4d31654a9d3
downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents:
350
diff
changeset
|
114 table: function (name, selector) { |
e4d31654a9d3
downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents:
350
diff
changeset
|
115 var out = ''; |
e4d31654a9d3
downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents:
350
diff
changeset
|
116 out += '<table border="0" cellspacing="0" ' + |
e4d31654a9d3
downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents:
350
diff
changeset
|
117 'cellpadding="0" class="latest" width="100%">\n'; |
e4d31654a9d3
downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents:
350
diff
changeset
|
118 out += '<thead>\n'; |
e4d31654a9d3
downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents:
350
diff
changeset
|
119 out += '<tr>\n'; |
e4d31654a9d3
downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents:
350
diff
changeset
|
120 out += '<th>Mercurial '; |
e4d31654a9d3
downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents:
350
diff
changeset
|
121 out += name; |
e4d31654a9d3
downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents:
350
diff
changeset
|
122 out += '</th>'; |
e4d31654a9d3
downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents:
350
diff
changeset
|
123 out += '<th></th>'; |
e4d31654a9d3
downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents:
350
diff
changeset
|
124 out += '<th></th>'; |
e4d31654a9d3
downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents:
350
diff
changeset
|
125 out += '</tr>'; |
e4d31654a9d3
downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents:
350
diff
changeset
|
126 out += '</thead>'; |
e4d31654a9d3
downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents:
350
diff
changeset
|
127 out += '<tbody>'; |
e4d31654a9d3
downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents:
350
diff
changeset
|
128 out += this.listall(selector); |
e4d31654a9d3
downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents:
350
diff
changeset
|
129 out += '</tbody>'; |
e4d31654a9d3
downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents:
350
diff
changeset
|
130 out += '</table>'; |
e4d31654a9d3
downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents:
350
diff
changeset
|
131 out += '<br/>'; |
e4d31654a9d3
downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents:
350
diff
changeset
|
132 return out; |
260
dd7fababf8b6
Working version of the download button with simple OS detection
David Soria Parra <dsp@php.net>
parents:
255
diff
changeset
|
133 } |
349
fb3ce83c1a48
download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents:
314
diff
changeset
|
134 }; |