Gettin functional, baby

master
Jason A. Donenfeld 2011-05-05 23:15:03 -04:00
parent 2a33cb215d
commit 0c7d542b46
2 changed files with 80 additions and 15 deletions

View File

@ -8,8 +8,16 @@
<script type="text/javascript" src="js/scripts.min.js"></script>
</head>
<body>
<div id="album">
<h2 id="title"></h2>
<div id="debug">Debug info here...</div>
<h3>Photos</h3>
<div id="photos"></div>
<h3 id="subalbums-title">Sub-albums</h3>
<div id="subalbums"></div>
</div>
<div id="photo"></div>
</body>
</html>

View File

@ -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("<h2>" + album.path + "</h2>");
$("#debug").append("<h3>Photos</h3>");
for (var i = 0; i < album.photos.length; ++i)
$("#debug").append("<a href=\"" + imagePath(album.photos[i].name, album.path, 1024, false) + "\"><img border=0 src=\"" + imagePath(album.photos[i].name, album.path, 150, true) + "\" height=150 width=150></a>");
if (album.albums.length)
$("#debug").append("<h3>Sub-albums</h3>");
for (var i = 0; i < album.albums.length; ++i) {
var link = $("<a href=\"#" + cachePath(album.path + "/" + album.albums[i].path) + "\"><li>" + album.albums[i].path + "</li></a>");
$("#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 += "<a href=\"#" + cachePath(last.substring(1)) + "\">";
title += components[i];
if (i < components.length - 1) {
title += "</a>";
title += " &raquo; ";
}
}
$("#title").html(title);
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 border=0 src=\"" + imagePath(current_album.photos[i].name, current_album.path, 150, true) + "\" height=150 width=150></a>";
$("#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 += "<a href=\"#" + cachePath(current_album.path + "/" + current_album.albums[i].path) + "\"><li>" + current_album.albums[i].path + "</li></a>";
$("#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("<a href=\"javascript:history.back(-1)\"><img src=\"" + imagePath(current_album.photos[index].name, current_album.path, 640, false) + "\"></a>");
$("#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();
});