From 6854cb3f4d8219cf1829e32122eb2502a916eae9 Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Sat, 1 Feb 2020 09:05:48 +0100 Subject: initial checkin --- js/tabs.js | 148 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 148 insertions(+) create mode 100644 js/tabs.js (limited to 'js/tabs.js') diff --git a/js/tabs.js b/js/tabs.js new file mode 100644 index 0000000..58828a7 --- /dev/null +++ b/js/tabs.js @@ -0,0 +1,148 @@ +/* + * $Id$ + */ +addEvent(window, "load", initTabs); +function addEvent(elm, evType, fn, useCapture) +// addEvent and removeEvent +// cross-browser event handling for IE5+, NS6 and Mozilla +// By Scott Andrew +{ + if (elm.addEventListener){ + elm.addEventListener(evType, fn, useCapture); + return true; + } else if (elm.attachEvent){ + var r = elm.attachEvent("on"+evType, fn); + return r; + } else { + alert("Handler could not be removed"); + } +} + +var _TAB_DIVS; + +// tabs handling {{{ +// show tab with given id +function showTabById(tabid, noEval) { // {{{ + var divs = document.getElementsByTagName('div'); + var tab = document.getElementById(tabid); + var submenu = document.getElementById('submenu'); + var i; + var el = document.getElementById(tabid + "taba"); + + if (!noEval && el) { + eval(el.getAttribute('onmousedown')); + } + for (i=0; i -1)) { + //divs[i].style.display = 'none'; + if (divs[i].className && (divs[i].className.indexOf(' active') > -1)) { + divs[i].className = divs[i].className.substr(0, divs[i].className.length-7); + } + } + } + + if (tab) { + //tab.style.display = 'block'; + tab.className = tab.className +' active'; + + if (submenu) { + var links = submenu.getElementsByTagName('a'); + for (i=0; i= targets.length) { + number = targets.length-1; + } + showTabById(targets[number]); +} // }}} + +// get list of all DIVs that contain tabs +function getTabDivs() {/*{{{*/ + if (_TAB_DIVS == null) { + _TAB_DIVS = new Array(); + var divs = document.getElementsByTagName('div'); + var i; + for (i=0; i -1)) { + _TAB_DIVS[_TAB_DIVS.length] = divs[i]; //array[array.length]= same as .push, but IE-compatible. + } + } + } + return _TAB_DIVS; +}/*}}}*/ + +// tabs init +// show first tab or tab with given name (string after #) +function initTabs() {/*{{{*/ + var target = location.href.substring(location.href.indexOf('#')+1); + if (target.match(/comment/)) { + target = "comments"; + } + + makeTabLinks(); + + if (target && document.getElementById(target) && document.getElementById(target).className == 'tab') { + showTabById(target); + } else { + showTabByNumber(0); + } + var history = document.getElementById('history'); + if (history) { + addEvent(history,'click',uglyHistoryCommentFix); + } + +}/*}}}*/ +function uglyHistoryCommentFix(e) { + var target = e.target || window.event.srcElement; + if ('A' == target.nodeName) { + var re= /#comments/; + if (re.test(target.href)) { + showTabById('comments'); + } + } + var history = document.getElementById('history'); + if (history) { + addEvent(history,'click',uglyHistoryCommentFix); + } +} +// }}} + +// }}} + +// vim:enc=utf-8:fenc=utf-8:fdm=marker -- cgit v1.2.3-70-g09d2