[PATCH 1 of 1 hg-website] downloads: put each available version into a separate table
David Champion
dgc at uchicago.edu
Tue Nov 23 11:16:35 CST 2010
# HG changeset patch
# User David Champion <dgc at uchicago.edu>
# Date 1290526585 21600
# Node ID 2bc5d025678014accd270afa547982d9674d3ec4
# Parent a6c7665d9f67a4d704ec14b9b2f6f7a4ee413d0d
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.
diff -r a6c7665d9f67 -r 2bc5d0256780 static/css/styles.css
--- a/static/css/styles.css Mon Nov 22 20:10:42 2010 +0100
+++ b/static/css/styles.css Tue Nov 23 09:36:25 2010 -0600
@@ -67,6 +67,12 @@
thead td, thead th { background: #999; color: #fff; font-weight: bold; }
tbody td { border-bottom: 1px solid #ccc; }
tbody td em { font-style: normal; font-weight: bolder; }
+tbody td:last-child { width: 5em; }
+
+/*
+ * Table expansion
+ */
+div #more { font-size: smaller; color: #999; }
/*
* Quotes
diff -r a6c7665d9f67 -r 2bc5d0256780 static/js/download.js
--- a/static/js/download.js Mon Nov 22 20:10:42 2010 +0100
+++ b/static/js/download.js Tue Nov 23 09:36:25 2010 -0600
@@ -28,6 +28,9 @@
var Downloader = {
+ // maximum number of versions to display (0 to display all available)
+ maxversions: 3,
+
downloads: [],
init: function (sources) {
@@ -47,9 +50,35 @@
return null;
},
- listall: function () {
- // copy the download list
- var downloads = this.downloads.slice(0);
+ versions: function () {
+ var uniq = new Object();
+ for (i in this.downloads) {
+ uniq[this.downloads[i].version] = 1;
+ }
+ var versions = new Array();
+ for (key in uniq) {
+ versions.push(key);
+ }
+ versions.sort(function (a, b) {
+ a = a.toLowerCase();
+ b = b.toLowerCase();
+ return (a < b) - (b < a);
+ });
+ return versions;
+ },
+
+ listall: function (selector) {
+ if (selector == null)
+ selector = function (o) { return true; }
+
+ // copy the download list, selecting only wanted nodes
+ var downloads = new Array();
+ for (i in this.downloads) {
+ if (selector(this.downloads[i])) {
+ downloads.push(this.downloads[i]);
+ }
+ }
+
// alpha-sort it by description (case-folded)
downloads.sort(function (a, b) {
a = a.desc.toLowerCase();
@@ -58,6 +87,7 @@
});
var desc;
+ var out = ''
for (i in downloads) {
var dl = downloads[i];
var ua = navigator.userAgent;
@@ -65,10 +95,32 @@
desc = '<em>' + dl.desc + '</em>';
else
desc = dl.desc;
- document.write('<tr>\n<td>' + desc + '</td>' +
- '<td></td>' +
- '<td><a href="' + dl.url + '">download</a></td>' +
- '</tr>');
+ out += '<tr>\n<td>' + desc + '</td>' +
+ '<td></td>' +
+ '<td><a href="' + dl.url + '">download</a></td>' +
+ '</tr>';
}
+ return out;
+ },
+
+ table: function (name, selector) {
+ var out = '';
+ out += '<table border="0" cellspacing="0" ' +
+ 'cellpadding="0" class="latest" width="100%">\n';
+ out += '<thead>\n';
+ out += '<tr>\n';
+ out += '<th>Mercurial ';
+ out += name;
+ out += '</th>';
+ out += '<th></th>';
+ out += '<th></th>';
+ out += '</tr>';
+ out += '</thead>';
+ out += '<tbody>';
+ out += this.listall(selector);
+ out += '</tbody>';
+ out += '</table>';
+ out += '<br/>';
+ return out;
}
};
More information about the Mercurial-devel
mailing list