Mercurial > hg > batmud > maputils
changeset 1516:f2b2e7441e3c
Indentation & cosmetics.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sun, 08 Feb 2015 22:06:12 +0200 |
parents | 677002de7795 |
children | 9d048902f06b |
files | maps/util.js |
diffstat | 1 files changed, 69 insertions(+), 58 deletions(-) [+] |
line wrap: on
line diff
--- a/maps/util.js Sun Feb 08 20:03:42 2015 +0200 +++ b/maps/util.js Sun Feb 08 22:06:12 2015 +0200 @@ -4,84 +4,95 @@ var currLoc = ""; // This function was stolen from http://www.quirksmode.org/js/findpos.html -function findPos(obj) { - var curleft = curtop = 0; +function findPos(obj) +{ + var curleft = curtop = 0; - if (obj.offsetParent) { - curleft = obj.offsetLeft; - curtop = obj.offsetTop; - while (obj = obj.offsetParent) { - curleft += obj.offsetLeft; - curtop += obj.offsetTop; - } - } + if (obj.offsetParent) + { + curleft = obj.offsetLeft; + curtop = obj.offsetTop; + while (obj = obj.offsetParent) + { + curleft += obj.offsetLeft; + curtop += obj.offsetTop; + } + } - return [curleft,curtop]; + return [curleft, curtop]; } function gotoElem(obj) { - 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; - } + 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; + } - c = findPos(obj); - window.scrollTo(c[0]-(winW/2), c[1]-(winH/2)); + c = findPos(obj); + window.scrollTo(c[0]-(winW/2), c[1]-(winH/2)); } function gotoOnLoadPos() { - var s = window.location.href; - if (s.indexOf("#") >= 0) { - var n = unescape(s.substr(s.indexOf("#")+1).toLowerCase()); - var e = document.getElementById(n); - if (e) { - e.style.background = "red"; - gotoElem(e); - currLoc = n; - } - } + var s = window.location.href; + if (s.indexOf("#") >= 0) + { + var n = unescape(s.substr(s.indexOf("#")+1).toLowerCase()); + var e = document.getElementById(n); + if (e) + { + e.style.background = "red"; + gotoElem(e); + currLoc = n; + } + } } function gotoPos() { - var newLoc = document.forms[0].slocation.value; - if (currLoc != newLoc) { - var e = document.getElementById(newLoc); - if (e) { - e.style.background = "red"; - e.style.color = "black"; - gotoElem(e); - var e = document.getElementById(currLoc); - if (e) { - e.style.background = "white"; - } - currLoc = newLoc; - } - } + var newLoc = document.forms[0].slocation.value; + if (currLoc != newLoc) + { + var e = document.getElementById(newLoc); + if (e) + { + e.style.background = "red"; + e.style.color = "black"; + gotoElem(e); + var e = document.getElementById(currLoc); + if (e) + { + e.style.background = "white"; + } + currLoc = newLoc; + } + } } + function toggleLabels() { - var labVis = document.forms[0].shide.checked; - if (document.all) { - var cl = document.styleSheets[0].rules[0]; - } else { - var cl = document.styleSheets[0].cssRules[0]; - } - cl.style.visibility = labVis ? "visible" : "hidden"; + var cl = document.all ? document.styleSheets[0].rules[0] : document.styleSheets[0].cssRules[0]; + cl.style.visibility = document.forms[0].shide.checked ? "visible" : "hidden"; }