From 7566bce8792e8289950c36fac2a0307a70a48959 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Tue, 17 May 2011 23:50:02 -0400 Subject: [PATCH] Pass jshint. --- web/js/011-display.js | 200 +++++++++++++++++++++--------------------- 1 file changed, 100 insertions(+), 100 deletions(-) diff --git a/web/js/011-display.js b/web/js/011-display.js index 3618d7e..013248a 100644 --- a/web/js/011-display.js +++ b/web/js/011-display.js @@ -29,80 +29,86 @@ $(document).ready(function() { var photoFloat = new PhotoFloat(); - /* Entry point for most events */ - - function hashParsed(album, photo, photoIndex) { - undie(); - $("#loading").hide(); - if (album == currentAlbum && photo == currentPhoto) - return; - previousAlbum = currentAlbum; - previousPhoto = currentPhoto; - currentAlbum = album; - currentPhoto = photo; - currentPhotoIndex = photoIndex; - setTitle(); - showAlbum(previousAlbum != currentAlbum); - if (photo != null) - showPhoto(); - } - - /* Displays */ function setTitle() { - var title = ""; - var documentTitle = ""; - var components; - if (currentAlbum.path.length == 0) + var title = "", documentTitle = "", last = "", components, i; + if (!currentAlbum.path.length) components = [originalTitle]; else { components = currentAlbum.path.split("/"); components.unshift(originalTitle); } - if (currentPhoto != null) + if (currentPhoto !== null) documentTitle += photoFloat.trimExtension(currentPhoto.name); - var last = ""; - for (var i = 0; i < components.length; ++i) { - if (i || currentPhoto != null) + 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 += ""; + if (i < components.length - 1 || currentPhoto !== null) + title += ""; title += components[i]; documentTitle += components[components.length - 1 - i]; - if (i < components.length - 1 || currentPhoto != null) { + if (i < components.length - 1 || currentPhoto !== null) { title += ""; title += " » "; } } - if (currentPhoto != null) + 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) { - if (currentPhoto == null && previousPhoto == null) + var i, link, image, photos, thumbsElement, subalbums, subalbumsElement; + if (currentPhoto === null && previousPhoto === null) $("html, body").stop().animate({ scrollTop: 0 }, "slow"); if (populate) { - var photos = []; - for (var i = 0; i < currentAlbum.photos.length; ++i) { - var link = $(""); - var image = $("\"""); + photos = []; + for (i = 0; i < currentAlbum.photos.length; ++i) { + link = $(""); + image = $("\"""); link.append(image); image.get(0).photo = currentAlbum.photos[i]; photos.push(link); } - var thumbsElement = $("#thumbs"); + thumbsElement = $("#thumbs"); thumbsElement.empty(); thumbsElement.append.apply(thumbsElement, photos); - var subalbums = []; - for (var i = currentAlbum.albums.length - 1; i >= 0; --i) { - var link = $(""); - var image = $("
" + currentAlbum.albums[i].path + "
"); + subalbums = []; + for (i = currentAlbum.albums.length - 1; i >= 0; --i) { + link = $(""); + image = $("
" + currentAlbum.albums[i].path + "
"); link.append(image); subalbums.push(link); (function(theAlbum, theImage) { @@ -111,12 +117,12 @@ $(document).ready(function() { }); })(currentAlbum.albums[i], image); } - var subalbumsElement = $("#subalbums"); + subalbumsElement = $("#subalbums"); subalbumsElement.empty(); subalbumsElement.append.apply(subalbumsElement, subalbums); } - if (currentPhoto == null) { + if (currentPhoto === null) { $("#thumbs img").removeClass("current-thumb"); $("#album-view").removeClass("photo-view-container"); $("#subalbums").show(); @@ -130,19 +136,21 @@ $(document).ready(function() { return (fraction[0] / fraction[1]).toString(); } function scaleImage() { - var image = $("#photo"); - if (image.get(0) == this) + var image, container; + image = $("#photo"); + if (image.get(0) === this) $(window).bind("resize", scaleImage); - var container = $("#photo-view"); - if (image.css("width") != "100%" && container.height() * image.width() / image.height() > container.width()) + container = $("#photo-view"); + if (image.css("width") !== "100%" && container.height() * image.width() / image.height() > container.width()) image.css("width", "100%").css("height", "auto").css("position", "absolute").css("bottom", 0); - else if (image.css("height") != "100%") + else if (image.css("height") !== "100%") image.css("height", "100%").css("width", "auto").css("position", "").css("bottom", ""); } function showPhoto() { - var maxSize = 800; - var width = currentPhoto.size[0]; - var height = currentPhoto.size[1]; + var maxSize, width, height, photoSrc, previousPhoto, nextPhoto, nextLink, text; + maxSize = 800; + width = currentPhoto.size[0]; + height = currentPhoto.size[1]; if (width > height) { height = height / width * maxSize; width = maxSize; @@ -151,7 +159,7 @@ $(document).ready(function() { height = maxSize; } $(window).unbind("resize", scaleImage); - var photoSrc = photoFloat.photoPath(currentAlbum, currentPhoto, maxSize, false); + photoSrc = photoFloat.photoPath(currentAlbum, currentPhoto, maxSize, false); $("#photo") .attr("width", width).attr("height", height) .attr("src", photoSrc) @@ -160,34 +168,34 @@ $(document).ready(function() { .load(scaleImage); $("head").append(""); - var previousPhoto = currentAlbum.photos[ + previousPhoto = currentAlbum.photos[ (currentPhotoIndex - 1 < 0) ? (currentAlbum.photos.length - 1) : (currentPhotoIndex - 1) ]; - var nextPhoto = currentAlbum.photos[ + nextPhoto = currentAlbum.photos[ (currentPhotoIndex + 1 >= currentAlbum.photos.length) ? 0 : (currentPhotoIndex + 1) ]; $.preloadImages(photoFloat.photoPath(currentAlbum, nextPhoto, maxSize, false), photoFloat.photoPath(currentAlbum, previousPhoto, maxSize, false)); - var nextLink = "#!/" + photoFloat.photoHash(currentAlbum, nextPhoto); + nextLink = "#!/" + photoFloat.photoHash(currentAlbum, nextPhoto); $("#next-photo").attr("href", nextLink); $("#next").attr("href", nextLink); $("#back").attr("href", "#!/" + photoFloat.photoHash(currentAlbum, previousPhoto)); $("#original-link").attr("target", "_blank").attr("href", photoFloat.originalPhotoPath(currentAlbum, currentPhoto)); - var text = ""; - if (currentPhoto.make != undefined) text += ""; - if (currentPhoto.model != undefined) text += ""; - if (currentPhoto.date != undefined) text += ""; - if (currentPhoto.size != undefined) text += ""; - if (currentPhoto.aperture != undefined) text += ""; - if (currentPhoto.focalLength != undefined) text += ""; - if (currentPhoto.iso != undefined) text += ""; - if (currentPhoto.exposureTime != undefined) text += ""; - if (currentPhoto.exposureProgram != undefined) text += ""; - if (currentPhoto.exposureCompensation != undefined) text += ""; - if (currentPhoto.spectralSensitivity != undefined) text += ""; - if (currentPhoto.flash != undefined) text += ""; - if (currentPhoto.orientation != undefined) text += ""; + text = "
Camera Maker" + currentPhoto.make + "
Camera Model" + currentPhoto.model + "
Time Taken" + currentPhoto.date + "
Resolution" + currentPhoto.size[0] + " x " + currentPhoto.size[1] + "
Aperture f/" + getDecimal(currentPhoto.aperture) + "
Focal Length" + getDecimal(currentPhoto.focalLength) + " mm
ISO" + currentPhoto.iso + "
Exposure Time" + getDecimal(currentPhoto.exposureTime) + " sec
Exposure Program" + currentPhoto.exposureProgram + "
Exposure Compensation" + getDecimal(currentPhoto.exposureCompensation) + "
Spectral Sensitivity" + currentPhoto.spectralSensitivity + "
Flash" + currentPhoto.flash + "
Orientation" + currentPhoto.orientation + "
"; + if (typeof currentPhoto.make !== "undefined") text += ""; + if (typeof currentPhoto.model !== "undefined") text += ""; + if (typeof currentPhoto.date !== "undefined") text += ""; + if (typeof currentPhoto.size !== "undefined") text += ""; + if (typeof currentPhoto.aperture !== "undefined") text += ""; + if (typeof currentPhoto.focalLength !== "undefined") text += ""; + if (typeof currentPhoto.iso !== "undefined") text += ""; + if (typeof currentPhoto.exposureTime !== "undefined") text += ""; + if (typeof currentPhoto.exposureProgram !== "undefined") text += ""; + if (typeof currentPhoto.exposureCompensation !== "undefined") text += ""; + if (typeof currentPhoto.spectralSensitivity !== "undefined") text += ""; + if (typeof currentPhoto.flash !== "undefined") text += ""; + if (typeof currentPhoto.orientation !== "undefined") text += ""; text += "
Camera Maker" + currentPhoto.make + "
Camera Model" + currentPhoto.model + "
Time Taken" + currentPhoto.date + "
Resolution" + currentPhoto.size[0] + " x " + currentPhoto.size[1] + "
Aperture f/" + getDecimal(currentPhoto.aperture) + "
Focal Length" + getDecimal(currentPhoto.focalLength) + " mm
ISO" + currentPhoto.iso + "
Exposure Time" + getDecimal(currentPhoto.exposureTime) + " sec
Exposure Program" + currentPhoto.exposureProgram + "
Exposure Compensation" + getDecimal(currentPhoto.exposureCompensation) + "
Spectral Sensitivity" + currentPhoto.spectralSensitivity + "
Flash" + currentPhoto.flash + "
Orientation" + currentPhoto.orientation + "
"; $("#metadata").html(text); @@ -195,33 +203,6 @@ $(document).ready(function() { $("#subalbums").hide(); $("#photo-view").show(); } - function scrollToThumb() { - var photo = currentPhoto - if (photo == null) { - photo = previousPhoto; - if (photo == null) - return; - } - var thumb; - $("#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"); - } - } /* Error displays */ @@ -235,7 +216,26 @@ $(document).ready(function() { $("#error-text, #error-overlay").fadeOut(500); $("body, html").css("overflow", "auto"); } + + + /* Entry point for most events */ + + function hashParsed(album, photo, photoIndex) { + undie(); + $("#loading").hide(); + if (album === currentAlbum && photo === currentPhoto) + return; + previousAlbum = currentAlbum; + previousPhoto = currentPhoto; + currentAlbum = album; + currentPhoto = photo; + currentPhotoIndex = photoIndex; + setTitle(); + showAlbum(previousAlbum !== currentAlbum); + if (photo !== null) + showPhoto(); + } /* Event listeners */ @@ -246,19 +246,19 @@ $(document).ready(function() { }); $(window).hashchange(); $(document).keydown(function(e){ - if (currentPhoto == null) + if (currentPhoto === null) return true; - if (e.keyCode == 39) { + if (e.keyCode === 39) { window.location.href = $("#next").attr("href"); return false; - } else if (e.keyCode == 37) { + } else if (e.keyCode === 37) { window.location.href = $("#back").attr("href"); return false; } return true; }); $(document).mousewheel(function(event, delta) { - if (currentPhoto == null) + if (currentPhoto === null) return true; if (delta < 0) { window.location.href = $("#next").attr("href");