Take out scaling function to its own.

This commit is contained in:
Jason A. Donenfeld 2011-05-09 04:11:31 -04:00
parent e5f9ec18ea
commit 4a7d7ad39f

View File

@ -128,6 +128,16 @@ $(document).ready(function() {
return fraction[0] + "/" + fraction[1]; return fraction[0] + "/" + fraction[1];
return (fraction[0] / fraction[1]).toString(); return (fraction[0] / fraction[1]).toString();
} }
function scaleImage() {
var 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())
image.css("width", "100%").css("height", "auto");
else if (image.css("height") != "100%")
image.css("height", "100%").css("width", "auto");
}
function showPhoto() { function showPhoto() {
currentPhoto(); currentPhoto();
if (current_photo == null) { if (current_photo == null) {
@ -144,12 +154,13 @@ $(document).ready(function() {
width = width / height * maxSize; width = width / height * maxSize;
height = maxSize; height = maxSize;
} }
$(window).unbind("resize", scaleImage);
$("#photo") $("#photo")
.attr("width", width).attr("height", height) .attr("width", width).attr("height", height)
.attr("src", imagePath(current_photo.name, current_album.path, maxSize, false)) .attr("src", imagePath(current_photo.name, current_album.path, maxSize, false))
.attr("alt", current_photo.name) .attr("alt", current_photo.name)
.attr("title", current_photo.date) .attr("title", current_photo.date)
.load(function() { $(this).css("width", "auto").css("height", "100%"); }); .load(scaleImage);
var previousPhoto = current_album.photos[ var previousPhoto = current_album.photos[
(current_photo_index - 1 < 0) ? (current_album.photos.length - 1) : (current_photo_index - 1) (current_photo_index - 1 < 0) ? (current_album.photos.length - 1) : (current_photo_index - 1)