User:Darklama/Main Page/tabstyle.js

function Tabbed_Navigation { // set initial state if (document.createStyleSheet) { var style = document.createStyleSheet; style.addRule(".contents", "display:none;"); style.addRule(".contents.selected", "display:block;"); } else { var head = document.getElementsByTagName("head")[0]; if (head) { var style = document.createElement("style"); style.setAttribute("type", "text/css"); style.appendChild(document.createTextNode(".contents { display: none; }")); style.appendChild(document.createTextNode(".contents.selected { display: block; }")); head.appendChild(style); } }  function Tabbed(id, update) { if (!id) return; var content_id = document.getElementById(id.substring(1)); if (content_id && hasClass(content_id.parentNode, "tabnav")) { for (var contents = content_id.parentNode.firstChild; contents != null; contents = contents.nextSibling) { if (hasClass(contents, "tabs")) { var links = contents.getElementsByTagName("a"); for (var i = 0; link = links[i]; i++) { if (link.hash && link.parentNode) { if (hasClass(link.parentNode, "selected")) link.parentNode.className = link.parentNode.className.replace(/ \bselected\b|\bselected\b ?/gi, "unselected"); else if (!hasClass(link.parentNode, "unselected")) link.parentNode.className = (link.parentNode.className ? " " : "") + "unselected"; if (link.hash == id) link.parentNode.className = link.parentNode.className.replace(/ \bunselected\b|\bunselected\b ?/gi, "selected"); }         }        } else if (hasClass(contents, "contents") && hasClass(contents, "selected")) { contents.className = contents.className.replace(/ \bselected\b|\bselected\b ?/gi, ""); }     }      content_id.className += (content_id.className ? " " : "") + "selected"; if (update) window.location.replace(id); } }  if (window.location.hash) Tabbed(window.location.hash); function Switch_Tab(e) {   if (!e) e = window.event; if (e.target.tagName != 'A' || !e.target.hash) return; if (e.preventDefault) e.preventDefault; else e.returnValue = false; Tabbed(e.target.hash, true) } var page = document.getElementById("bodyContent") || document.getElementById("article") || document.getElementById("content"); if (page) { var tree = page.getElementsByTagName("*"); for (var i=0; node=tree[i]; i++) { if (!hasClass(node, 'tabnav')) continue; node.onclick = Switch_Tab; if (!window.location.hash) { for (var contents = node.firstChild; contents != null; contents = contents.nextSibling) { if (hasClass(contents, "contents") && hasClass(contents, "selected")) { if (contents.id) Tabbed("#" + contents.id); break; }       }      }    }  } }

addLoadEvent(Tabbed_Navigation);