From 0c7d542b46fd9e3265b8e33e2285def133744526 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Thu, 5 May 2011 23:15:03 -0400 Subject: [PATCH] Gettin functional, baby --- web/index.html | 10 ++++- web/js/010-debugger.js | 85 +++++++++++++++++++++++++++++++++++------- 2 files changed, 80 insertions(+), 15 deletions(-) diff --git a/web/index.html b/web/index.html index dcad414..8e97590 100644 --- a/web/index.html +++ b/web/index.html @@ -8,8 +8,16 @@ +
+

-
Debug info here...
+

Photos

+
+ +

Sub-albums

+
+
+
diff --git a/web/js/010-debugger.js b/web/js/010-debugger.js index 988c0a2..8af0305 100644 --- a/web/js/010-debugger.js +++ b/web/js/010-debugger.js @@ -14,25 +14,82 @@ $(document).ready(function() { $.ajax({ type: "GET", url: "cache/" + path + ".json", + error: function() { $(document.body).html("Couldn't fetch it."); }, success: function(album) { - $("#debug").html("

" + album.path + "

"); - $("#debug").append("

Photos

"); - for (var i = 0; i < album.photos.length; ++i) - $("#debug").append(""); - if (album.albums.length) - $("#debug").append("

Sub-albums

"); - for (var i = 0; i < album.albums.length; ++i) { - var link = $("
  • " + album.albums[i].path + "
  • "); - $("#debug").append(link); - } + current_album = album; + if (current_image_cache != null) + showPhoto(); + else + showAlbum(); } }); } + function showAlbum() { + $("html, body").animate({ scrollTop: 0 }, "slow"); + var title = ""; + var components = current_album.path.split("/"); + var last = ""; + for (var i = 0; i < components.length; ++i) { + last += "/" + components[i]; + if (i < components.length - 1) + title += ""; + title += components[i]; + if (i < components.length - 1) { + title += ""; + title += " » "; + } + } + $("#title").html(title); + var photos = ""; + for (var i = 0; i < current_album.photos.length; ++i) + photos += ""; + $("#photos").html(photos); + if (current_album.albums.length) + $("#subalbums-title").show(); + else + $("#subalbums-title").hide(); + var subalbums = ""; + for (var i = 0; i < current_album.albums.length; ++i) + subalbums += "
  • " + current_album.albums[i].path + "
  • "; + $("#subalbums").html(subalbums); + + $("#album").fadeIn(); + $("#photo").fadeOut(); + } + function showPhoto() { + var index; + for (index = 0; index < current_album.photos.length; ++index) { + if (cachePath(current_album.photos[index].name) == current_image_cache) + break; + } + if (index >= current_album.photos.length) { + $(document.body).html("Wrong picture."); + return; + } + $("#photo").html(""); + $("#album").fadeOut(); + $("#photo").fadeIn(); + } + var current_album_cache = ""; + var current_image_cache = ""; + var current_album = null; $(window).hashchange(function() { - var cache = location.hash.substring(1); - if (!cache.length) - cache = cachePath("New York Summer 2009"); //root - loadAlbum(cache); + var new_album_cache = location.hash.substring(1); + var index = new_album_cache.lastIndexOf("/"); + if (index != -1 && index != new_album_cache.length - 1) { + current_image_cache = new_album_cache.substring(index + 1); + new_album_cache = new_album_cache.substring(0, index); + } else + current_image_cache = null; + if (!new_album_cache.length) + new_album_cache = cachePath("New York Summer 2009"); //root + if (new_album_cache != current_album_cache) { + current_album_cache = new_album_cache; + loadAlbum(current_album_cache); + } else if (current_image_cache != null) + showPhoto(); + else + showAlbum(); }); $(window).hashchange(); });