diff --git a/src/main/java/org/forkalsrud/album/video/FlvMetadata.java b/src/main/java/org/forkalsrud/album/video/FlvMetadata.java index 608c7db..d68a6cc 100644 --- a/src/main/java/org/forkalsrud/album/video/FlvMetadata.java +++ b/src/main/java/org/forkalsrud/album/video/FlvMetadata.java @@ -477,7 +477,7 @@ public class FlvMetadata { } public void setDurationFromLastTimestamp() { - if (duration.value == null || duration.value.doubleValue() <= 0) { + if ((duration.value == null || duration.value.doubleValue() <= 0) && lasttimestamp != null && lasttimestamp.value != null) { setDuration(lasttimestamp.value / 1000d); } } diff --git a/src/main/java/org/forkalsrud/album/web/AlbumServlet.java b/src/main/java/org/forkalsrud/album/web/AlbumServlet.java index cf8cd28..8a22191 100644 --- a/src/main/java/org/forkalsrud/album/web/AlbumServlet.java +++ b/src/main/java/org/forkalsrud/album/web/AlbumServlet.java @@ -6,6 +6,7 @@ import java.io.FileOutputStream; import java.io.FileReader; import java.io.IOException; import java.io.PrintWriter; +import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.Properties; @@ -302,7 +303,7 @@ public class AlbumServlet req.setAttribute("thmb", new Integer(250)); req.setAttribute("full", new Integer(800)); req.setAttribute("D", "$"); - RequestDispatcher rd = req.getRequestDispatcher("/WEB-INF/velocity/dynamic.vm"); + RequestDispatcher rd = req.getRequestDispatcher("/WEB-INF/ng.html"); rd.forward(req, res); } @@ -384,6 +385,18 @@ public class AlbumServlet PrintWriter out = res.getWriter(); out.println("{"); out.println(" \"name\": " + jsStr(entry.getName()) + ","); + if (entry.parent() != null && "dir".equals(entry.parent().getType())) { + out.println(" \"parent\": " + jsStr(mapper.map(entry.parent().getPath())) + ","); + } + if (entry.prev() != null && "dir".equals(entry.prev().getType())) { + out.println(" \"prev\": " + jsStr(mapper.map(entry.prev().getPath())) + ","); + } + if (entry.next() != null && "dir".equals(entry.next().getType())) { + out.println(" \"next\": " + jsStr(mapper.map(entry.next().getPath())) + ","); + } + if (entry.groupByYear()) { + out.println(" \"groupPrefix\": 4,"); + } out.println(" \"contents\": ["); int n = 0; for (Entry e : entry.getContents()) { @@ -392,14 +405,25 @@ public class AlbumServlet out.println(" {"); out.println(" \"name\": " + jsStr(e.getName()) + ","); out.println(" \"type\": " + jsStr(e.getType()) + ","); + if ("dir".equals(e.getType())) { + DirectoryEntry de = (DirectoryEntry)e; + if (de.getEarliest() != null) { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy"); + out.println(" \"earliest\": " + jsStr(sdf.format(de.getEarliest())) + ","); + } + } Thumbnail thumb = e.getThumbnail(); if (thumb != null) { out.println(" \"path\": " + jsStr(mapper.map(thumb.getPath())) + ","); out.println(" \"thumbtype\": " + jsStr(thumb.getType()) + ","); out.println(" \"width\": " + thumb.getSize().getWidth() + ","); - out.println(" \"height\": " + thumb.getSize().getHeight() + ","); + out.print(" \"height\": " + thumb.getSize().getHeight()); + } + if (e.getCaption() != null) { + out.println(",\n \"caption\": " + jsStr(e.getCaption())); + } else { + out.println(); } - out.println(" \"caption\": " + jsStr(e.getCaption())); out.print(" }"); } catch (Exception ex) { throw new Exception(e.toString(), ex); diff --git a/src/main/webapp/WEB-INF/ng.html b/src/main/webapp/WEB-INF/ng.html new file mode 100644 index 0000000..2d915d2 --- /dev/null +++ b/src/main/webapp/WEB-INF/ng.html @@ -0,0 +1,86 @@ + + + + + + album + + + + + + + + + + + + + + +
+

 

+
+ + diff --git a/src/main/webapp/assets/render.js b/src/main/webapp/assets/render.js new file mode 100644 index 0000000..ba47214 --- /dev/null +++ b/src/main/webapp/assets/render.js @@ -0,0 +1,149 @@ + +$(function() { + + function formatTitle(title, currentArray, currentIndex, currentOpts) { + 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) }; + } + } + + $.getJSON(location.pathname.replace(/\.album(\?|$)/, '.json'), function(data, textStatus) { + + $("#name").text(data.name); + $("title").text(data.name); + + var thmb = 250; + var picSize = 800; + var movieSize = 640; + var prevName = null, thisName; + + $.each(data.contents, function(idx, entry) { + + if (data.groupPrefix && entry.type == "dir") { + thisName = entry.earliest; + if (prevName != null && prevName != thisName) { + $("
").appendTo("body"); + prevName = null; + } + if (prevName == null) { + $("

").text(thisName).appendTo("body"); + prevName = thisName; + } + } + + var dim = scale(entry.width, entry.height, thmb); + + var gridDiv = $("
\n" + + " " + entry.name + "
\n" + + "
" + + "
\n" + + "
\n"); + + var captionP = $("

\n"); + if (entry.caption) { + captionP.text(entry.caption); + } + captionP.appendTo(gridDiv); + + gridDiv.appendTo('body'); + + switch (entry.type) { + case "movie": + var size = scale(entry.width, entry.height, movieSize); + var href = "/photo/album" + escape(entry.path) + ".movie?size=" + movieSize; + $("#ent" + idx).attr("rel", "album").attr("href", href).fancybox({ + 'titlePosition' : 'inside', + 'transitionIn' : 'elastic', + 'transitionOut' : 'elastic', + 'easingIn' : 'easeInQuad', + 'easingOut' : 'easeOutQuad', + 'titleFormat' : formatTitle, + 'padding' : 0, + 'href' : "/photo/assets/flowplayer/flowplayer-3.0.3.swf", + 'width' : size.w, + 'height' : size.h, + 'type' : 'swf', + 'swf' : { + 'allowfullscreen' : 'true', + 'wmode' : 'transparent', + 'flashvars': + "config={\ + 'clip': {\ + 'url': '" + href + "'\ + },\ + 'plugins': {\ + 'controls': {\ + 'url': '/photo/assets/flowplayer/flowplayer.controls-3.0.3.swf',\ + 'backgroundColor': 'transparent',\ + 'progressColor': 'transparent',\ + 'bufferColor': 'transparent',\ + 'play':true,\ + 'fullscreen':true,\ + 'autoHide': 'always'\ + }\ + }\ + }" + } + }); + break; + 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', + 'titleFormat' : formatTitle, + '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; + } + + }); + + + function buildButton(direction, destination, transform) { + var imgName = destination ? direction : direction + "-inactive", + imgElement = $(""); + if (destination) { + return $("").attr("href", "/photo/album" + destination + ".album").append(imgElement); + } else { + return imgElement; + } + } + + $("#titleBar").html("").append(buildButton("left", data.prev)).append(buildButton("up", data.parent)).append(buildButton("right", data.next)).append(" " + data.name); + + + + 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; + } + }); + } + + if (selectedPos !== undefined) { + $("#ent" + selectedPos).trigger('click'); + } + }); + +});