User:KingAragorn/common.js

function replaceSearchIcon {   var innerDiv;

var searchbox = document.getElementById('searchBody');

if(searchbox) {       // monobook

innerDiv = searchbox.getElementsByTagName('div')[0]; var link = innerDiv.getElementsByTagName('a')[0];

if(link) innerDiv.removeChild(link); }   else {       // smoke

innerDiv = document.getElementById('WidgetSearch_1_content'); }   var loader = new ContentLoader; loader.div = innerDiv; loader.callback = onSearchIconsArrival; loader.send('/index.php?title=Template:Searchicons&action=raw'); }

function rand(n) {   return Math.round(Math.random * n); }

function onSearchIconsArrival {   // macbre: fixing "this.div" has no properties bug if (!this.div) { return; }

var lines = this.text.split('\n'); var line = lines[rand(lines.length - 1)]; var pos = line.indexOf(' '); var link = document.createElement('div'); //   link.href = '/index.php?title=Special:Search&adv=1'; link.id = 'search-icon-wrapper'; var img = document.createElement('img'); img.alt = 'Search'; img.src = (pos == -1) ? line : line.substring(0, pos); link.appendChild(img); this.div.insertBefore(link, this.div.firstChild);

var div = document.createElement('div'); div.id = 'search-popup'; div.style.display = 'none'; var ul = document.createElement('ul'); var li; var a;

li = document.createElement('li'); a = document.createElement('a'); a.href = '/index.php?title=Special:Search&adv=1'; a.appendChild(document.createTextNode('Advanced search')); li.appendChild(a); ul.appendChild(li); li = document.createElement('li'); a = document.createElement('a'); a.href = (pos == -1) ? 'javascript:emptySearchDesc' : '/wiki/' + line.substring(pos + 1); a.appendChild(document.createTextNode("What's this? (" + ((pos == -1) ? 'NO DESCRIPTION' : line.substring(pos + 1)) + ')')); li.appendChild(a); ul.appendChild(li);

li = document.createElement('li'); a = document.createElement('a'); a.href = 'javascript:closeSearchPopup'; a.appendChild(document.createTextNode("Close")); li.appendChild(a); ul.appendChild(li);

var container = document.getElementById('globalWrapper'); if(!container) container = document.getElementById('container');

div.appendChild(ul); container.appendChild(div);

link.onclick = openSearchPopup; }

function openSearchPopup(event) {   var div = document.getElementById('search-popup'); var e = event || window.event; div.style.display = (div.style.display == 'none') ? 'block' : 'none'; div.style.left = e.clientX + 'px'; div.style.top = (e.clientY + document.documentElement.scrollTop) + 'px'; }

function closeSearchPopup {   document.getElementById('search-popup').style.display = 'none'; }

function emptySearchDesc {   alert('No description exists for this search icon. Please contact the administrators to resolve this problem.'); }

// Reskin parser script from Uncyclopedia:MediaWiki:Uncyclopedia.js skinjs = { "Logout": "Logout.js" }

var re = RegExp("(.*) - Wookieepedia, the Star Wars Wiki"); var matches = re.exec(document.title);

var skinNamejs;

if (matches) { if (skinjs[matches[1]] != undefined) { skinNamejs = (skinjs[matches[1]].length > 0) ? skinjs[matches[1]] : matches[1] + '.js'; document.write(' '); } }

function fixSearch {   var button = document.getElementById('searchSubmit');

if(button) button.name = 'go'; }

//addOnloadHook(loadFunc);

YAHOO.util.Event.onDOMReady(loadFunc);

//