2014-08-09 23:06:41 -07:00
|
|
|
|
|
|
|
|
$(function() {
|
|
|
|
|
|
2024-03-18 20:46:06 -07:00
|
|
|
function formatCaption(title, currentArray, currentIndex, currentOpts) {
|
2014-08-09 23:06:41 -07:00
|
|
|
var captionElement = document.getElementById(title);
|
|
|
|
|
return captionElement.innerHTML;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function scale(w, h, max) {
|
|
|
|
|
if (w > h) {
|
|
|
|
|
return { w : Math.floor(max), h: Math.floor((max * h + max / 2) / w) };
|
|
|
|
|
} else {
|
|
|
|
|
return { w: Math.floor((max * w + max / 2) / h), h: Math.floor(max) };
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-04 13:37:03 -07:00
|
|
|
|
2024-12-30 15:12:40 -08:00
|
|
|
function encUri(str) {
|
|
|
|
|
return encodeURI(str)
|
|
|
|
|
.replace(/%5B/g, "[")
|
|
|
|
|
.replace(/%5D/g, "]")
|
|
|
|
|
.replace(/[!'()*?&#]/g, function (c) {
|
|
|
|
|
return "%" + c.charCodeAt(0).toString(16).toUpperCase();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-14 14:50:49 -08:00
|
|
|
function renderGrid(data, textStatus) {
|
|
|
|
|
|
2024-09-16 17:11:10 -07:00
|
|
|
var container = $("#container");
|
|
|
|
|
container.empty();
|
2024-01-14 14:50:49 -08:00
|
|
|
$("#name").text(data.name);
|
|
|
|
|
document.title = data.name;
|
2014-08-09 23:06:41 -07:00
|
|
|
|
2024-01-14 14:50:49 -08:00
|
|
|
var thmb = 250;
|
|
|
|
|
var picSize = 800;
|
|
|
|
|
var movieSize = 640;
|
2014-08-09 23:06:41 -07:00
|
|
|
var prevName = null, thisName;
|
2024-01-14 14:50:49 -08:00
|
|
|
|
2024-03-18 20:46:06 -07:00
|
|
|
function updateButton(selector, direction, destination) {
|
|
|
|
|
var imgName = destination ? direction : direction + "-inactive",
|
|
|
|
|
imgUrl = "/photo/assets/" + imgName + ".png",
|
|
|
|
|
imgElement = $(selector),
|
|
|
|
|
isWrapped = imgElement.parent().get()[0].tagName == "A",
|
|
|
|
|
anchor = isWrapped ? imgElement.parent() : $("<a></a>");
|
|
|
|
|
if (destination) {
|
2024-12-30 15:12:40 -08:00
|
|
|
anchor.attr("href", encUri("/photo/album" + destination + ".album") + location.search);
|
2024-03-18 20:46:06 -07:00
|
|
|
if (!isWrapped) {
|
|
|
|
|
imgElement.wrap(anchor);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (isWrapped) {
|
|
|
|
|
imgElement.unwrap();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
imgElement.attr("src", imgUrl);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$("#entryName").text(data.name);
|
|
|
|
|
$("#arrowLeft").attr(data.name);
|
|
|
|
|
updateButton("#arrowLeft", "left", data.prev);
|
|
|
|
|
updateButton("#arrowUp", "up", data.parent);
|
|
|
|
|
updateButton("#arrowRight", "right", data.next);
|
|
|
|
|
if (location.search) {
|
|
|
|
|
let params = new URL(location.href).searchParams;
|
|
|
|
|
if (params.has("q")) {
|
|
|
|
|
$("#searchBox").val(params.get("q"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2024-01-14 14:50:49 -08:00
|
|
|
$.each(data.contents, function(idx, entry) {
|
2014-08-09 23:06:41 -07:00
|
|
|
|
|
|
|
|
if (data.groupPrefix && entry.type == "dir") {
|
|
|
|
|
thisName = entry.earliest;
|
|
|
|
|
if (prevName != null && prevName != thisName) {
|
2024-09-16 17:11:10 -07:00
|
|
|
$("<hr/>").appendTo(container);
|
2014-08-09 23:06:41 -07:00
|
|
|
prevName = null;
|
|
|
|
|
}
|
|
|
|
|
if (prevName == null) {
|
2024-09-16 17:11:10 -07:00
|
|
|
$("<h2></h2>").text(thisName).appendTo(container);
|
2014-08-09 23:06:41 -07:00
|
|
|
prevName = thisName;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-14 14:50:49 -08:00
|
|
|
var dim = scale(entry.width, entry.height, thmb);
|
2014-08-09 23:06:41 -07:00
|
|
|
|
2024-01-14 14:50:49 -08:00
|
|
|
var gridDiv = $("<div class=\"grid\">\n"
|
|
|
|
|
+ " <span class=\"name\">" + entry.name + "</span><br/>\n"
|
2024-12-30 15:12:40 -08:00
|
|
|
+ " <div class=\"imgborder\"><a class=\"ss\" id=\"ent" + idx + "\" href=\"/photo/album" + encUri(entry.path) + "?size=" + picSize + "\" title=\"" + entry.name + "\">"
|
|
|
|
|
+ "<img class=\"" + entry.type + "pic\" src=\"/photo/album" + (entry.thumbtype == "movie" ? encUri(entry.path) + ".frame" : encUri(entry.path)) + "?size=" + thmb + "\" border=\"0\" width=\"" + dim.w + "\" height=\"" + dim.h + "\"/></a></div>\n"
|
2024-01-14 14:50:49 -08:00
|
|
|
+ "</div>\n");
|
2014-08-09 23:06:41 -07:00
|
|
|
|
2024-09-16 17:11:10 -07:00
|
|
|
var captionP = $("<p class=\"caption\"></p>\n");
|
|
|
|
|
captionP.attr("id", entry.name);
|
2014-08-09 23:06:41 -07:00
|
|
|
if (entry.caption) {
|
|
|
|
|
captionP.text(entry.caption);
|
|
|
|
|
}
|
|
|
|
|
captionP.appendTo(gridDiv);
|
|
|
|
|
|
2024-09-16 17:11:10 -07:00
|
|
|
gridDiv.appendTo(container);
|
2014-08-09 23:06:41 -07:00
|
|
|
|
2024-01-14 14:50:49 -08:00
|
|
|
switch (entry.type) {
|
|
|
|
|
case "movie":
|
|
|
|
|
case "image":
|
|
|
|
|
var largeDim = scale(entry.width, entry.height, picSize);
|
|
|
|
|
$("#ent" + idx).attr("rel", "album").fancybox({
|
|
|
|
|
'titlePosition' : 'inside',
|
|
|
|
|
'transitionIn' : 'elastic',
|
|
|
|
|
'transitionOut' : 'elastic',
|
|
|
|
|
'easingIn' : 'easeInQuad',
|
|
|
|
|
'easingOut' : 'easeOutQuad',
|
2024-03-18 20:46:06 -07:00
|
|
|
'titleFormat' : formatCaption,
|
2024-01-14 14:50:49 -08:00
|
|
|
'width' : largeDim.w,
|
|
|
|
|
'height' : largeDim.h,
|
|
|
|
|
'type' : "image",
|
|
|
|
|
'href' : $("#ent" + idx).href
|
|
|
|
|
});
|
|
|
|
|
break;
|
|
|
|
|
case "dir":
|
|
|
|
|
$("#ent" + idx).attr("href", location.pathname.replace(/\.album?($|\?)/, "/" + entry.name + ".album"));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2024-03-18 20:46:06 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var selectedImg = window.location.search;
|
|
|
|
|
var selectedPos = undefined;
|
|
|
|
|
if (/^\?focus=/.test(selectedImg)) {
|
|
|
|
|
selectedImg = selectedImg.substring('?focus='.length);
|
|
|
|
|
$("a.ss").each(function(index) {
|
|
|
|
|
if (selectedImg == $(this).attr("title")) {
|
|
|
|
|
selectedPos = index;
|
2024-01-14 14:50:49 -08:00
|
|
|
}
|
2024-03-18 20:46:06 -07:00
|
|
|
});
|
|
|
|
|
}
|
2014-08-09 23:06:41 -07:00
|
|
|
|
2024-03-18 20:46:06 -07:00
|
|
|
if (selectedPos !== undefined) {
|
|
|
|
|
$("#ent" + selectedPos).trigger('click');
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-08-09 23:06:41 -07:00
|
|
|
|
|
|
|
|
|
2024-09-16 17:11:10 -07:00
|
|
|
$("#search").on("submit", function () {
|
2024-12-30 15:12:40 -08:00
|
|
|
var searchStr = "?q=" + encUri($("#searchBox").val());
|
2024-09-16 17:11:10 -07:00
|
|
|
history.pushState({ }, null, searchStr);
|
|
|
|
|
$.getJSON(location.pathname.replace(/\.album(\?|$)/, '.json') + searchStr, renderGrid);
|
|
|
|
|
return false;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
function resetSearch() {
|
|
|
|
|
$("#searchBox").val("");
|
|
|
|
|
history.pushState({ }, null, location.pathname);
|
|
|
|
|
$.getJSON(location.pathname.replace(/\.album(\?|$)/, '.json'), renderGrid);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
$("#search").on("reset", resetSearch);
|
|
|
|
|
$("#searchBox").keyup(function (e) {
|
|
|
|
|
if (e.key === "Escape") {
|
|
|
|
|
resetSearch();
|
|
|
|
|
}
|
|
|
|
|
});
|
2024-01-14 14:50:49 -08:00
|
|
|
|
|
|
|
|
|
2024-03-18 20:46:06 -07:00
|
|
|
$.getJSON(location.pathname.replace(/\.album(\?|$)/, '.json') + location.search, renderGrid);
|
2024-01-14 14:50:49 -08:00
|
|
|
|
|
|
|
|
|
2014-08-09 23:06:41 -07:00
|
|
|
|
|
|
|
|
});
|