User:Minesweeper.007/wikitabs.js

// User:Quarl/wikitabs.js (formerly User:Quarl/addlilink.js)

// depends: wikitabs.css

// originally based on // http://en.wikipedia.org/wiki/Wikipedia:WikiProject_User_scripts/Scripts/Add_LI_link

//

var wikitabs = new Object;

wikitabs.getPortlet = function(n) { return document.getElementById(n).getElementsByTagName('ul')[0]; }

wikitabs.getPortletPersonal = function { return wikitabs.getPortlet('p-personal'); } wikitabs.getPortletTabActions = function { return wikitabs.getPortlet('p-cactions'); } wikitabs.getPortletNavigation = function { return wikitabs.getPortlet('p-navigation'); } wikitabs.getPortletToolbox = function { return wikitabs.getPortlet('p-tb'); }

wikitabs.addTab = function(url, name, id, title, key) { return wikitabs.addLiLink(wikitabs.getPortletTabActions, url, name, id, title, key); }

wikitabs.addToolboxLink = function(url, name, id, title, key) { return wikitabs.addLiLink(wikitabs.getPortletToolbox, url, name, id, title, key); }

wikitabs.addNavigationLink = function(url, name, id, title, key) { return wikitabs.addLiLink(wikitabs.getPortletNavigation, url, name, id, title, key); }

// add a node at a location. If it's a regular node, then append to location // as parent. If it's {after:node}, then insert after node. wikitabs._fancyAdd = function(location, newNode) { if (location['after']) { var after = location['after']; if (after.nextSibling) { after.parentNode.insertBefore(newNode, after.nextSibling); } else { after.parentNode.appendChild(newNode); }   } else { location.appendChild(newNode); } }

wikitabs.addLiLinkX = function(location, entry, id, title, key){ var li = document.createElement('li'); if(id) li.id = id; if (typeof(entry) == 'string') { li.innerHTML = entry; } else { li.appendChild(entry); }

wikitabs._fancyAdd(location, li);

if(id && (key || title) && window.ta) { ta[id] = [(key||), (title||)]; }   // re-render the title and accesskeys from existing code in wikibits.js    akeytt; return li; }

wikitabs.addLiLink = function(parent, url, name, id, title, key){ var na = document.createElement('a'); na.href = url; na.appendChild(document.createTextNode(name)); return wikitabs.addLiLinkX(parent, na, id, title, key); }

wikitabs._toggleMenu = function { var mn = this.nextSibling; if (!mn || typeof(mn.displayState) != 'boolean') { alert("## invalid target for wikitabs._toggleMenu (error f66282ae-0762-4c90-8b5d-f095909cb786)"); return; }

if ( (mn.displayState = !mn.displayState) ) { // new state: display mn.className += ' sticky'; } else { // new state: hide mn.className = mn.className.replace(/(^| )sticky/, ''); } }

wikitabs.addTabMenu = function(name, id) {   var parent = wikitabs.getPortletTabActions;

var na = document.createElement('a'); na.href = 'javascript:void(0)'; na.appendChild(document.createTextNode(name)); na.onclick = wikitabs._toggleMenu;

var mn = document.createElement('ul'); mn.displayState = false;

var li = document.createElement('li'); li.id = id; li.className = 'tabmenu'; li.appendChild(na); li.appendChild(mn); parent.appendChild(li); return mn; }

// deprecated aliases getTabActions = wikitabs.getPortletTabActions; getToolbox = wikitabs.getPortletToolbox; getNavigationBox = wikitabs.getPortletNavigation; addlilink = wikitabs.addLiLink; addlilinkX = wikitabs.addLiLinkX; addTab = wikitabs.addTab; addToolboxLink = wikitabs.addToolboxLink; addNavigationLink = wikitabs.addNavigationLink;

//