diff mgallery.php @ 82:e0e5e5197bb8

Refactor for somewhat more mobile-bullshit-friendly style and usage.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 14 Sep 2016 23:00:04 +0300
parents 697846b47d17
children f13b05e4c896
line wrap: on
line diff
--- a/mgallery.php	Wed Sep 14 22:50:29 2016 +0300
+++ b/mgallery.php	Wed Sep 14 23:00:04 2016 +0300
@@ -577,18 +577,23 @@
     echo mgGetNaviControls($galImagesIndex, $index, $naviFlags);
 
   echo
-    "<div class=\"imageCBox\">\n".
+    "<div id=\"imageCBox\">\n".
+    mgGetNaviControlImageBox($galImagesIndex, $index, "prevBtm", -1).
     mgGetNaviControlImageBox($galImagesIndex, $index, "prev", -1).
     "<div class=\"imageBox\">\n".
-    "<a id=\"imageLink\" target=\"_blank\" href=\"".$galImageURL.$galPath."/".$galImage."\">".
-    "<img id=\"imageImage\" src=\"".mgGetImageURL($galTNPath, $data["base"].$galMedSuffix.$data["ext"])."\" alt=\"".chentities($data["base"].$galMedSuffix.$data["ext"])."\"></a>\n".
+//    "<a id=\"imageLink\" target=\"_blank\" href=\"".$galImageURL.$galPath."/".$galImage."\">".
+    "<img id=\"imageImage\" src=\"".mgGetImageURL($galTNPath, $data["base"].$galMedSuffix.$data["ext"])."\" alt=\"".chentities($data["base"].$galMedSuffix.$data["ext"])."\">".
+//    "</a>\n".
     "</div>\n".
+    mgGetNaviControlImageBox($galImagesIndex, $index, "nextBtm", 1).
     mgGetNaviControlImageBox($galImagesIndex, $index, "next", 1).
     "<div class=\"imageCaption\">".mgGetArr($data, "caption", "%1", "")."</div>\n".
+    "<a id=\"imageLink\" target=\"_blank\" href=\"".$galImageURL.$galPath."/".$galImage."\">".
     "<div class=\"infoBox\">\n".
     mgGetArr($data, "datetime", "<span class=\"infoDateTime\">%1</span>", "", "mgTimeStr").
     implode(", ", array_filter($list, function($a) { return $a !== NULL; })).
-    "</div>\n".
+    "</div>".
+    "</a>\n".
     "</div>\n";
 
   if ($naviFlags & GNAV_BOTTOM)
@@ -605,6 +610,7 @@
       "var mgalNextURL = \"".($nextActive ? $nextURL : "")."\";\n".
       "var mgalExpanded = false;\n".
       "\n";
+
 ?>
 function mgalAddEvent(evobj, evtype, evcallback)
 {
@@ -656,6 +662,64 @@
   return false;
 }
 
+
+function mgalGetWindowSize()
+{
+  var winW = 0, winH = 0;
+  if (typeof(window.innerWidth) == 'number')
+  {
+    // Non-MSIE
+    winW = window.innerWidth;
+    winH = window.innerHeight;
+  }
+  else
+  if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight))
+  {
+    // MSIE 6+ in 'standards compliant mode'
+    winW = document.documentElement.clientWidth;
+    winH = document.documentElement.clientHeight;
+  }
+  else
+  if (document.body && (document.body.clientWidth || document.body.clientHeight))
+  {
+    // MSIE 4 compatible
+    winW = document.body.clientWidth;
+    winH = document.body.clientHeight;
+  }
+
+  return [winW, winH];
+}
+
+
+function mgalAdjustImage()
+{
+  var eimg = document.getElementById("imageImage");
+  var win = mgalGetWindowSize();
+  var madj = 0.85;
+  if (eimg)
+  {
+    if (eimg.width > eimg.height)
+    {
+      eimg.style.width = "100%";
+      if (eimg.height > win[1] * madj)
+      {
+        eimg.style.width = "auto";
+        eimg.style.height = (win[1] * madj)+"px";
+      }
+    }
+    else
+    {
+      if (eimg.height > win[1] * madj)
+        eimg.style.height = (win[1] * madj)+"px";
+      else
+        eimg.style.height = "100%";
+    }
+  }
+}
+
+
+mgalAddEvent(document.getElementById("imageImage"), "load", mgalAdjustImage);
+mgalAddEvent(window, "resize", mgalAdjustImage);
 mgalAddEvent(document, "keypress", mgalProcessKeyPress);
 
 <?