changeset 149:b4751909c48f

Move some Javascript code to a separate file and make the location configurable.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 06 Sep 2017 16:46:09 +0300
parents 0c8a8c0438bf
children 28a2b6e6b527
files example.cfg mgallery.inc.php mgallery.js mgallery.php
diffstat 4 files changed, 139 insertions(+), 126 deletions(-) [+]
line wrap: on
line diff
--- a/example.cfg	Wed Sep 06 16:42:42 2017 +0300
+++ b/example.cfg	Wed Sep 06 16:46:09 2017 +0300
@@ -20,6 +20,9 @@
 album_icon           = "/mgallery/album_sm.png"
 ;urchin_file         = "urchin.inc.php"
 
+; Relative path to Javascript files used by MGallery (mgallery.js)
+js_path              = "/mgallery/"
+
 ; Use image from sub-album as album cover image?
 ; If disabled, album_icon will be always used for cover image
 cover_images         = yes
--- a/mgallery.inc.php	Wed Sep 06 16:42:42 2017 +0300
+++ b/mgallery.inc.php	Wed Sep 06 16:46:09 2017 +0300
@@ -77,6 +77,7 @@
   "title_sep"        => [MG_STR, " - "],
   "page_info"        => [MG_STR, "<b>MGallery ".$mgProgVersion."</b> &copy; Copyright ".$mgProgCopyright],
   "css"              => [MG_STR, NULL],
+  "js_path"          => [MG_STR, NULL],
   "urchin_file"      => [MG_STR, FALSE],
 
   "global_flags"     => [MG_FLAGS, MGF_JAVASCRIPT | MGF_BREADCRUMBS | MGF_CAPTIONS, &$mgGFlags],
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mgallery.js	Wed Sep 06 16:46:09 2017 +0300
@@ -0,0 +1,130 @@
+//
+// Yet Another Image Gallery
+// -- Main Javascript utility functions file
+// Programmed and designed by Matti 'ccr' Hamalainen <ccr@tnsp.org>
+// (C) Copyright 2015-2017 Tecnic Software productions (TNSP)
+//
+
+
+function mgalAddEvent(evobj, evtype, evcallback)
+{
+  if (evobj == null || typeof(evobj) == 'undefined')
+    return;
+
+  if (evobj.addEventListener)
+    evobj.addEventListener(evtype, evcallback, false);
+  else
+  if (evobj.attachEvent)
+    evobj.attachEvent("on" + evtype, evcallback);
+  else
+    evobj["on"+evtype] = evcallback;
+};
+
+
+function mgalNavigateTo(url)
+{
+  if (url != "")
+    window.location = url;
+}
+
+
+function mgalProcessKeyPress(ev)
+{
+  ev = ev || window.event;
+  var key = ev.keyCode ? ev.keyCode : ev.which;
+  switch (key)
+  {
+    case 37:
+    case 65:
+    case 52:
+      // left
+      mgalNavigateTo(mgalPrevURL);
+      break;
+
+    case 39:
+    case 68:
+    case 54:
+      // right
+      mgalNavigateTo(mgalNextURL);
+      break;
+
+    case 38:
+    case 56:
+      // up
+      mgalNavigateTo(mgalUpURL);
+      break;
+
+    default:
+      return true;
+  }
+
+  ev.preventDefault();
+  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 mgalAdjustImageDo()
+{
+  var eimg = document.getElementById("imageImage");
+  var win = mgalGetWindowSize();
+  var madj = 0.92;
+  if (eimg)
+  {
+    if (eimg.width > eimg.height)
+    {
+      eimg.style.width = "100%";
+      eimg.style.height = "auto";
+      if (eimg.height > win[1] * madj)
+      {
+        eimg.style.width = "auto";
+        eimg.style.height = (win[1] * madj)+"px";
+      }
+    }
+    else
+    {
+      eimg.style.width = "auto";
+      if (eimg.height > win[1] * madj)
+        eimg.style.height = (win[1] * madj)+"px";
+      else
+        eimg.style.height = "100%";
+    }
+  }
+  adjustPID = -1;
+}
+
+
+function mgalAdjustImage()
+{
+  if (adjustPID == -1)
+    adjustPID = setTimeout(mgalAdjustImageDo, 50);
+}
+
+
--- a/mgallery.php	Wed Sep 06 16:42:42 2017 +0300
+++ b/mgallery.php	Wed Sep 06 16:46:09 2017 +0300
@@ -103,7 +103,7 @@
 
 function mgPrintPageHeader($pageTitle, $pageExtra = "")
 {
-  global $pageCSS, $pageCharset, $pageUrchin;
+  global $pageCSS, $pageCharset, $pageUrchin, $pageJSPath;
 
   echo
   "<!DOCTYPE html>\n".
@@ -111,6 +111,7 @@
   "<head>\n".
   "  <meta charset=\"".$pageCharset."\">\n".
   "  <meta http-equiv=\"Content-type\" content=\"text/html;charset=".$pageCharset."\">\n".
+  "  <script type=\"text/javascript\" src=\"".$pageJSPath."mgallery.js\"></script>\n".
   "  <title>".strip_tags($pageTitle)."</title>\n".
   $pageExtra;
 
@@ -455,6 +456,7 @@
 mgReadSettings();
 
 $pageCSS = mgGetSetting("css");
+$pageJSPath = mgGetSetting("js_path");
 $pageUrchin = mgGetSetting("urchin_file");
 $galBasePath = mgGetSetting("base_path");
 $galBaseURL = mgGetSetting("base_url");
@@ -584,6 +586,7 @@
 
   echo
     mgGetPageInfoHeaderEnd()."\n".
+    "<div id=\"pageInfoButton\">_</div>\n".
     "<div id=\"imageCBox\">\n".
     mgGetNaviControlImageBoxJS($galImagesIndex, $index, "prevBtm", -1)."\n".
     mgGetNaviControlImageBox($galImagesIndex, $index, "prev", -1)."\n".
@@ -612,138 +615,14 @@
       "var mgalNextURL = \"".($nextActive ? $nextURL : "")."\";\n".
       "var mgalUpURL = \"".mgGetURL($galData["path"], FALSE)."\";\n".
       "\n";
-
 ?>
-function mgalAddEvent(evobj, evtype, evcallback)
-{
-  if (evobj == null || typeof(evobj) == 'undefined')
-    return;
-
-  if (evobj.addEventListener)
-    evobj.addEventListener(evtype, evcallback, false);
-  else
-  if (evobj.attachEvent)
-    evobj.attachEvent("on" + evtype, evcallback);
-  else
-    evobj["on"+evtype] = evcallback;
-};
-
-
-function mgalNavigateTo(url)
-{
-  if (url != "")
-    window.location = url;
-}
-
-
-function mgalProcessKeyPress(ev)
-{
-  ev = ev || window.event;
-  var key = ev.keyCode ? ev.keyCode : ev.which;
-  switch (key)
-  {
-    case 37:
-    case 65:
-    case 52:
-      // left
-      mgalNavigateTo(mgalPrevURL);
-      break;
-
-    case 39:
-    case 68:
-    case 54:
-      // right
-      mgalNavigateTo(mgalNextURL);
-      break;
-
-    case 38:
-    case 56:
-      // up
-      mgalNavigateTo(mgalUpURL);
-      break;
-
-    default:
-      return true;
-  }
-
-  ev.preventDefault();
-  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 mgalAdjustImageDo()
-{
-  var eimg = document.getElementById("imageImage");
-  var win = mgalGetWindowSize();
-  var madj = 0.85;
-  if (eimg)
-  {
-    if (eimg.width > eimg.height)
-    {
-      eimg.style.width = "100%";
-      eimg.style.height = "auto";
-      if (eimg.height > win[1] * madj)
-      {
-        eimg.style.width = "auto";
-        eimg.style.height = (win[1] * madj)+"px";
-      }
-    }
-    else
-    {
-      eimg.style.width = "auto";
-      if (eimg.height > win[1] * madj)
-        eimg.style.height = (win[1] * madj)+"px";
-      else
-        eimg.style.height = "100%";
-    }
-  }
-  adjustPID = -1;
-}
-
-
-function mgalAdjustImage()
-{
-  if (adjustPID == -1)
-    adjustPID = setTimeout(mgalAdjustImageDo, 50);
-}
-
 
 mgalAddEvent(document.getElementById("imageImage"), "load", mgalAdjustImageDo);
 mgalAddEvent(window, "resize", mgalAdjustImage);
 mgalAddEvent(document, "keypress", mgalProcessKeyPress);
 adjustPID = -1;
-
+</script>
 <?
-    echo
-      "</script>\n";
   }
 }
 else