web server: can disable buttons
authorNiki Roo <niki@nikiroo.be>
Tue, 12 May 2020 14:08:19 +0000 (16:08 +0200)
committerNiki Roo <niki@nikiroo.be>
Tue, 12 May 2020 14:08:19 +0000 (16:08 +0200)
src/be/nikiroo/fanfix/library/WebLibraryServer.java
src/be/nikiroo/fanfix/library/web/style.css

index 3e2c90605de78b2956290b4b36b56bb8a6a42688..4bd51f47e3a4a141b7fd4b45460a60ba60405ee1 100644 (file)
@@ -672,7 +672,8 @@ public class WebLibraryServer implements Runnable {
                // 1-based (0 = desc)
                int chapter = 0;
                if (chapterStr != null && !"cover".equals(chapterStr)
-                               && !"metadata".equals(chapterStr) && !"json".equals(chapterStr)) {
+                               && !"metadata".equals(chapterStr)
+                               && !"json".equals(chapterStr)) {
                        try {
                                chapter = Integer.parseInt(chapterStr);
                                if (chapter < 0) {
@@ -711,7 +712,7 @@ public class WebLibraryServer implements Runnable {
                                JSONObject json = JsonIO.toJson(meta);
                                mimeType = "application/json";
                                in = new ByteArrayInputStream(json.toString().getBytes());
-                       }  else if ("json".equals(chapterStr)) {
+                       } else if ("json".equals(chapterStr)) {
                                Story story = story(luid, whitelist);
                                JSONObject json = JsonIO.toJson(story);
                                mimeType = "application/json";
@@ -835,6 +836,12 @@ public class WebLibraryServer implements Runnable {
                                String first, previous, next, last;
                                String content;
 
+                               String disabledLeft = "";
+                               String disabledRight = "";
+                               String disabledZoomReal = "";
+                               String disabledZoomWidth = "";
+                               String disabledZoomHeight = "";
+
                                if (paragraph <= 0) {
                                        first = getViewUrl(luid, 1, null);
                                        previous = getViewUrl(luid, (Math.max(chapter - 1, 1)),
@@ -847,6 +854,11 @@ public class WebLibraryServer implements Runnable {
                                        content = "<div class='viewer text'>\n"
                                                        + new TextOutput(false).convert(chap, true)
                                                        + "</div>\n";
+
+                                       if (chapter <= 1)
+                                               disabledLeft = " disabled='disbaled'";
+                                       if (chapter >= story.getChapters().size())
+                                               disabledRight = " disabled='disbaled'";
                                } else {
                                        first = getViewUrl(luid, chapter, 1);
                                        previous = getViewUrl(luid, chapter,
@@ -856,6 +868,11 @@ public class WebLibraryServer implements Runnable {
                                        last = getViewUrl(luid, chapter,
                                                        chap.getParagraphs().size());
 
+                                       if (paragraph <= 1)
+                                               disabledLeft = " disabled='disbaled'";
+                                       if (paragraph >= chap.getParagraphs().size())
+                                               disabledRight = " disabled='disbaled'";
+
                                        Paragraph para = null;
                                        try {
                                                para = chap.getParagraphs().get(paragraph - 1);
@@ -867,15 +884,20 @@ public class WebLibraryServer implements Runnable {
 
                                        if (para.getType() == ParagraphType.IMAGE) {
                                                String zoomStyle = "max-width: 100%;";
+                                               disabledZoomWidth = " disabled='disabled'";
                                                String zoomOption = cookies.get("zoom");
                                                if (zoomOption != null && !zoomOption.isEmpty()) {
                                                        if (zoomOption.equals("real")) {
                                                                zoomStyle = "";
+                                                               disabledZoomWidth = "";
+                                                               disabledZoomReal = " disabled='disabled'";
                                                        } else if (zoomOption.equals("width")) {
                                                                zoomStyle = "max-width: 100%;";
                                                        } else if (zoomOption.equals("height")) {
                                                                // see height of navbar + optionbar
                                                                zoomStyle = "max-height: calc(100% - 128px);";
+                                                               disabledZoomWidth = "";
+                                                               disabledZoomHeight = " disabled='disabled'";
                                                        }
                                                }
                                                content = String.format("" //
@@ -893,16 +915,16 @@ public class WebLibraryServer implements Runnable {
 
                                builder.append(String.format("" //
                                                + "<div class='bar navbar'>\n" //
-                                               + "\t<a class='button first' href='%s'>&lt;&lt;</a>\n"//
-                                               + "\t<a class='button previous' href='%s'>&lt;</a>\n"//
-                                               + "\t<a class='button next' href='%s'>&gt;</a>\n"//
-                                               + "\t<a class='button last' href='%s'>&gt;&gt;</a>\n"//
+                                               + "\t<a%s class='button first' href='%s'>&lt;&lt;</a>\n"//
+                                               + "\t<a%s class='button previous' href='%s'>&lt;</a>\n"//
+                                               + "\t<a%s class='button next' href='%s'>&gt;</a>\n"//
+                                               + "\t<a%s class='button last' href='%s'>&gt;&gt;</a>\n"//
                                                + "</div>\n" //
                                                + "%s", //
-                                               first, //
-                                               previous, //
-                                               next, //
-                                               last, //
+                                               disabledLeft, first, //
+                                               disabledLeft, previous, //
+                                               disabledRight, next, //
+                                               disabledRight, last, //
                                                content //
                                ));
 
@@ -918,12 +940,15 @@ public class WebLibraryServer implements Runnable {
 
                                if (paragraph > 0) {
                                        builder.append(String.format("" //
-                                                       + "\t<a class='button zoomreal'   href='%s'>REAL</a>\n"//
-                                                       + "\t<a class='button zoomwidth'  href='%s'>WIDTH</a>\n"//
-                                                       + "\t<a class='button zoomheight' href='%s'>HEIGHT</a>\n"//
+                                                       + "\t<a%s class='button zoomreal'   href='%s'>REAL</a>\n"//
+                                                       + "\t<a%s class='button zoomwidth'  href='%s'>WIDTH</a>\n"//
+                                                       + "\t<a%s class='button zoomheight' href='%s'>HEIGHT</a>\n"//
                                                        + "</div>\n", //
+                                                       disabledZoomReal,
                                                        uri + "?optionName=zoom&optionValue=real", //
+                                                       disabledZoomWidth,
                                                        uri + "?optionName=zoom&optionValue=width", //
+                                                       disabledZoomHeight,
                                                        uri + "?optionName=zoom&optionValue=height" //
                                        ));
                                }
@@ -1099,4 +1124,10 @@ public class WebLibraryServer implements Runnable {
                }
                builder.append(">").append(name).append("</option>\n");
        }
+
+       public static void main(String[] args) throws IOException {
+               Instance.init();
+               WebLibraryServer web = new WebLibraryServer(false);
+               web.run();
+       }
 }
index c520d78f2230fc2a8dad5e95f13f768f87f540d6..705006cf4ce91cb203103d24e36971d90b9ded2f 100644 (file)
@@ -1,9 +1,8 @@
 html, body, .main {
        margin: 0;
        padding: 0;
-       font-family : Verdana, "Bitstream Vera Sans", "DejaVu Sans", Tahoma, Geneva, Arial, Sans-serif;
+       font-family: Verdana, "Bitstream Vera Sans", "DejaVu Sans", Tahoma, Geneva, Arial, Sans-serif;
        font-size: 12px;
-       DISABLED_color: #635c4a;
        height: 100%;
 }
 
@@ -29,21 +28,21 @@ table {
 }
 
 .message {
-        background-color: #ddffdd;
-        border: 1px solid #88dd88;
-        clear: left;
-        border-radius: 5px;
-        padding: 5px;
-        margin: 10px;
+       background-color: #ddffdd;
+       border: 1px solid #88dd88;
+       clear: left;
+       border-radius: 5px;
+       padding: 5px;
+       margin: 10px;
 }
 
 .error {
-        background-color: #ffdddd;
-        border: 1px solid #dd8888;
-        clear: left;
-        border-radius: 5px;
-        padding: 5px;
-        margin: 10px;
+       background-color: #ffdddd;
+       border: 1px solid #dd8888;
+       clear: left;
+       border-radius: 5px;
+       padding: 5px;
+       margin: 10px;
 }
 
 /* all links and clickable should show a pointer cursor */
@@ -141,6 +140,11 @@ h3 {
        padding-bottom: 64px;
 }
 
+.viewer.img {
+       margin: auto;
+       display: block;
+}
+
 a.viewer.link:hover {
        background-color: transparent;
 }
@@ -155,7 +159,7 @@ a.viewer.link:hover {
 }
 
 .bar.optionbar {
-       bottom: 0;      
+       bottom: 0;
 }
 
 .bar.optionbar.s1 {
@@ -181,6 +185,13 @@ a.viewer.link:hover {
        margin: 5px;
 }
 
+.bar .button[disabled] {
+       pointer-events: none;
+       background-color: #aaa;
+       filter: grayscale(100%);
+       border-color: gray;
+}
+
 .bar .button:hover {
        background-color: bac2e1;
 }