comparison static/js/download.js @ 355:e4d31654a9d3

downloads: put each available version into a separate table With this update we generate a separate table on the /downloads page for each version that is represented in sources.js. Downloader.maxversions is the number of versions to display by default; 0 means to display all. If any versions are not displayed by default, a "more versions" label appears. Clicking it reveals the remaining versions.
author David Champion <dgc@uchicago.edu>
date Tue, 23 Nov 2010 09:36:25 -0600
parents 987caba84824
children a71e03f5edde
comparison
equal deleted inserted replaced
354:3e0b0dc69adf 355:e4d31654a9d3
26 } 26 }
27 } 27 }
28 28
29 29
30 var Downloader = { 30 var Downloader = {
31 // maximum number of versions to display (0 to display all available)
32 maxversions: 3,
33
31 downloads: [], 34 downloads: [],
32 35
33 init: function (sources) { 36 init: function (sources) {
34 for (i in sources) { 37 for (i in sources) {
35 var source = new Download(sources[i]); 38 var source = new Download(sources[i]);
45 } 48 }
46 } 49 }
47 return null; 50 return null;
48 }, 51 },
49 52
50 listall: function () { 53 versions: function () {
51 // copy the download list 54 var uniq = new Object();
52 var downloads = this.downloads.slice(0); 55 for (i in this.downloads) {
56 uniq[this.downloads[i].version] = 1;
57 }
58 var versions = new Array();
59 for (key in uniq) {
60 versions.push(key);
61 }
62 versions.sort(function (a, b) {
63 a = a.toLowerCase();
64 b = b.toLowerCase();
65 return (a < b) - (b < a);
66 });
67 return versions;
68 },
69
70 listall: function (selector) {
71 if (selector == null)
72 selector = function (o) { return true; }
73
74 // copy the download list, selecting only wanted nodes
75 var downloads = new Array();
76 for (i in this.downloads) {
77 if (selector(this.downloads[i])) {
78 downloads.push(this.downloads[i]);
79 }
80 }
81
53 // alpha-sort it by description (case-folded) 82 // alpha-sort it by description (case-folded)
54 downloads.sort(function (a, b) { 83 downloads.sort(function (a, b) {
55 a = a.desc.toLowerCase(); 84 a = a.desc.toLowerCase();
56 b = b.desc.toLowerCase(); 85 b = b.desc.toLowerCase();
57 return (b < a) - (a < b); 86 return (b < a) - (a < b);
58 }); 87 });
59 88
60 var desc; 89 var desc;
90 var out = ''
61 for (i in downloads) { 91 for (i in downloads) {
62 var dl = downloads[i]; 92 var dl = downloads[i];
63 var ua = navigator.userAgent; 93 var ua = navigator.userAgent;
64 if (dl.matches(ua)) 94 if (dl.matches(ua))
65 desc = '<em>' + dl.desc + '</em>'; 95 desc = '<em>' + dl.desc + '</em>';
66 else 96 else
67 desc = dl.desc; 97 desc = dl.desc;
68 document.write('<tr>\n<td>' + desc + '</td>' + 98 out += '<tr>\n<td>' + desc + '</td>' +
69 '<td></td>' + 99 '<td></td>' +
70 '<td><a href="' + dl.url + '">download</a></td>' + 100 '<td><a href="' + dl.url + '">download</a></td>' +
71 '</tr>'); 101 '</tr>';
72 } 102 }
103 return out;
104 },
105
106 table: function (name, selector) {
107 var out = '';
108 out += '<table border="0" cellspacing="0" ' +
109 'cellpadding="0" class="latest" width="100%">\n';
110 out += '<thead>\n';
111 out += '<tr>\n';
112 out += '<th>Mercurial ';
113 out += name;
114 out += '</th>';
115 out += '<th></th>';
116 out += '<th></th>';
117 out += '</tr>';
118 out += '</thead>';
119 out += '<tbody>';
120 out += this.listall(selector);
121 out += '</tbody>';
122 out += '</table>';
123 out += '<br/>';
124 return out;
73 } 125 }
74 }; 126 };