annotate static/js/download.js @ 356:a71e03f5edde

downloads: only show the last 2 versions of mercurial
author David Soria Parra <dsp@php.net>
date Mon, 29 Nov 2010 10:49:49 +0100
parents e4d31654a9d3
children 8e3b10220bb9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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];
255
4a52186008ee Add a first version of the sidebar
David Soria Parra <dsp@php.net>
parents:
diff changeset
6 }
4a52186008ee Add a first version of the sidebar
David Soria Parra <dsp@php.net>
parents:
diff changeset
7
260
dd7fababf8b6 Working version of the download button with simple OS detection
David Soria Parra <dsp@php.net>
parents: 255
diff changeset
8 Download.prototype = {
349
fb3ce83c1a48 download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents: 314
diff changeset
9 matches: function (ua) {
fb3ce83c1a48 download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents: 314
diff changeset
10 if (ua.match(this.regex))
fb3ce83c1a48 download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents: 314
diff changeset
11 return true;
fb3ce83c1a48 download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents: 314
diff changeset
12 return false;
fb3ce83c1a48 download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents: 314
diff changeset
13 },
260
dd7fababf8b6 Working version of the download button with simple OS detection
David Soria Parra <dsp@php.net>
parents: 255
diff changeset
14
349
fb3ce83c1a48 download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents: 314
diff changeset
15 download: function () {
fb3ce83c1a48 download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents: 314
diff changeset
16 document.location.href = this.url;
fb3ce83c1a48 download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents: 314
diff changeset
17 return false;
fb3ce83c1a48 download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents: 314
diff changeset
18 },
260
dd7fababf8b6 Working version of the download button with simple OS detection
David Soria Parra <dsp@php.net>
parents: 255
diff changeset
19
349
fb3ce83c1a48 download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents: 314
diff changeset
20 attr: function (key) {
fb3ce83c1a48 download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents: 314
diff changeset
21 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
22 },
dd7fababf8b6 Working version of the download button with simple OS detection
David Soria Parra <dsp@php.net>
parents: 255
diff changeset
23
349
fb3ce83c1a48 download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents: 314
diff changeset
24 write: function (key) {
fb3ce83c1a48 download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents: 314
diff changeset
25 document.write(this[key]);
fb3ce83c1a48 download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents: 314
diff changeset
26 }
fb3ce83c1a48 download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents: 314
diff changeset
27 }
fb3ce83c1a48 download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents: 314
diff changeset
28
fb3ce83c1a48 download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents: 314
diff changeset
29
fb3ce83c1a48 download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents: 314
diff changeset
30 var Downloader = {
355
e4d31654a9d3 downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents: 350
diff changeset
31 // 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
32 maxversions: 2,
355
e4d31654a9d3 downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents: 350
diff changeset
33
349
fb3ce83c1a48 download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents: 314
diff changeset
34 downloads: [],
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 init: function (sources) {
fb3ce83c1a48 download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents: 314
diff changeset
37 for (i in sources) {
fb3ce83c1a48 download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents: 314
diff changeset
38 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
39 this.downloads.push(source);
fb3ce83c1a48 download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents: 314
diff changeset
40 }
260
dd7fababf8b6 Working version of the download button with simple OS detection
David Soria Parra <dsp@php.net>
parents: 255
diff changeset
41 },
dd7fababf8b6 Working version of the download button with simple OS detection
David Soria Parra <dsp@php.net>
parents: 255
diff changeset
42
349
fb3ce83c1a48 download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents: 314
diff changeset
43 select: function () {
fb3ce83c1a48 download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents: 314
diff changeset
44 var ua = navigator.userAgent;
fb3ce83c1a48 download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents: 314
diff changeset
45 for (i in this.downloads) {
fb3ce83c1a48 download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents: 314
diff changeset
46 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
47 return this.downloads[i];
fb3ce83c1a48 download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents: 314
diff changeset
48 }
313
1de4a7a49d94 Link to download page when javascript disabled or OS not detected. (issue2192)
Laurens Holst <laurens.hg@grauw.nl>
parents: 308
diff changeset
49 }
349
fb3ce83c1a48 download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents: 314
diff changeset
50 return null;
260
dd7fababf8b6 Working version of the download button with simple OS detection
David Soria Parra <dsp@php.net>
parents: 255
diff changeset
51 },
dd7fababf8b6 Working version of the download button with simple OS detection
David Soria Parra <dsp@php.net>
parents: 255
diff changeset
52
355
e4d31654a9d3 downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents: 350
diff changeset
53 versions: function () {
e4d31654a9d3 downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents: 350
diff changeset
54 var uniq = new Object();
e4d31654a9d3 downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents: 350
diff changeset
55 for (i in this.downloads) {
e4d31654a9d3 downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents: 350
diff changeset
56 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
57 }
e4d31654a9d3 downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents: 350
diff changeset
58 var versions = new Array();
e4d31654a9d3 downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents: 350
diff changeset
59 for (key in uniq) {
e4d31654a9d3 downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents: 350
diff changeset
60 versions.push(key);
e4d31654a9d3 downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents: 350
diff changeset
61 }
e4d31654a9d3 downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents: 350
diff changeset
62 versions.sort(function (a, b) {
e4d31654a9d3 downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents: 350
diff changeset
63 a = a.toLowerCase();
e4d31654a9d3 downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents: 350
diff changeset
64 b = b.toLowerCase();
e4d31654a9d3 downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents: 350
diff changeset
65 return (a < b) - (b < a);
e4d31654a9d3 downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents: 350
diff changeset
66 });
e4d31654a9d3 downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents: 350
diff changeset
67 return versions;
e4d31654a9d3 downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents: 350
diff changeset
68 },
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 listall: function (selector) {
e4d31654a9d3 downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents: 350
diff changeset
71 if (selector == null)
e4d31654a9d3 downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents: 350
diff changeset
72 selector = function (o) { return true; }
e4d31654a9d3 downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents: 350
diff changeset
73
e4d31654a9d3 downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents: 350
diff changeset
74 // 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
75 var downloads = new Array();
e4d31654a9d3 downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents: 350
diff changeset
76 for (i in this.downloads) {
e4d31654a9d3 downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents: 350
diff changeset
77 if (selector(this.downloads[i])) {
e4d31654a9d3 downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents: 350
diff changeset
78 downloads.push(this.downloads[i]);
e4d31654a9d3 downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents: 350
diff changeset
79 }
e4d31654a9d3 downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents: 350
diff changeset
80 }
e4d31654a9d3 downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents: 350
diff changeset
81
349
fb3ce83c1a48 download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents: 314
diff changeset
82 // 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
83 downloads.sort(function (a, b) {
fb3ce83c1a48 download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents: 314
diff changeset
84 a = a.desc.toLowerCase();
fb3ce83c1a48 download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents: 314
diff changeset
85 b = b.desc.toLowerCase();
fb3ce83c1a48 download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents: 314
diff changeset
86 return (b < a) - (a < b);
fb3ce83c1a48 download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents: 314
diff changeset
87 });
fb3ce83c1a48 download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents: 314
diff changeset
88
350
987caba84824 downloads: highlight preferred options with <em>
David Champion <dgc@uchicago.edu>
parents: 349
diff changeset
89 var desc;
355
e4d31654a9d3 downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents: 350
diff changeset
90 var out = ''
349
fb3ce83c1a48 download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents: 314
diff changeset
91 for (i in downloads) {
fb3ce83c1a48 download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents: 314
diff changeset
92 var dl = downloads[i];
350
987caba84824 downloads: highlight preferred options with <em>
David Champion <dgc@uchicago.edu>
parents: 349
diff changeset
93 var ua = navigator.userAgent;
987caba84824 downloads: highlight preferred options with <em>
David Champion <dgc@uchicago.edu>
parents: 349
diff changeset
94 if (dl.matches(ua))
987caba84824 downloads: highlight preferred options with <em>
David Champion <dgc@uchicago.edu>
parents: 349
diff changeset
95 desc = '<em>' + dl.desc + '</em>';
987caba84824 downloads: highlight preferred options with <em>
David Champion <dgc@uchicago.edu>
parents: 349
diff changeset
96 else
987caba84824 downloads: highlight preferred options with <em>
David Champion <dgc@uchicago.edu>
parents: 349
diff changeset
97 desc = dl.desc;
355
e4d31654a9d3 downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents: 350
diff changeset
98 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
99 '<td></td>' +
e4d31654a9d3 downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents: 350
diff changeset
100 '<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
101 '</tr>';
349
fb3ce83c1a48 download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents: 314
diff changeset
102 }
355
e4d31654a9d3 downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents: 350
diff changeset
103 return out;
e4d31654a9d3 downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents: 350
diff changeset
104 },
e4d31654a9d3 downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents: 350
diff changeset
105
e4d31654a9d3 downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents: 350
diff changeset
106 table: function (name, selector) {
e4d31654a9d3 downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents: 350
diff changeset
107 var out = '';
e4d31654a9d3 downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents: 350
diff changeset
108 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
109 '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
110 out += '<thead>\n';
e4d31654a9d3 downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents: 350
diff changeset
111 out += '<tr>\n';
e4d31654a9d3 downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents: 350
diff changeset
112 out += '<th>Mercurial ';
e4d31654a9d3 downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents: 350
diff changeset
113 out += name;
e4d31654a9d3 downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents: 350
diff changeset
114 out += '</th>';
e4d31654a9d3 downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents: 350
diff changeset
115 out += '<th></th>';
e4d31654a9d3 downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents: 350
diff changeset
116 out += '<th></th>';
e4d31654a9d3 downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents: 350
diff changeset
117 out += '</tr>';
e4d31654a9d3 downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents: 350
diff changeset
118 out += '</thead>';
e4d31654a9d3 downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents: 350
diff changeset
119 out += '<tbody>';
e4d31654a9d3 downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents: 350
diff changeset
120 out += this.listall(selector);
e4d31654a9d3 downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents: 350
diff changeset
121 out += '</tbody>';
e4d31654a9d3 downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents: 350
diff changeset
122 out += '</table>';
e4d31654a9d3 downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents: 350
diff changeset
123 out += '<br/>';
e4d31654a9d3 downloads: put each available version into a separate table
David Champion <dgc@uchicago.edu>
parents: 350
diff changeset
124 return out;
260
dd7fababf8b6 Working version of the download button with simple OS detection
David Soria Parra <dsp@php.net>
parents: 255
diff changeset
125 }
349
fb3ce83c1a48 download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents: 314
diff changeset
126 };