Mercurial > hg > mgallery
diff mgallery.js @ 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 | |
children | 606b05c31d5e |
line wrap: on
line diff
--- /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); +} + +