Mercurial > hg > mgallery
diff mgallery.php @ 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 | 6c1467fe7d5c |
children | 28a2b6e6b527 |
line wrap: on
line diff
--- 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