$(document).ready(function() { /* * The display is not yet object oriented. It's procedural code * broken off into functions. It makes use of libphotofloat's * PhotoFloat class for the network and management logic. * * All of this could potentially be object oriented, but presently * it should be pretty readable and sufficient. The only thing to * perhaps change in the future would be to consolidate calls to * jQuery selectors. And perhaps it'd be nice to move variable * declarations to the top, to stress that JavaScript scope is * for an entire function and always hoisted. * * None of the globals here polutes the global scope, as everything * is enclosed in an anonymous function. * */ /* Globals */ var currentAlbum = null; var currentPhoto = null; var currentPhotoIndex = -1; var previousAlbum = null; var previousPhoto = null; var originalTitle = document.title; var photoFloat = new PhotoFloat(); var maxSize = 1024; /* Displays */ function setTitle() { var title = "", documentTitle = "", last = "", components, i; if (!currentAlbum.path.length) components = [originalTitle]; else { components = currentAlbum.path.split("/"); components.unshift(originalTitle); } if (currentPhoto !== null) documentTitle += photoFloat.trimExtension(currentPhoto.name); for (i = 0; i < components.length; ++i) { if (i || currentPhoto !== null) documentTitle += " \u00ab "; if (i) last += "/" + components[i]; if (i < components.length - 1 || currentPhoto !== null) title += ""; title += components[i]; documentTitle += components[components.length - 1 - i]; if (i < components.length - 1 || currentPhoto !== null) { title += ""; title += " » "; } } if (currentPhoto !== null) title += photoFloat.trimExtension(currentPhoto.name); $("#title").html(title); document.title = documentTitle; } function scrollToThumb() { var photo, thumb; photo = currentPhoto; if (photo === null) { photo = previousPhoto; if (photo === null) return; } $("#thumbs img").each(function() { if (this.photo === photo) { thumb = $(this); return false; } }); if (typeof thumb === "undefined") return; if (currentPhoto !== null) { var scroller = $("#album-view"); scroller.stop().animate({ scrollLeft: thumb.position().left + scroller.scrollLeft() - scroller.width() / 2 + thumb.width() / 2 }, "slow"); } else $("html, body").stop().animate({ scrollTop: thumb.offset().top - $(window).height() / 2 + thumb.height() }, "slow"); if (currentPhoto !== null) { $("#thumbs img").removeClass("current-thumb"); thumb.addClass("current-thumb"); } } function showAlbum(populate) { var i, link, image, photos, thumbsElement, subalbums, subalbumsElement; if (currentPhoto === null && previousPhoto === null) $("html, body").stop().animate({ scrollTop: 0 }, "slow"); if (populate) { photos = []; for (i = 0; i < currentAlbum.photos.length; ++i) { link = $(""); image = $("\"""); if (currentAlbum.photos[i].mediaType == "video") image.css("background-image", "url(" + image.attr("src") + ")").attr("src", "img/video-icon.png"); image.get(0).photo = currentAlbum.photos[i]; link.append(image); photos.push(link); (function(theLink, theImage, theAlbum) { theImage.error(function() { photos.splice(photos.indexOf(theLink), 1); theLink.remove(); theAlbum.photos.splice(theAlbum.photos.indexOf(theImage.get(0).photo), 1); }); })(link, image, currentAlbum); } thumbsElement = $("#thumbs"); thumbsElement.empty(); thumbsElement.append.apply(thumbsElement, photos); subalbums = []; for (i = currentAlbum.albums.length - 1; i >= 0; --i) { link = $(""); image = $("
" + currentAlbum.albums[i].path + "
"); link.append(image); subalbums.push(link); (function(theContainer, theAlbum, theImage, theLink) { photoFloat.albumPhoto(theAlbum, function(album, photo) { theImage.css("background-image", "url(" + photoFloat.photoPath(album, photo, 150, true) + ")"); }, function error() { theContainer.albums.splice(currentAlbum.albums.indexOf(theAlbum), 1); theLink.remove(); subalbums.splice(subalbums.indexOf(theLink), 1); }); })(currentAlbum, currentAlbum.albums[i], image, link); } subalbumsElement = $("#subalbums"); subalbumsElement.empty(); subalbumsElement.append.apply(subalbumsElement, subalbums); if (currentAlbum.albums.length > 1) subalbumsElement.insertBefore(thumbsElement); else thumbsElement.insertBefore(subalbumsElement); } if (currentPhoto === null) { $("#thumbs img").removeClass("current-thumb"); $("#album-view").removeClass("photo-view-container"); $("#subalbums").show(); $("#photo-view").hide(); $("#video-box-inner").empty(); $("#video-box").hide(); } setTimeout(scrollToThumb, 1); } function getDecimal(fraction) { if (fraction[0] < fraction[1]) return fraction[0] + "/" + fraction[1]; return (fraction[0] / fraction[1]).toString(); } function scaleImage() { var image, container; image = $("#photo"); if (image.get(0) === this) $(window).bind("resize", scaleImage); container = $("#photo-view"); if (image.css("width") !== "100%" && container.height() * image.attr("ratio") > container.width()) image.css("width", "100%").css("height", "auto"); else if (image.css("height") !== "100%") image.css("height", "100%").css("width", "auto"); } function scaleVideo() { var video, container; video = $("#video"); if (video.get(0) === this) $(window).bind("resize", scaleVideo); container = $("#photo-view"); if (video.attr("width") > container.width() && container.height() * video.attr("ratio") > container.width()) video.css("width", container.width()).css("height", container.width() / video.attr("ratio")).parent().css("height", container.width() / video.attr("ratio")).css("margin-top", - container.width() / video.attr("ratio") / 2).css("top", "50%"); else if (video.attr("height") > container.height() && container.height() * video.attr("ratio") < container.width()) video.css("height", container.height()).css("width", container.height() * video.attr("ratio")).parent().css("height", "100%").css("margin-top", "0").css("top", "0"); else video.css("height", "").css("width", "").parent().css("height", video.attr("height")).css("margin-top", - video.attr("height") / 2).css("top", "50%"); } function showPhoto() { var width, height, photoSrc, videoSrc, previousPhoto, nextPhoto, nextLink, text; width = currentPhoto.size[0]; height = currentPhoto.size[1]; if (currentPhoto.mediaType == "video") { $("#video-box-inner").empty(); if (!Modernizr.video) { $('

Sorry, your browser doesn\'t support the HTML5 <video> element!

Here\'s a list of which browsers do.

').appendTo('#video-box-inner'); } else if (!Modernizr.video.h264) { $('

Sorry, your browser doesn\'t support the H.264 video format!

').appendTo('#video-box-inner'); } else { $(window).unbind("resize", scaleVideo); $(window).unbind("resize", scaleImage); videoSrc = photoFloat.videoPath(currentAlbum, currentPhoto); $('