Show images differently.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 23 Sep 2011 05:29:01 +0000 (07:29 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 23 Sep 2011 05:29:01 +0000 (07:29 +0200)
src/main/java/net/pterodactylus/sone/template/ImageLinkFilter.java
src/main/resources/static/css/sone.css
src/main/resources/templates/imageBrowser.html

index 12f44ef..35cc140 100644 (file)
@@ -39,7 +39,7 @@ import net.pterodactylus.util.template.TemplateParser;
 public class ImageLinkFilter implements Filter {
 
        /** The template to render for the &lt;img%gt; tag. */
-       private static final Template linkTemplate = TemplateParser.parse(new StringReader("<img<%ifnull !class> class=\"<%class|css>\"<%/if> src=\"<%src|html>\" alt=\"<%alt|html>\" title=\"<%title|html>\" width=\"<%width|html>\" height=\"<%height|html>\" />"));
+       private static final Template linkTemplate = TemplateParser.parse(new StringReader("<img<%ifnull !class> class=\"<%class|css>\"<%/if> src=\"<%src|html>\" alt=\"<%alt|html>\" title=\"<%title|html>\" width=\"<%width|html>\" height=\"<%height|html>\" style=\"position: relative;<%ifnull ! top>top: <% top|html>;<%/if><%ifnull ! left>left: <% left|html>;<%/if>\"/>"));
 
        /** The template context factory. */
        private final TemplateContextFactory templateContextFactory;
@@ -63,6 +63,7 @@ public class ImageLinkFilter implements Filter {
                String imageClass = parameters.get("class");
                int maxWidth = Numbers.safeParseInteger(parameters.get("max-width"), Integer.MAX_VALUE);
                int maxHeight = Numbers.safeParseInteger(parameters.get("max-height"), Integer.MAX_VALUE);
+               String mode = String.valueOf(parameters.get("mode"));
                String title = parameters.get("title");
                if ((title != null) && title.startsWith("=")) {
                        title = String.valueOf(templateContext.get(title.substring(1)));
@@ -77,12 +78,25 @@ public class ImageLinkFilter implements Filter {
                }
                int imageWidth = image.getWidth();
                int imageHeight = image.getHeight();
-               double scale = 1;
-               if ((imageWidth > maxWidth) || (imageHeight > maxHeight)) {
-                       scale = Math.min(maxWidth / (double) imageWidth, maxHeight / (double) imageHeight);
+               if ("enlarge".equals(mode)) {
+                       double scale = Math.max(maxWidth / (double) imageWidth, maxHeight / (double) imageHeight);
+                       linkTemplateContext.set("width", (int) (imageWidth * scale + 0.5));
+                       linkTemplateContext.set("height", (int) (imageHeight * scale + 0.5));
+                       if (scale >= 1) {
+                               linkTemplateContext.set("left", String.format("%dpx", (int) ((imageWidth * scale) - maxWidth) / 2));
+                               linkTemplateContext.set("top", String.format("%dpx", (int) ((imageHeight * scale) - maxHeight) / 2));
+                       } else {
+                               linkTemplateContext.set("left", String.format("%dpx", (int) (maxWidth - (imageWidth * scale)) / 2));
+                               linkTemplateContext.set("top", String.format("%dpx", (int) (maxHeight - (imageHeight * scale)) / 2));
+                       }
+               } else {
+                       double scale = 1;
+                       if ((imageWidth > maxWidth) || (imageHeight > maxHeight)) {
+                               scale = Math.min(maxWidth / (double) imageWidth, maxHeight / (double) imageHeight);
+                       }
+                       linkTemplateContext.set("width", (int) (imageWidth * scale + 0.5));
+                       linkTemplateContext.set("height", (int) (imageHeight * scale + 0.5));
                }
-               linkTemplateContext.set("width", (int) (imageWidth * scale + 0.5));
-               linkTemplateContext.set("height", (int) (imageHeight * scale + 0.5));
                linkTemplateContext.set("alt", Default.forNull(title, image.getDescription()));
                linkTemplateContext.set("title", Default.forNull(title, image.getTitle()));
 
index 1e400fb..1cb2e95 100644 (file)
@@ -656,17 +656,24 @@ textarea {
        display: table-row;
 }
 
+#sone .image-container {
+       width: 200px;
+       height: 200px;
+       overflow: hidden;
+       padding: -1px;
+       border: solid 1px #000;
+}
+
 #sone .image {
        width: 200px;
        height: 150px;
        display: table-cell;
-       vertical-align: middle;
+       vertical-align: top;
        text-align: center;
        padding: 0.5ex;
 }
 
 #sone .image img, #sone .single-image img {
-       padding: 1ex;
        border: solid 1px #000;
        background-color: #fff;
 }
@@ -679,6 +686,14 @@ textarea {
        width: 95%;
 }
 
+#sone .image .image-title {
+       font-weight: bold;
+}
+
+#sone .image .image-description {
+       text-align: left;
+}
+
 #sone .backlinks .separator {
        display: inline;
 }
index 9c0ef90..162441a 100644 (file)
                                <%first><h2><%= Page.ImageBrowser.Header.Albums|l10n|html></h2><%/first>
                                <%if loop.count|mod divisor=3><div class="image-row"><%/if>
                                <div class="album image">
-                                       <a href="imageBrowser.html?album=<% album.id|html>" title="<% album.title|html>">
-                                               <%ifnull album.albumImage>
-                                                       <img src="images/unknown-image-0.png" width="200" height="150" alt="<% album.title|html>" title="<% album.title|html>" />
-                                               <%else><!-- TODO -->
-                                                       <% album.albumImage|image-link max-width=200 max-height=150 title==album.title>
-                                               <%/if>
-                                               <br/>
-                                               <% album.title|html>
-                                       </a>
+                                       <div class="image-container">
+                                               <a href="imageBrowser.html?album=<% album.id|html>" title="<% album.title|html>">
+                                                       <%ifnull album.albumImage>
+                                                               <img src="images/unknown-image-0.png" width="266" height="200" alt="<% album.title|html>" title="<% album.title|html>" style="position: relative; top: 0px; left: -33px;" />
+                                                       <%else><!-- TODO -->
+                                                               <% album.albumImage|image-link max-width=200 max-height=200 mode=enlarge title==album.title>
+                                                       <%/if>
+                                               </a>
+                                       </div>
+                                       <% album.title|html>
                                </div>
                                <%= false|store key=endRow>
                                <%if loop.count|mod divisor=3 offset=1><%= true|store key=endRow><%/if>
                        <%foreach album.images image>
                                <%first><h2><%= Page.ImageBrowser.Header.Images|l10n|html></h2><%/first>
                                <%if loop.count|mod divisor=3><div class="image-row"><%/if>
-                               <div class="image">
-                                       <a href="imageBrowser.html?image=<%image.id|html>"><% image|image-link max-width=200 max-height=150></a>
+                               <div id="image-<% image.id|html>" class="image">
+                                       <div class="image-id hidden"><% image.id|html></div>
+                                       <div class="image-container">
+                                               <a href="imageBrowser.html?image=<%image.id|html>"><% image|image-link max-width=200 max-height=200 mode=enlarge title==image.title></a>
+                                       </div>
                                        <%if album.sone.local>
-                                               <br/>
                                                <form class="edit-image" action="editImage.html" method="post">
                                                        <input type="hidden" name="formPassword" value="<%formPassword|html>" />
                                                        <input type="hidden" name="returnPage" value="<%request.uri|html>" />
                                                        <input type="hidden" name="image" value="<%image.id|html>" />
 
-                                                       <div>
-                                                               <input type="text" name="title" value="<%image.title|html>" />
+                                                       <div class="show-data">
+                                                               <div class="image-title"><% image.title|html></div>
+                                                               <div class="image-description"><% image.description|html></div>
                                                        </div>
-                                                       <div>
-                                                               <textarea name="description"><%image.description|html></textarea>
-                                                       </div>
-                                                       <div>
-                                                               <button type="submit"><%= Page.ImageBrowser.Image.Button.Save|l10n|html></button>
+                                                       <div class="edit-data hidden">
+                                                               <div>
+                                                                       <input type="text" name="title" value="<%image.title|html>" />
+                                                               </div>
+                                                               <div>
+                                                                       <textarea name="description"><%image.description|html></textarea>
+                                                               </div>
+                                                               <div>
+                                                                       <button type="submit"><%= Page.ImageBrowser.Image.Button.Save|l10n|html></button>
+                                                               </div>
                                                        </div>
                                                </form>
                                        <%/if>
                        <%foreach sone.albums album>
                                <%if loop.count|mod divisor=3><div class="image-row"><%/if>
                                <div class="album image">
-                                       <a href="imageBrowser.html?album=<% album.id|html>" title="<% album.title|html>">
-                                               <%ifnull album.albumImage>
-                                                       <img src="images/unknown-image-0.png" width="200" height="150" alt="<% album.title|html>" title="<% album.title|html>" />
-                                               <%else><!-- TODO -->
-                                                       <% album.albumImage|image-link max-width=200 max-height=150 title==album.title>
-                                               <%/if>
-                                               <br/>
+                                       <div class="image-container">
+                                               <a href="imageBrowser.html?album=<% album.id|html>" title="<% album.title|html>">
+                                                       <%ifnull album.albumImage>
+                                                               <img src="images/unknown-image-0.png" width="266" height="200" alt="<% album.title|html>" title="<% album.title|html>" style="position: relative; top: 0px; left: -33px;"/>
+                                                       <%else><!-- TODO -->
+                                                               <% album.albumImage|image-link max-width=200 max-height=200 mode=enlarge title==album.title>
+                                                       <%/if>
+                                               </a>
                                                <% album.title|html>
-                                       </a>
+                                       </div>
                                </div>
                                <%= false|store key=endRow>
                                <%if loop.count|mod divisor=3 offset=1><%= true|store key=endRow><%/if>