Mercurial > hg-website
annotate static/js/download.js @ 350:987caba84824
downloads: highlight preferred options with <em>
author | David Champion <dgc@uchicago.edu> |
---|---|
date | Sun, 21 Nov 2010 01:26:01 -0600 |
parents | fb3ce83c1a48 |
children | e4d31654a9d3 |
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 = { |
fb3ce83c1a48
download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents:
314
diff
changeset
|
31 downloads: [], |
fb3ce83c1a48
download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents:
314
diff
changeset
|
32 |
fb3ce83c1a48
download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents:
314
diff
changeset
|
33 init: function (sources) { |
fb3ce83c1a48
download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents:
314
diff
changeset
|
34 for (i in sources) { |
fb3ce83c1a48
download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents:
314
diff
changeset
|
35 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
|
36 this.downloads.push(source); |
fb3ce83c1a48
download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents:
314
diff
changeset
|
37 } |
260
dd7fababf8b6
Working version of the download button with simple OS detection
David Soria Parra <dsp@php.net>
parents:
255
diff
changeset
|
38 }, |
dd7fababf8b6
Working version of the download button with simple OS detection
David Soria Parra <dsp@php.net>
parents:
255
diff
changeset
|
39 |
349
fb3ce83c1a48
download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents:
314
diff
changeset
|
40 select: function () { |
fb3ce83c1a48
download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents:
314
diff
changeset
|
41 var ua = navigator.userAgent; |
fb3ce83c1a48
download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents:
314
diff
changeset
|
42 for (i in this.downloads) { |
fb3ce83c1a48
download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents:
314
diff
changeset
|
43 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
|
44 return this.downloads[i]; |
fb3ce83c1a48
download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents:
314
diff
changeset
|
45 } |
313
1de4a7a49d94
Link to download page when javascript disabled or OS not detected. (issue2192)
Laurens Holst <laurens.hg@grauw.nl>
parents:
308
diff
changeset
|
46 } |
349
fb3ce83c1a48
download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents:
314
diff
changeset
|
47 return null; |
260
dd7fababf8b6
Working version of the download button with simple OS detection
David Soria Parra <dsp@php.net>
parents:
255
diff
changeset
|
48 }, |
dd7fababf8b6
Working version of the download button with simple OS detection
David Soria Parra <dsp@php.net>
parents:
255
diff
changeset
|
49 |
349
fb3ce83c1a48
download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents:
314
diff
changeset
|
50 listall: function () { |
fb3ce83c1a48
download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents:
314
diff
changeset
|
51 // copy the download list |
fb3ce83c1a48
download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents:
314
diff
changeset
|
52 var downloads = this.downloads.slice(0); |
fb3ce83c1a48
download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents:
314
diff
changeset
|
53 // 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
|
54 downloads.sort(function (a, b) { |
fb3ce83c1a48
download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents:
314
diff
changeset
|
55 a = a.desc.toLowerCase(); |
fb3ce83c1a48
download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents:
314
diff
changeset
|
56 b = b.desc.toLowerCase(); |
fb3ce83c1a48
download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents:
314
diff
changeset
|
57 return (b < a) - (a < b); |
fb3ce83c1a48
download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents:
314
diff
changeset
|
58 }); |
fb3ce83c1a48
download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents:
314
diff
changeset
|
59 |
350
987caba84824
downloads: highlight preferred options with <em>
David Champion <dgc@uchicago.edu>
parents:
349
diff
changeset
|
60 var desc; |
349
fb3ce83c1a48
download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents:
314
diff
changeset
|
61 for (i in downloads) { |
fb3ce83c1a48
download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents:
314
diff
changeset
|
62 var dl = downloads[i]; |
350
987caba84824
downloads: highlight preferred options with <em>
David Champion <dgc@uchicago.edu>
parents:
349
diff
changeset
|
63 var ua = navigator.userAgent; |
987caba84824
downloads: highlight preferred options with <em>
David Champion <dgc@uchicago.edu>
parents:
349
diff
changeset
|
64 if (dl.matches(ua)) |
987caba84824
downloads: highlight preferred options with <em>
David Champion <dgc@uchicago.edu>
parents:
349
diff
changeset
|
65 desc = '<em>' + dl.desc + '</em>'; |
987caba84824
downloads: highlight preferred options with <em>
David Champion <dgc@uchicago.edu>
parents:
349
diff
changeset
|
66 else |
987caba84824
downloads: highlight preferred options with <em>
David Champion <dgc@uchicago.edu>
parents:
349
diff
changeset
|
67 desc = dl.desc; |
987caba84824
downloads: highlight preferred options with <em>
David Champion <dgc@uchicago.edu>
parents:
349
diff
changeset
|
68 document.write('<tr>\n<td>' + desc + '</td>' + |
349
fb3ce83c1a48
download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents:
314
diff
changeset
|
69 '<td></td>' + |
fb3ce83c1a48
download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents:
314
diff
changeset
|
70 '<td><a href="' + dl.url + '">download</a></td>' + |
fb3ce83c1a48
download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents:
314
diff
changeset
|
71 '</tr>'); |
fb3ce83c1a48
download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents:
314
diff
changeset
|
72 } |
260
dd7fababf8b6
Working version of the download button with simple OS detection
David Soria Parra <dsp@php.net>
parents:
255
diff
changeset
|
73 } |
349
fb3ce83c1a48
download: use sources.js instead of jinja static templates
David Champion <dgc@uchicago.edu>
parents:
314
diff
changeset
|
74 }; |