Mercurial > hg > mgallery
view mgallery.js @ 313:d94b0ebe97c6
Add some commented out / unused example code in mgParseXMPData().
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 06 Apr 2020 18:37:49 +0300 |
parents | 548a349bc015 |
children | ffcd1225e85c |
line wrap: on
line source
// // Yet Another Image Gallery // -- Main Javascript utility functions file // Programmed and designed by Matti 'ccr' Hamalainen <ccr@tnsp.org> // (C) Copyright 2015-2018 Tecnic Software productions (TNSP) // function mgalAddEventOb(obname, evobj, evtype, evcallback) { if (evobj == null || typeof(evobj) == 'undefined') { console.log("Event object '"+ obname +"' == null."); return; } if (evobj.addEventListener) evobj.addEventListener(evtype, evcallback, false); else if (evobj.attachEvent) evobj.attachEvent("on"+evtype, evcallback); else evobj["on"+evtype] = evcallback; } function mgalAddEventsToClass(clname, evtype, evcallback) { var elist = document.getElementsByClassName(clname); for (var index = 0; index < elist.length; index++) { mgalAddEventOb(clname, elist[index], evtype, evcallback); } } function mgalAddEvent(obname, evtype, evcallback) { mgalAddEventOb(obname, document.getElementById(obname), evtype, evcallback); } function mgalNavigateTo(url) { if (url != "") window.location = url; } function mgalProcessKeyPress(evt) { evt = evt || window.event; var key = evt.keyCode ? evt.keyCode : (evt.charCode ? evt.charCode : evt.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; } evt.preventDefault(); return false; } function mgalGetElementOrWindowSize(nelem) { if (nelem) { var elem = document.getElementById(nelem); if (elem) return [elem.clientWidth, elem.clientHeight]; } if (typeof(window.innerWidth) == 'number') { // Non-MSIE return [window.innerWidth, window.innerHeight]; } if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) { // MSIE 6+ in 'standards compliant mode' return [document.documentElement.clientWidth, document.documentElement.clientHeight]; } if (document.body && (document.body.clientWidth || document.body.clientHeight)) { // MSIE 4 compatible return [document.body.clientWidth, document.body.clientHeight]; } return null; } function mgalAdjustImageDo() { var eimg = document.getElementById("imageImage"); var ewin = mgalGetElementOrWindowSize("pageImageBox"); var madj = 0.99; if (eimg && ewin != null) { if (eimg.width > eimg.height) { eimg.style.width = "100%"; eimg.style.height = "auto"; if (eimg.height > ewin[1] * madj) { eimg.style.width = "auto"; eimg.style.height = (ewin[1] * madj)+"px"; } } else { eimg.style.width = "auto"; eimg.style.height = "100%"; if (eimg.height > ewin[1] * madj) eimg.style.height = (ewin[1] * madj)+"px"; } } adjustPID = -1; } function mgalAdjustImage() { if (adjustPID == -1) adjustPID = setTimeout(mgalAdjustImageDo, 10); } function mgalDisplayInfo(mvstate) { var mvbut = document.getElementById("pageInfoButton"); var mvnbut = document.getElementById("pageUpNaviButton"); var mvinfo = document.getElementById("pageInfoHeader"); var mviinfo = document.getElementById("infoBox"); mvinfo.style.display = mvstate ? "block" : "none"; if (window.getComputedStyle(mviinfo).opacity == 1) mviinfo.style.display = mvstate ? "block" : "none"; mvbut.style.display = !mvstate ? "block" : "none"; mvnbut.style.display = !mvstate ? "block" : "none"; mvInfoOpen = mvstate; } function mgalOpenInfo() { mgalDisplayInfo(true); } function mgalCloseInfo() { mgalDisplayInfo(false); } function mgalPreventDefault(ev) { ev.preventDefault(); ev.target.click(); } var mgalTouchX = null, mgalTouchY = null; function mgalTouchStart(evt) { mgalTouchX = evt.touches[0].clientX; mgalTouchY = evt.touches[0].clientY; } function mgalTouchMove(evt) { if (mgalTouchX != null && mgalTouchY != null && evt) { var deltaX = mgalTouchX - evt.touches[0].clientX; var deltaY = mgalTouchY - evt.touches[0].clientY; if (Math.abs(deltaX) > Math.abs(deltaY)) { if (deltaX < 0) mgalNavigateTo(mgalPrevURL); else mgalNavigateTo(mgalNextURL); } } mgalTouchX = mgalTouchY = null; }