comparison static/js/download.js @ 349:fb3ce83c1a48

download: use sources.js instead of jinja static templates See http://mercurial.selenic.com/wiki/BinaryReleasePlan 1. [hg-website] update the main page (templates/base.html and static/js/download.js) to use sources.js as a dynamic binary release information source instead of using a jinja template maintained as part of the web site. templates/data no longer required; removed. 2. [hg-website-content] update the /downloads page use the sources.js information also. This changes some of the detection and package naming, naturally, but that likely must be addressed in latest.dat files or in the protocol for creating sources.js.
author David Champion <dgc@uchicago.edu>
date Sat, 20 Nov 2010 19:53:07 -0600
parents 657b465caaa2
children 987caba84824
comparison
equal deleted inserted replaced
348:7cb309f3e33a 349:fb3ce83c1a48
1 function Download() { 1 function Download (source) {
2 this.downloads = {}; 2 this.version = source[0];
3 this.regex = source[1];
4 this.url = source[2];
5 this.desc = source[3];
3 } 6 }
4 7
5 Download.prototype = { 8 Download.prototype = {
9 matches: function (ua) {
10 if (ua.match(this.regex))
11 return true;
12 return false;
13 },
6 14
7 parse_os: function() { 15 download: function () {
8 var OSName="Source code"; 16 document.location.href = this.url;
9 if (navigator.appVersion.indexOf("Win")!=-1) OSName="Windows"; 17 return false;
10 if (navigator.appVersion.indexOf("Mac")!=-1) { 18 },
11 if (navigator.userAgent.indexOf("10.6")!=-1 || /* firefox */ 19
12 navigator.userAgent.indexOf("10_6") !=-1) { /* chrome */ 20 attr: function (key) {
13 OSName="Mac OS X 10.6"; 21 return this[key];
14 } else { 22 },
15 OSName="Mac OS X 10.5"; 23
24 write: function (key) {
25 document.write(this[key]);
26 }
27 }
28
29
30 var Downloader = {
31 downloads: [],
32
33 init: function (sources) {
34 for (i in sources) {
35 var source = new Download(sources[i]);
36 this.downloads.push(source);
37 }
38 },
39
40 select: function () {
41 var ua = navigator.userAgent;
42 for (i in this.downloads) {
43 if (this.downloads[i].matches(ua)) {
44 return this.downloads[i];
16 } 45 }
17 } 46 }
18 if (navigator.appVersion.indexOf("X11")!=-1) OSName="UNIX"; 47 return null;
19 if (navigator.appVersion.indexOf("Linux")!=-1) OSName="Linux";
20
21 return OSName;
22 }, 48 },
23 49
24 os_detection: function() { 50 listall: function () {
25 document.write(this.parse_os()); 51 // copy the download list
26 }, 52 var downloads = this.downloads.slice(0);
53 // alpha-sort it by description (case-folded)
54 downloads.sort(function (a, b) {
55 a = a.desc.toLowerCase();
56 b = b.desc.toLowerCase();
57 return (b < a) - (a < b);
58 });
27 59
28 os_link: function() { 60 for (i in downloads) {
29 var os = this.parse_os(); 61 var dl = downloads[i];
30 if (this.downloads[os]) { 62 document.write('<tr>\n<td>' + dl.desc + '</td>' +
31 document.location.href = this.downloads[os]; 63 '<td></td>' +
32 return false; 64 '<td><a href="' + dl.url + '">download</a></td>' +
65 '</tr>');
33 } 66 }
34 return true;
35 },
36
37 register_download:function(type, url) {
38 this.downloads[type] = url;
39 } 67 }
40 } 68 };