Commits

php committed dd7faba

Working version of the download button with simple OS detection

Comments (0)

Files changed (5)

-6293e2d423105e6abe6a21f81d3ab67616ea2096 content
+a65bad2173f210d817556679c0dfc8ae93c95f66 content

static/javascript/download.js

-function os_detection() {
-    var OSName="Source";
-    if (navigator.appVersion.indexOf("Win")!=-1) OSName="Windows";
-    if (navigator.appVersion.indexOf("Mac")!=-1) OSName="Mac OS X";
-    if (navigator.appVersion.indexOf("X11")!=-1) OSName="UNIX";
-    if (navigator.appVersion.indexOf("Linux")!=-1) OSName="Linux";
-
-    document.write(OSName);
+function Download() {
+    this.downloads = new Array();
 }
 
+Download.prototype = {
+
+    parse_os: function() {
+        var OSName="Source code";
+        if (navigator.appVersion.indexOf("Win")!=-1) OSName="Windows";
+        if (navigator.appVersion.indexOf("Mac")!=-1) OSName="Mac OS X";
+        if (navigator.appVersion.indexOf("X11")!=-1) OSName="UNIX";
+        if (navigator.appVersion.indexOf("Linux")!=-1) OSName="Linux";
+
+        return OSName;
+    },
+
+    os_detection: function() {
+        document.write(this.parse_os());
+    },
+
+    os_link: function() {
+        document.location.href = this.downloads[this.parse_os()];
+    },
+
+    register_download:function(type, url) {
+        this.downloads[type] = url;
+    }
+}

templates/base.html

         <script type="text/javascript" src="/javascript/typeface.js"></script>
         <script type="text/javascript" src="/javascript/optimer_regular.typeface.js"></script>
         <script type="text/javascript" src="/javascript/download.js"></script>
+        <script language="javascript" type="text/javascript">
+        {% set download = downloads[downloads['current']] %}
+         var dl = new Download();
+         dl.register_download('Windows', "{{ download['Windows']}}");
+         dl.register_download('Mac OS X', "{{ download['Mac OS X 10.6']}}");
+         dl.register_download('UNIX', "{{ download['Source code']}}");
+         dl.register_download('Linux', "{{ download['Source code']}}");
+        </script>
         <link rel="shortcut icon" type="image/x-icon" href="/images/favicon.ico">
 
         <title>Mercurial SCM</title>
                     </div>
                     <div class="col">
                         {% block sidebar %}
-                        <a class="download typeface-js" href="/downloads">
+                        <a class="download typeface-js" href="#" onClick="javascript:dl.os_link()">
                                     <strong>Download now</strong>
                                     Mercurial <em>1.3.1</em>
-                                    <span><script language="javascript">os_detection();</script></span>
+                                    <span><script language="javascript">dl.os_detection();</script></span>
                         </a>
                         <dl>
                             <dt class="typeface-js">Requirements</dt>
-{% set downloads = {'1.3.1': {'windows': 'linkwin', 'os.x': 'linkosx'}} %}
+{% set downloads = {
+    'current': '1.3.1',
+    '1.3.1': {
+        'Windows (Tortoise HG)': 'http://bitbucket.org/tortoisehg/stable/downloads/TortoiseHg-0.8.1-hg-1.3.1.exe',
+        'Windows': 'http://mercurial.berkwood.com/binaries/Mercurial-1.3.1.exe',
+        'Mac OS X 10.6': 'http://mercurial.berkwood.com/binaries/Mercurial-1.3.1-py2.6-macosx10.6.zip',
+        'Mac OS X 10.5': 'http://mercurial.berkwood.com/binaries/Mercurial-1.3.1-py2.5-macosx10.5.zip',
+        'Source code': 'http://www.selenic.com/mercurial/release/mercurial-1.3.1.tar.gz'}}
+%}

templates/frontpage.html

         </ol>
     </div>
     <div class="col">
-        <h3>Download</h3>
-        {% for version in downloads %}
-            <h4><strong>{{ version }}</strong></h4>
-            <ul>
-                {% for os in downloads[version] %}
-                    <li>{{ os }}: {{ downloads[version][os] }}</li>
-                {% endfor %}
-            </ul>
-            
-        {% endfor %}
-        
         <h3>Quick Start</h3>
 
         <p><em>Clone a project and create a patch</em>
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.