summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2011-05-07 18:14:21 -0400
committerJason A. Donenfeld <Jason@zx2c4.com>2011-05-07 18:14:21 -0400
commit6e0eadadbd1e7b973f3e70bb1282c9d854504f3d (patch)
tree47f90a5527dab658f58d03513cda454d4f4df646
parentCaching. (diff)
downloadPhotoFloat-6e0eadadbd1e7b973f3e70bb1282c9d854504f3d.tar.xz
PhotoFloat-6e0eadadbd1e7b973f3e70bb1282c9d854504f3d.zip
Scrolling, load order.
-rw-r--r--web/js/010-control.js93
1 files changed, 57 insertions, 36 deletions
diff --git a/web/js/010-control.js b/web/js/010-control.js
index b78ce80..c60843c 100644
--- a/web/js/010-control.js
+++ b/web/js/010-control.js
@@ -52,10 +52,10 @@ $(document).ready(function() {
$("#loading").hide();
album_cache[cachePath(album.path)] = album;
current_album = album;
- if (cachePath(album.path) == current_album_cache)
- showAlbum();
if (current_photo_cache != null)
showPhoto();
+ if (cachePath(album.path) == current_album_cache)
+ showAlbum(true);
setTitle();
}
function trimExtension(title) {
@@ -89,35 +89,39 @@ $(document).ready(function() {
title += trimExtension(current_photo.name);
$("#title").html(title);
}
- function showAlbum() {
- $("html, body").animate({ scrollTop: 0 }, "slow");
- var photos = "";
- for (var i = 0; i < current_album.photos.length; ++i)
- photos += "<a href=\"#" + current_album_cache + "/" + cachePath(current_album.photos[i].name) + "\"><img title=\"" + trimExtension(current_album.photos[i].name) + "\" alt=\"" + trimExtension(current_album.photos[i].name) + "\" id=\"thumb-" + cachePath(current_album.photos[i].name) + "\" src=\"" + imagePath(current_album.photos[i].name, current_album.path, 150, true) + "\" height=\"150\" width=\"150\"></a>";
- $("#thumbs").html(photos);
- if (current_album.albums.length)
- $("#subalbums-title").show();
- else
- $("#subalbums-title").hide();
- var subalbums = "";
- var thumbFinderList = new Array();
- for (var i = current_album.albums.length - 1; i >= 0; --i) {
- var path = cachePath(current_album.path + "/" + current_album.albums[i].path);
- var id = "album-" + path;
- subalbums += "<a href=\"#" + path + "\"><div title=\"" + current_album.albums[i].date + "\" id=\"" + id + "\" class=\"album-button\">" + current_album.albums[i].path + "</div></a>";
- thumbFinderList.push({ path: path, id: escapeId(id) });
+ function showAlbum(populate) {
+ if (current_photo_cache == null && previous_photo_cache == null)
+ $("html, body").stop().animate({ scrollTop: 0 }, "slow");
+
+ if (populate) {
+ var photos = "";
+ for (var i = 0; i < current_album.photos.length; ++i)
+ photos += "<a href=\"#" + current_album_cache + "/" + cachePath(current_album.photos[i].name) + "\"><img title=\"" + trimExtension(current_album.photos[i].name) + "\" alt=\"" + trimExtension(current_album.photos[i].name) + "\" id=\"thumb-" + cachePath(current_album.photos[i].name) + "\" src=\"" + imagePath(current_album.photos[i].name, current_album.path, 150, true) + "\" height=\"150\" width=\"150\"></a>";
+ $("#thumbs").html(photos);
+
+ var subalbums = "";
+ var thumbFinderList = new Array();
+ for (var i = current_album.albums.length - 1; i >= 0; --i) {
+ var path = cachePath(current_album.path + "/" + current_album.albums[i].path);
+ var id = "album-" + path;
+ subalbums += "<a href=\"#" + path + "\"><div title=\"" + current_album.albums[i].date + "\" id=\"" + id + "\" class=\"album-button\">" + current_album.albums[i].path + "</div></a>";
+ thumbFinderList.push({ path: path, id: escapeId(id) });
+ }
+ $("#subalbums").html(subalbums);
+ for (var i = 0; i < thumbFinderList.length; ++i)
+ (function(thumb) {
+ albumThumbFinder(thumb.path, function(photo, album) {
+ $("#" + thumb.id).css("background-image", "url(" + imagePath(photo.name, album.path, 150, true) + ")");
+ });
+ })(thumbFinderList[i]);
}
- $("#subalbums").html(subalbums);
- for (var i = 0; i < thumbFinderList.length; ++i)
- (function(thumb) {
- albumThumbFinder(thumb.path, function(photo, album) {
- $("#" + thumb.id).css("background-image", "url(" + imagePath(photo.name, album.path, 150, true) + ")");
- });
- })(thumbFinderList[i]);
- $("#album-view").removeClass("photo-view-container");
- $("#subalbums").show();
- $("#photo-view").hide();
+ if (current_photo_cache == null) {
+ $("#album-view").removeClass("photo-view-container");
+ $("#subalbums").show();
+ $("#photo-view").hide();
+ }
+ scrollToThumb();
}
function getDecimal(fraction) {
if (fraction[0] < fraction[1])
@@ -176,10 +180,22 @@ $(document).ready(function() {
$("#album-view").addClass("photo-view-container");
$("#subalbums").hide();
$("#photo-view").show();
- var thumb = $("#thumb-" + escapeId(current_photo_cache));
- var scroller = $("#album-view");
- scroller.stop();
- scroller.animate({ scrollLeft: thumb.position().left + scroller.scrollLeft() - scroller.width() / 2 + thumb.width() / 2 }, "slow");
+ }
+ function scrollToThumb() {
+ var photo = current_photo_cache
+ if (photo == null) {
+ photo = previous_photo_cache;
+ if (photo == null)
+ return;
+ }
+ var thumb = $("#thumb-" + escapeId(photo));
+ if (!thumb.length)
+ return;
+ if (current_photo_cache != 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");
}
function currentPhoto() {
for (current_photo_index = 0; current_photo_index < current_album.photos.length; ++current_photo_index) {
@@ -229,6 +245,7 @@ $(document).ready(function() {
var current_album_cache = null;
var current_photo_cache = null;
+ var previous_photo_cache = null;
var current_album = null;
var current_photo = null;
var current_photo_index = -1;
@@ -237,21 +254,25 @@ $(document).ready(function() {
var new_album_cache = location.hash.substring(1);
var index = new_album_cache.lastIndexOf("/");
if (index != -1 && index != new_album_cache.length - 1) {
+ previous_photo_cache = current_photo_cache;
current_photo_cache = new_album_cache.substring(index + 1);
new_album_cache = new_album_cache.substring(0, index);
- } else
+ } else {
+ previous_photo_cache = current_photo_cache;
current_photo_cache = null;
+ }
if (!new_album_cache.length)
new_album_cache = cachePath("root");
if (new_album_cache != current_album_cache) {
current_album_cache = new_album_cache;
+ previous_photo_cache = null;
loadAlbum();
} else if (current_photo_cache != null) {
- showAlbum();
showPhoto();
+ showAlbum(false);
setTitle();
} else {
- showAlbum();
+ showAlbum(false);
setTitle();
}
});