# HG changeset patch # User Matti Hamalainen # Date 1504705569 -10800 # Node ID b4751909c48f90e7f79872f2aacd9a43149ff698 # Parent 0c8a8c0438bf448959b82e7dd8397e942c7ec15e Move some Javascript code to a separate file and make the location configurable. diff -r 0c8a8c0438bf -r b4751909c48f example.cfg --- 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 diff -r 0c8a8c0438bf -r b4751909c48f mgallery.inc.php --- 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, "MGallery ".$mgProgVersion." © 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], diff -r 0c8a8c0438bf -r b4751909c48f mgallery.js --- /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 +// (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); +} + + diff -r 0c8a8c0438bf -r b4751909c48f mgallery.php --- 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 "\n". @@ -111,6 +111,7 @@ "\n". " \n". " \n". + " \n". " ".strip_tags($pageTitle)."\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". + "
_
\n". "
\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; - + \n"; } } else