Mercurial > hg-website
view 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 |
line wrap: on
line source
function Download (source) { this.version = source[0]; this.regex = source[1]; this.url = source[2]; this.desc = source[3]; } Download.prototype = { matches: function (ua) { if (ua.match(this.regex)) return true; return false; }, download: function () { document.location.href = this.url; return false; }, attr: function (key) { return this[key]; }, write: function (key) { document.write(this[key]); } } var Downloader = { downloads: [], init: function (sources) { for (i in sources) { var source = new Download(sources[i]); this.downloads.push(source); } }, select: function () { var ua = navigator.userAgent; for (i in this.downloads) { if (this.downloads[i].matches(ua)) { return this.downloads[i]; } } return null; }, listall: function () { // copy the download list var downloads = this.downloads.slice(0); // alpha-sort it by description (case-folded) downloads.sort(function (a, b) { a = a.desc.toLowerCase(); b = b.desc.toLowerCase(); return (b < a) - (a < b); }); for (i in downloads) { var dl = downloads[i]; document.write('<tr>\n<td>' + dl.desc + '</td>' + '<td></td>' + '<td><a href="' + dl.url + '">download</a></td>' + '</tr>'); } } };