Delay the generation of the button script, so it gets the right download url.

This commit is contained in:
Eli Barzilay 2010-07-04 15:44:52 -04:00
parent bb6a109e98
commit 5b6b3f3bac

View File

@ -9,33 +9,34 @@
#:file "download/" #:part-of 'download]{
@(render-download-page)})
(define download-button
(let ([img1 (copyfile (in-here "download.png"))]
[img2 (copyfile (in-here "download-dark.png"))])
@list{
@script/inline[type: "text/javascript"]{
@; Don't load all images here -- it causes a delay when loading the
@; page instead, do it only when needed, and also set a timer to do it
@; after loading the page. This makes it so that there's almost never
@; a delay when loading the page, and also no delay when switching the
@; image.
var rollovers = false, the_download_button = false;
function init_rollovers() {
if (!rollovers) {
rollovers = [ new Image(), new Image() ];
rollovers[0].src = "@img1";
rollovers[1].src = "@img2";
the_download_button = document.getElementById("download_button");
}
(define images (list (copyfile (in-here "download.png"))
(copyfile (in-here "download-dark.png"))))
(define (download-button)
@text{
@script/inline[type: "text/javascript"]{
@; Don't load all images here -- it causes a delay when loading the
@; page instead, do it only when needed, and also set a timer to do it
@; after loading the page. This makes it so that there's almost never
@; a delay when loading the page, and also no delay when switching the
@; image.
var rollovers = false, the_download_button = false;
function init_rollovers() {
if (!rollovers) {
rollovers = [ new Image(), new Image() ];
rollovers[0].src = "@(car images)";
rollovers[1].src = "@(cadr images)";
the_download_button = document.getElementById("download_button");
}
function set_download_image(n) {
if (!rollovers) init_rollovers();
the_download_button.src = rollovers[n].src;
}
setTimeout(init_rollovers, 400);
}
@a[href: "download/"
onmouseover: "set_download_image(1);"
onmouseout: "set_download_image(0);"]{
@img[id: "download_button" src: img1 style: "border-width: 0;"
alt: "Download Racket" title: "Download Racket"]}}))
function set_download_image(n) {
if (!rollovers) init_rollovers();
the_download_button.src = rollovers[n].src;
}
setTimeout(init_rollovers, 400);
}
@a[href: (get-resource-path download)
onmouseover: "set_download_image(1);"
onmouseout: "set_download_image(0);"]{
@img[id: "download_button" src: (car images) style: "border-width: 0;"
alt: "Download Racket" title: "Download Racket"]}})