Proper ID scheme for thumbs.

This commit is contained in:
Jason A. Donenfeld 2011-05-13 04:51:49 -04:00
parent 271afa6611
commit fbf63ba769

View File

@ -32,6 +32,11 @@ $(document).ready(function() {
suffix = size.toString(); suffix = size.toString();
return "cache/" + cachePath(path + "/" + image + "_" + suffix + ".jpg"); return "cache/" + cachePath(path + "/" + image + "_" + suffix + ".jpg");
} }
function properId(path) {
if (!path[0].match(/[a-zA-Z]/))
path = "a" + path;
return path.replace(/[^a-zA-Z0-9_:.\-]/g, "-");
}
function escapeId(id) { function escapeId(id) {
return id.replace(/\./g, "\\.").replace(/,/g, "\\,"); return id.replace(/\./g, "\\.").replace(/,/g, "\\,");
} }
@ -114,7 +119,7 @@ $(document).ready(function() {
var thumbFinderList = new Array(); var thumbFinderList = new Array();
for (var i = current_album.albums.length - 1; i >= 0; --i) { for (var i = current_album.albums.length - 1; i >= 0; --i) {
var path = cachePath(current_album.path + "/" + current_album.albums[i].path); var path = cachePath(current_album.path + "/" + current_album.albums[i].path);
var id = "album-" + path; var id = properId("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>"; 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) }); thumbFinderList.push({ path: path, id: escapeId(id) });
} }
@ -217,7 +222,7 @@ $(document).ready(function() {
if (photo == null) if (photo == null)
return; return;
} }
var thumb = $("#thumb-" + escapeId(photo)); var thumb = $("#thumb-" + escapeId(properId(photo)));
if (!thumb.length) if (!thumb.length)
return; return;
if (current_photo_cache != null) { if (current_photo_cache != null) {