User:Lirmont/tooltip.js

// Ignore this for now. // See Help:Tooltips

// AJAX RC page list ajaxPages = "Special:RecentChanges,";

// error handling window.onerror = handleError;

function handleError(msg,url,l) { if (wgUserName == "Lirmont") { // would be nice if user script loaded first if (document.getElementById("jsErrors") == null) { errorTa = document.createElement("textarea"); errorTa.id = "jsErrors"; document.getElementById("bodyContent").appendChild(errorTa); } errorText="Error: " + msg + "\n"; if (typeof(url) != "undefined") errorText+="URL: " + url + "\n"; if (typeof(l) != "undefined") errorText+="Line: " + l + "\n\n"; document.getElementById("jsErrors").innerHTML += errorText + "\n\n"; } return true; }

// old JS loader script for backwards-compliance loadedJS = {}; function loadJS(page, rv) { if (loadedJS[page]) return; loadedJS[page] = true; var url = wgScriptPath+'/index.php?title='+encodeURIComponent(page.replace(/ /g,'_'))+'&action=raw&ctype=text/javascript&oldid='+rv; var scriptElem = document.createElement('script'); scriptElem.setAttribute('src',url); scriptElem.setAttribute('type','text/javascript'); document.getElementsByTagName('head')[0].appendChild(scriptElem); }

// default setting to turn tooltips on var tooltipsOn = (getCookie("tooltips-0")=="off")?false:true;

// individual tooltip controls, defaulted to on var itemTooltips = (getCookie("tooltips-1")=="off")?false:true; var npcTooltips = (getCookie("tooltips-2")=="off")?false:true; var questTooltips = (getCookie("tooltips-3")=="off")?false:true; var coordTooltips = (getCookie("tooltips-4")=="off")?false:true; var quickTooltips = (getCookie("tooltips-5")=="off")?false:true; var scTooltips = (getCookie("tooltips-6")=="off")?false:true; var flightPoints = true; var tableData = true; var achievementTooltips = true;

// override cookie management of AJAX RC enablement var ajaxRCOverride = false;

// use Special:Preferences to configure options var showPrefsPanel = true;

// adds options to Special:Preferences

function toggleTooltips(ttSelect, whichWay) { ttOnOrOff = (whichWay)?"on":"off"; setCookie("tooltips-" + ttSelect,ttOnOrOff,30); }

function setText(elem, value){ if (typeof(elem.textContent) != "undefined") { elem.textContent = value; } else { elem.innerText = value; } }

function getTip(tipType) { if (typeof(tipType) == "undefined" || tipType == 0) return document.getElementById("tfb"); if (typeof(tipType) == "object") return tipType; if (tipType == 1) return document.getElementById("templatetfb"); if (tipType == 2) return document.getElementById("coordstfb"); }

function extDBChange { setCookie("extDB", document.getElementById("wwExtDB").value, 30); }

function genTooltipToggle(labelText, indexNum) { return ' ' + labelText + ':  On  Off  \n'; }

function genExtDBOption(optURL, optName) { return '\n'+optName+' '; } function findUnusedPrefPaneId { var minid = 9; while (document.getElementById("prefsection-" + minid) != null) minid++; return minid; } function addPrefs { if (getCookie("extDB")) { dbSite = getCookie("extDB"); } else { dbSite = "http://wiki.ffxiclopedia.org/"; } newListEntry = document.createElement("li"); newFieldLink = document.createElement("a"); newFieldLink.secid = "prefsection-" + findUnusedPrefPaneId; newFieldLink.setAttribute("href", "#" + newFieldLink.secid); newFieldLink.onclick = newFieldLink.onmousedown = uncoversection; setText(newFieldLink,"Tooltips"); newListEntry.insertBefore(newFieldLink, newListEntry.lastChild); document.getElementById("mw-preferences-form").childNodes[0].appendChild(newListEntry); prefFields = document.getElementsByTagName("fieldset"); newField = document.createElement("fieldset"); newField.style.display = "none"; newField.setAttribute("class", "prefsection"); newField.setAttribute("id", newFieldLink.secid); newLegend = document.createElement("legend"); newLegend.setAttribute("class", "mainLegend"); setText(newLegend,"Tooltips"); fieldsParent = prefFields[prefFields.length - 1].parentNode; newField.insertBefore(newLegend, newField.firstChild); newField.innerHTML += 'Changes in this section are saved to cookies immediately. They will persist on your local computer for 30 days. '; newFieldBuffer = " "; fieldsParent.insertBefore(newField, prefFields[prefFields.length - 1].nextSibling);

for (x=0;x<=6;x++) { if (getCookie("tooltips-" + x)) { if (getCookie("tooltips-" + x) == "off") { document.getElementById("wwTooltips-" + x + "-Off").checked = true; } else { document.getElementById("wwTooltips-" + x + "-On").checked = true; } } else { document.getElementById("wwTooltips-" + x + "-On").checked = true; } } document.getElementById("wwExtDB").value = dbSite; }

// core variables var ttDebug = false; var ctn = ""; var noCache = false; ttBgStyle = "background-color:black;"; if (wgServer == "http://wiki.ffxiclopedia.org/") ttBgStyle = "background: transparent;"; //url(http://images1.wikia.nocookie.net/wowwiki/images/thumb/c/c0/Ttbackground.svg/275px-Ttbackground.svg.png) var ttHTMLStart = ''; var ttCoordStart = ''; var crlf = new RegExp("\r\n", "g"); var ttLoading = ttHTMLStart + "Loading... Please wait. "; var pagename = new Array;

// prototype functions function $A(a) { var r = []; for (var i = 0, len = a.length; i < len; ++i) r.push(a[i]); return r; }

Function.prototype.bind = function { var __method = this, args = $A(arguments), object = args.shift; return function { return __method.apply(object, args.concat($A(arguments))) }; }

// browser-independent textContent function getText(elem) { if (typeof(elem.textContent) != "undefined") return elem.textContent; return elem.innerText; }

function setText(elem, value){ if (typeof(elem.textContent) != "undefined") { elem.textContent = value; } else { elem.innerText = value; } }

// browser-independent cssFloat function getFloat(elem) { if (typeof(elem.style.cssFloat) != "undefined") return elem.style.cssFloat; return elem.style.styleFloat; }

// Empty variables to hold the mouse position and the window size var mousePos = null; var winSize = null;

// Set events to catch mouse position and window size document.onmousemove = mouseMove; window.onresize = windowResize;

// The mouseMove and mouseCoords function track the mouse position for us function mouseMove(ev) { ev = ev || window.event; mousePos = mouseCoords(ev); }

function getDBC { dbc = new Array; docBase = document.documentElement || document.body; dbc[0] = docBase.clientWidth || 0; dbc[1] = docBase.clientHeight || 0; return dbc; }

function getDBS { dbs = new Array; docBase = document.documentElement || document.body; dbs[0] = docBase.scrollLeft || 0; dbs[1] = docBase.scrollTop || 0; return dbs; }

function mouseCoords(ev) { if (ev.pageX || ev.pageY) return {x:ev.pageX, y:ev.pageY}; dbS = getDBS; return {x:ev.clientX + dbS[0], y:ev.clientY + dbS[1]}; }

// returns error function ttError(type) { extraText = ""; noCache = true; if (type == "NPC") extraText = " A correctly formatted {" + "{npcbox}" + "} must be added to the target NPC page."; return ttHTMLStart + "Error This " + type + " either has no tooltip or was not intended to have one." + extraText + " "; }

// The windowResize function keeps track of the window size for us function windowResize { dbC = getDBC; winSize = {x:(dbC[0])? dbC[0]:window.innerWidth, y:(dbC[1])? dbC[1]:window.innerHeight} }

//Determine what XmlHttpRequest object we will use. function getXmlHttpRequestObject { if (window.XMLHttpRequest) { return new XMLHttpRequest; //Not Internet Explorer } else if(window.ActiveXObject) { return new ActiveXObject("Microsoft.XMLHTTP"); //Internet Explorer } else { //fail silently } }

var getRequest = getXmlHttpRequestObject;

// hides the tooltip, stops any request function hideTip(tipType) { if (typeof(tipType) != "undefined" && tipType != 0) { hideTipNonCache(tipType); } else { if (ctn == "") { getRequest.onreadystatechange = function {} getRequest.abort; var tip = getTip; tip.innerHTML = ""; } else { var tip = document.getElementById(ctn); ctn = ""; } tip.style.display = "none"; } }

// hides the tip, doesn't stop a request function hideTipNonCache(tipType) { var tip = getTip(tipType); if (tip == null || typeof(tip.style) == "undefined") tip = document.getElementById("tfb"); if (typeof(tip.style) == "undefined") return false; tip.innerHTML = ""; tip.style.display = "none"; }

// begins AJAX request function getInfo(pgname, type) { cacheName = pgname + "-cache"; if (document.getElementById(cacheName)) { displayCacheTip(cacheName); } else { pnArr = pagename.length; pagename[pnArr] = pgname; //Checks to see if XmlHttpRequest object is ready. if (getRequest.readyState == 4 || getRequest.readyState == 0) { if (type==1 || type==10) { getRequest.open("GET", "http://" + location.hostname + "/api.php?action=parse&prop=text&text=&format=json", true); } else { getRequest.open("GET", "http://" + location.hostname + "/" + pgname + '?action=render', true); } if (type>1 && type != 10) { getRequest.onreadystatechange = function { pt(type,new Array(pgname, pnArr)); } } else { showTT = 1; if (pgname.indexOf("#") != -1) showTT = pgname.substr(pgname.indexOf("#")+1); if (type==1) { getRequest.onreadystatechange = function { parseText(new Array(pgname, pnArr, showTT)); } } else { getRequest.onreadystatechange = function { parseAchText(new Array(pgname, pnArr, showTT)); } } } }

//Makes the request. getRequest.send(null); } }

// switcher for the various parsing functions function pt(type, tArr) { ttF = new Array("","","Set","SC","Quest","NPC"); eval("parse"+ttF[type]+"Text(tArr);"); }

// displays the tooltip function displayTip(tipType) { var tip = (typeof(tipType)=="object")?tipType:getTip(tipType); tip.style.position = "absolute"; tip.style.visibility = "hidden"; tip.style.display = "block"; tip.style.zIndex = "999"; moveTip(tip); tip.style.visibility = "visible"; }

// displays an already-cached tooltip function displayCacheTip(cachename) { ctn = cachename; displayTip(document.getElementById(ctn)); }

// creates a cache for tooltips function createCache(cpagename, pnArr) { if (!noCache) { if (cpagename == pagename[pnArr]) { cacheDiv = document.createElement("div"); cacheDiv.setAttribute("id", cpagename + "-cache"); cacheDiv.style.display = "none"; contentstart.insertBefore(cacheDiv, contentstart.childNodes[0]); var tip = document.getElementById('tfb'); cacheDiv.innerHTML = tip.innerHTML; } } }

// This function moves the tool-tips when our mouse moves function moveTip(tipType) { cacheTip = null; skinAdjust = new Array; dbS = getDBS; if (typeof(this)=="object" && this != window) { var ttLink = this.parentNode; if (hasClass(this, "itemlink")) { if (hasClass(this, "pdlink")) ttLink = this.childNodes[1].childNodes[0]; tempName = ttLink.getAttribute("href").replace("http://","").replace("wiki.","").replace("ffxiclopedia.org","").replace("/wiki","").replace("/index.php?title=", "").replace("&amp;action=edit", "").replace("/","").replace(/_/g," "); } else { tempName = this.parentNode.getAttribute("title") || ttLink.lastChild.getAttribute("title"); } if (document.getElementById(tempName+"-cache")) cacheTip = document.getElementById(tempName+"-cache"); } tip = (cacheTip != null)?cacheTip:(typeof(tipType)=="object")?tipType:getTip(tipType); if (tip == null || typeof(tip.style) == "undefined") tip = document.getElementById("tfb"); if (document.getElementById("tfb").style.display != "none") tip = document.getElementById("tfb"); coAdjust=(tip.getAttribute("id")=="coordstfb")?50:0; var newTop = mousePos.y - (tip.clientHeight + 40); if (skin == "monaco") { skinAdjust[0] = (tip.clientWidth / 1.5) - coAdjust; skinAdjust[1] = (tip.clientWidth > 300)?(1.5 * tip.clientWidth):(2 * tip.clientWidth) - coAdjust; } else { skinAdjust[0] = (tip.clientWidth / 2) - coAdjust; skinAdjust[1] = (tip.clientWidth > 300)?(1.35 * tip.clientWidth):(1.85 * tip.clientWidth) - coAdjust; } var newLeft = mousePos.x - skinAdjust[0] + 11; if ((newTop < dbS[1]) || (document.getElementById("adSpace0") && (mousePos.y - tip.clientHeight - 200) < 0)) { newTop = mousePos.y + 1; if (newTop + tip.clientHeight > winSize.y) newTop = dbS[1]; } if (newLeft < dbS[0]) newLeft = dbS[0]; if ((mousePos.x + skinAdjust[0]) >= winSize.x - 150) newLeft = mousePos.x - skinAdjust[1]; tip.style.top = newTop + "px"; tip.style.left = newLeft + "px"; }

// getting the browser ready to accept what we're going to do windowResize; var contentstart;

// AJAX RC variables getRCDataRO = getXmlHttpRequestObject; var cr = new RegExp("\r", "gm"); var lf = new RegExp("\n", "gm"); var endText = new RegExp(' [\t\s]*?[\t\s]*? ', "mi"); var rcTimer; var rcTO; var rcTOs = 0; var doRefresh = true; var rcRefresh = 60000; ajaxRCCookie = (getCookie("ajaxload-"+wgPageName)=="on"||ajaxRCOverride) ? true:false; function ajaxRC { document.getElementsByTagName("h1")[0].innerHTML += ' AJAX:   '; document.getElementById("ajaxRCtoggle").checked = ajaxRCCookie; if (ajaxRCCookie) loadRCData; }

function toggleRC { if (document.getElementById("ajaxRCtoggle").checked == true) { setCookie("ajaxload-"+wgPageName, "on", 30); doRefresh = true; loadRCData; } else { setCookie("ajaxload-"+wgPageName, "off", 30); doRefresh = false; clearTimeout(rcTimer); } }

function loadRCData { if (getRCDataRO.readyState == 4 || getRCDataRO.readyState == 0) { getRCDataRO.open("GET", "http://" + location.hostname + "/" + wgPageName + location.search, true); getRCDataRO.onreadystatechange = parseRCdata; getRCDataRO.send(null); rcTO = setTimeout("timeOut;", 30000); } }

function timeOut { getRCDataRO.onreadystatechange = function {} getRCDataRO.abort; if (rcTOs < 3) { rcTOs++; loadRCData; } else { document.getElementById("ajaxRCtoggle").checked = false; document.getElementById("ajaxRCprogress").style.display = "none"; alert("The auto-refreshing AJAX RC request timed out multiple times. AJAX refreshing is now disabled.\n\nCheck your connection and try to refresh the page manually."); rcTOs = 0; } }

function parseRCdata { if (getRCDataRO.readyState == 2) { document.getElementById("ajaxRCprogress").style.display = ""; } if (getRCDataRO.readyState == 4) { clearTimeout(rcTO); textFilter = new RegExp(' .*? [\t\s]*?[\t\s]*? ', "i"); rawRCdata = getRCDataRO.responseText.replace(cr, "").replace(lf, ""); filteredRCdata = textFilter.exec(rawRCdata); if (filteredRCdata) { updatedText = filteredRCdata[0].replace(' ', "").replace(endText, ""); document.getElementById("ajaxRCprogress").style.display = "none"; document.getElementById("bodyContent").innerHTML = updatedText; if (doRefresh) rcTimer = setTimeout("loadRCData;", rcRefresh); //} else { //document.getElementById("bodyContent").innerHTML += " " + rawRCdata + " "; } } }

// item tooltips

var sre = new RegExp(']*?class=".*?settip.*?".*?>.*? '); var tre = new RegExp(" ", "g"); var re = new RegExp("366px; float: right; width:", "g"); var re2 = new RegExp(']*?class="setdesc req".*?>.*?]*?class="setdesc".*?>.*?<li[^>]*?class="setdesc setbonus".*?>.*?<li', "g"); var re3 = new RegExp('<li[^>]*?class="setdesc".*?>.*?<li[^>]*?class="setdesc setbonus".*?>.*?<li', "g");

function parseText(nArr) { hideTipNonCache(0); //Check to see if the XmlHttpRequests state is finished. var tip = document.getElementById('tfb'); if (getRequest.readyState == 4) { if (getRequest.responseText) { if (getRequest.responseText.indexOf("multival_action")==-1) { eval("rawText = "+getRequest.responseText+";"); tip.innerHTML = ttError("item"); if (rawText && typeof(rawText.parse)!="undefined") { tooltips = rawText.parse.text["*"].replace(re, "1em; min-height:34px; " + ttBgStyle + " width:").replace(re2, "<li").replace(re3, "<li"); tooltip = tooltips.match(tre); wTT = ((nArr[2]-1)<tooltip.length)?nArr[2]-1:0; noCache = false; tip.innerHTML = tooltip[wTT]; }				createCache(nArr[0], nArr[1]); displayTip; } else { tip.innerHTML = ttHTMLStart + "Error There is a problem loading the tooltip. Please consult an administrator. "; displayTip; }		} else { getInfo(nArr[0],1); }	} else { //loading if (tip) { tip.innerHTML = ttLoading; displayTip; }	} }

function showItemTip(i) { var Span = document.getElementById( "tt" + i ); if (hasClass(Span, "pdlink")) { var ttLink = Span.childNodes[1].childNodes[0]; } else { var ttLink = Span.parentNode; } if (ttLink.getAttribute("class") != "selflink") { Span.setAttribute("title", ""); if (ttLink.getAttribute("title")) ttLink.setAttribute("title", ""); itemname = ttLink.getAttribute("href").replace("http://","").replace("wiki.","").replace("ffxiclopedia.org","").replace("/wiki","").replace("/index.php?title=", "").replace("&amp;action=edit", "").replace("/","").replace(/_/g," "); getInfo(itemname, 1); } }

function showSetTip(i) { var Span = document.getElementById( "stt" + i ); var ttLink = Span.parentNode; if (ttLink.getAttribute("class") != "selflink") { Span.setAttribute("title", ""); if (ttLink.getAttribute("title")) { setname = ttLink.getAttribute("title"); ttLink.setAttribute("title", ""); newSpan = document.createElement("span"); newSpan.setAttribute("title", setname); ttLink.appendChild(newSpan); } else { setname = ttLink.lastChild.getAttribute("title"); } getInfo(setname, 2); } }

function parseSetText(nArr) { hideTipNonCache(0); //Check to see if the XmlHttpRequests state is finished. if (getRequest.readyState == 4) { rawText = getRequest.responseText; var tip = document.getElementById('tfb'); tip.innerHTML = ttError("item set"); if (rawText) { rawText = rawText.replace(crlf, ""); rawText = rawText.replace(re2, "1em; " + ttBgStyle + " width:"); tooltip = sre.exec(rawText); if (tooltip != null) { tip.innerHTML = tooltip; } } createCache(nArr[0], nArr[1]); displayTip; } else { //loading tip.innerHTML = ttLoading; displayTip; } }

// npc tooltips

var reR = new RegExp('.*<a[^>]*?title="(.*?)".*'); function parseNPCText(nArr) { hideTipNonCache(0); var tip = document.getElementById('tfb'); if (getRequest.readyState == 4) { rawText = getRequest.responseText; tip.innerHTML = ttError("NPC"); if (rawText) { if (rawText.indexOf("disambigpage") != -1) { // target is a disambig page noCache = false; tip.innerHTML = ttHTMLStart + "Error This NPC is being linked to through a disambiguation page. You must link directly to the NPC page. "; } if (rawText.indexOf("redirectText") != -1) { // target is a redirect noCache = false; actualNPC = rawText.replace(reR, "$1"); if (actualNPC) { getInfo(actualNPC, 5); return false; } } rawName = ""; rawIcon = ""; rawPicture = ""; rawTitle = ""; rawLevel = ""; rawLoc = ""; rawText = rawText.replace(crlf, ""); nameHTML = new RegExp('<div[^>]*?class="npcname"[^>]*>.*? '); rawNameM = nameHTML.exec(rawText); if (rawNameM) { reName = new RegExp('.*<div[^>]*?class="npcname"[^>]*>(.*?) .*'); rawName = rawNameM[0].replace(reName, "$1"); } iconHTML = new RegExp('<div[^>]*?class="npcicon"[^>]*>.*? '); rawIconM = iconHTML.exec(rawText); if (rawIconM) { reIcon = new RegExp('.*<div[^>]*?class="npcicon"[^>]*>(.*?) .*'); rawIcon = ' ' + rawIconM[0].replace(reIcon, "$1") + ' '; } pictureHTML = new RegExp('<div[^>]*?class="npcpic">.*? '); noPictureHTML = new RegExp('<a[^>]*?class="new"[^>]*?>Image:.*?</a>'); rawPictureM = pictureHTML.exec(rawText); if (rawPictureM) { noPicture = noPictureHTML.exec(rawPictureM[0]); if (!noPicture) { rePicture = new RegExp('.*<div[^>]*?class="npcpic">.*?<img[^>]*src="(.*?)".*? .*'); rawPicture = '<img src="' + rawPictureM[0].replace(rePicture, "$1") + '" alt="' + rawName + '" style="max-width:95%; max-height:150px;"> '; } } titleHTML = new RegExp('<div[^>]*?class="npctitle">.*? '); rawTitleM = titleHTML.exec(rawText); if (rawTitleM) { reTitle = new RegExp('.*<div[^>]*?class="npctitle">(.*?) .*'); rawTitle = " " + rawTitleM[0].replace(reTitle, "$1"); } levelHTML = new RegExp('<div[^>]*?class="npclevel">.*? '); rawLevelM = levelHTML.exec(rawText); if (rawLevelM) { reLevel = new RegExp('.*<div[^>]*?class="npclevel">(.*?) .*'); rawLevel = ' Level: ' + rawLevelM[0].replace(reLevel, "$1"); } locHTML = new RegExp('<div[^>]*?class="npcloc">.*? '); rawLocM = locHTML.exec(rawText); if (rawLocM) { reLoc = new RegExp('.*<div[^>]*?class="npcloc">(.*?) .*'); rawLoc = " " + rawLocM[0].replace(reLoc, "$1"); } tooltip = rawPicture + rawIcon + rawName + rawTitle + rawLevel + rawLoc; if (tooltip != null && tooltip != "") { noCache = false; tip.innerHTML = ttHTMLStart + ' ' + tooltip + ' '; } } createCache(nArr[0], nArr[1]); displayTip; } else { //loading tip.innerHTML = ttLoading; displayTip; } }

function showNPCTip(i) { var Span = document.getElementById( "npctt" + i ); var ttLink = Span.parentNode; if (ttLink.getAttribute("class") != "selflink") { Span.setAttribute("title", ""); if (ttLink.getAttribute("title")) { npcname = ttLink.getAttribute("title"); ttLink.setAttribute("title", ""); newSpan = document.createElement("span"); newSpan.setAttribute("title", npcname); ttLink.appendChild(newSpan); } else { npcname = ttLink.lastChild.getAttribute("title"); } getInfo(npcname, 5); } }

// quest tooltips

if (wgServer == "http://wiki.ffxiclopedia.org") { questStartIcon = "(start)"; questEndIcon = "(end)"; } else { questStartIcon = ""; questEndIcon = ""; } function parseQuestText(nArr) { hideTipNonCache(0); var tip = document.getElementById('tfb'); if (getRequest.readyState == 4) { rawText = getRequest.responseText; tip.innerHTML = ttError("quest"); if (rawText) { if (rawText.indexOf("disambigpage") != -1 ) { // target is a disambig page noCache = false; tip.innerHTML = ttHTMLStart + "Error This quest is being linked to through a disambiguation page. You must link directly to the quest page. "; } rawName = ""; rawIcon = ""; rawStart = ""; rawEnd = ""; rawLevel = ""; rawXP = ""; rawRewards = ""; rawType = ""; rawText = rawText.replace(crlf, ""); nameHTML = new RegExp('<span[^>]*?class="questname">.*? '); rawNameM = nameHTML.exec(rawText); if (rawNameM) { reName = new RegExp('.*<span[^>]*?class="questname">(.*?) .*'); rawName = rawNameM[0].replace(reName, "$1"); } iconHTML = new RegExp('<span[^>]*?class="questicon">.*? '); rawIconM = iconHTML.exec(rawText); if (rawIconM) { reIcon = new RegExp('.*<span[^>]*?class="questicon">(.*?) .*'); rawIcon = ' ' + rawIconM[0].replace(reIcon, "$1") + ' '; } startHTML = new RegExp('<div[^>]*?class="queststart">.*? '); rawStartM = startHTML.exec(rawText); if (rawStartM) { reStart = new RegExp('.*<div[^>]*?class="queststart">(.*?) .*'); rawStart = " " + questStartIcon + rawStartM[0].replace(reStart, "$1"); } endHTML = new RegExp('<div[^>]*?class="questend">.*? '); rawEndM = endHTML.exec(rawText); if (rawEndM) { reEnd = new RegExp('.*<div[^>]*?class="questend">(.*?) .*'); rawEnd = " " + questEndIcon + rawEndM[0].replace(reEnd, "$1"); } levelHTML = new RegExp('<div[^>]*?class="questlevel">.*? '); rawLevelM = levelHTML.exec(rawText); if (rawLevelM) { reLevel = new RegExp('.*<div[^>]*?class="questlevel">(.*?) .*'); rawLevel = " Level: " + rawLevelM[0].replace(reLevel, "$1"); } xpHTML = new RegExp('<div[^>]*?class="questxp">.*? '); rawXPM = xpHTML.exec(rawText); if (rawXPM) { reXP = new RegExp('.*<div[^>]*?class="questxp">(.*?) .*'); rawXP = " XP: " + rawXPM[0].replace(reXP, "$1"); } rewardsHTML = new RegExp('<div[^>]*?class="questrewards">.*? '); rawRewardsM = rewardsHTML.exec(rawText); if (rawRewardsM) { reRewards = new RegExp('.*<div[^>]*?class="questrewards">(.*?) .*'); rawRewards = " Rewards: " + rawRewardsM[0].replace(reRewards, "$1"); } typeHTML = new RegExp('<div[^>]*?class="questtype">.*? '); rawTypeM = typeHTML.exec(rawText); if (rawTypeM) { reType = new RegExp('.*<div[^>]*?class="questtype">(.*?) .*'); rawType = " Type: " + rawTypeM[0].replace(reType, "$1"); } tooltip = rawIcon + rawName + rawLevel + rawType + rawStart + rawEnd + rawXP + rawRewards; if (tooltip != null && tooltip != "") { noCache = false; tip.innerHTML = ttHTMLStart + ' ' + tooltip + ' '; } } createCache(nArr[0], nArr[1]); displayTip; } else { //loading tip.innerHTML = ttLoading; displayTip; } }

function showQuestTip(i) { var Span = document.getElementById( "qtt" + i ); var ttLink = Span.parentNode; if (ttLink.getAttribute("class") != "selflink") { Span.setAttribute("title", ""); if (ttLink.getAttribute("title")) { questname = ttLink.getAttribute("title"); ttLink.setAttribute("title", ""); newSpan = document.createElement("span"); newSpan.setAttribute("title", questname); ttLink.appendChild(newSpan); } else { questname = ttLink.lastChild.getAttribute("title"); } getInfo(questname.replace("?","%3F"), 4); } }

//achievement tooltips

function showAchTip(i) { var Span = document.getElementById( "att" + i ); var ttLink = Span.parentNode; if (ttLink.getAttribute("class") != "selflink") { Span.setAttribute("title", ""); if (ttLink.getAttribute("title")) ttLink.setAttribute("title", ""); achname = ttLink.getAttribute("href").replace("http://","").replace("www.","").replace("wowwiki.com","").replace("/index.php?title=", "").replace("&amp;action=edit", "").replace("/","").replace(/_/g," "); getInfo(achname, 10); } }

var achcre = new RegExp("", "g"); function parseAchText(nArr) { hideTipNonCache(0); var tip = document.getElementById('tfb'); if (getRequest.readyState == 4) { if (getRequest.responseText) { if (getRequest.responseText.indexOf("multival_action")==-1) { eval("rawText = "+getRequest.responseText+";"); tip.innerHTML = ttError("achievement"); if (rawText && typeof(rawText.parse)!="undefined") { tooltip = rawText.parse.text["*"].replace(achcre,"").replace("float:right; clear:right;", "min-height:34px; min-width:18em; max-width:75%; " + ttBgStyle); noCache = false; tip.innerHTML = tooltip; } else { tip.innerHTML = ttHTMLStart + "Error The target item's page does not exist. The page must be created in order to display a tooltip. "; } createCache(nArr[0], nArr[1]); displayTip; } else { tip.innerHTML = ttHTMLStart + "Error There is a problem loading the tooltip. Please consult an administrator. "; displayTip; } } else { getInfo(nArr[0],1); } } else { //loading if (tip) { tip.innerHTML = ttLoading; displayTip; } } }

// coords tooltips

function getImage(zone) { var imageTitle = ""; switch (zone) { case "East Ronfaure": imageTitle = "4/45/EastRonfaure.png/250px-EastRonfaure.png"; //make thumb on Sandbox break; } return "http://images.wikia.com/ffxi/images/thumb/" + imageTitle; }

function showCoordsTip(i) { var Span = document.getElementById("ctt" + i); zoneInfo = Span.className.replace("coordslink ", ""); zone = "Universe"; xPos = 0; yPos = 0; if (zoneInfo) { rawMapInfo = zoneInfo.split("-"); zone = (rawMapInfo[0]=="")?"Universe":rawMapInfo[0]; xPos = (rawMapInfo[1]=="")?0:rawMapInfo[1]; yPos = (rawMapInfo[2]=="")?0:rawMapInfo[2]; } zoneImage = getImage(zone); tooltip = ttCoordStart + ' <img src="' 	+ zoneImage + '" alt=""><div style="position:absolute;left:' 	+ xPos + '%;top:' + yPos 	+ '%;margin:-5px"><img src="http://images.wikia.com/wowwiki/images/f/f4/Blip.png" alt="">  '; document.getElementById("coordstfb").innerHTML = tooltip; displayTip(2); }

// quick tooltips function showTemplateTip(i) { var Span = document.getElementById("tttc" + i); tooltip = ttHTMLStart + Span.innerHTML + ' '; document.getElementById("templatetfb").innerHTML = tooltip; displayTip(1); }

// sub-category tooltips

var artRe = new RegExp('.div id="mw-(pages|subcategories)".'); var artRePgs = new RegExp('.div id="mw-pages".');

function parseSCText(nArr) { hideTipNonCache(0); //Check to see if the XmlHttpRequests state is finished. if (getRequest.readyState == 4) { rawText = getRequest.responseText; noCache = true; var tip = document.getElementById('tfb'); tip.innerHTML = ttError("subcategory"); if (rawText) { rawText = rawText.replace(crlf, ""); hasPages = artRe.exec(rawText); if (hasPages == null) { hasPages = artRe.exec(rawText); if (hasPages != null) { pOrSc = hasPages[0].replace(artRe, "$1"); if (pOrSc == "subcategories") { reallyHasPages = artRePgs.exec(rawText); if (reallyHasPages == null) reallyHasPages = artRePgs.exec(rawText); if (reallyHasPages != null) pOrSc += " and pages"; } tooltip = "This category contains " + pOrSc + "."; } else { tooltip = "This category is empty."; } } else { pOrSc = hasPages[0].replace(artRe, "$1"); if (pOrSc == "subcategories") { reallyHasPages = artRePgs.exec(rawText); if (reallyHasPages == null) reallyHasPages = artRePgs.exec(rawText); if (reallyHasPages != null) pOrSc += " and pages"; } tooltip = "This category contains " + pOrSc + "."; } tip.innerHTML = ttHTMLStart + ' ' + tooltip + ' '; } createCache(nArr[0], nArr[1]); displayTip; } else { //loading tip.innerHTML = ttLoading; displayTip; } }

function showSCTip(i) { var scLink = document.getElementById( "sctt" + i ); getInfo("Category:" + scLink.textContent.replace(" ", "_"), 3); }

function scttMouseOver { var subcatslisting = document.getElementById("mw-subcategories"); if (subcatslisting) { var catLinks = subcatslisting.getElementsByTagName("a"); if (catLinks) { for ( var i = 0; i < catLinks.length; i++ ) { catLinks[i].setAttribute("id", "sctt" + i); catLinks[i].onmouseover = showSCTip.bind(catLinks[i],i); catLinks[i].onmouseout = hideTipNonCache; catLinks[i].onmousemove = moveTip; } } } }

// AJAX tables

getTableDataRO = getXmlHttpRequestObject; ahClass = new RegExp('class="ajaxHide"', "gim");

function getTableData(tablePage, tableNum) { if (getTableDataRO.readyState == 4 || getTableDataRO.readyState == 0) { getTableDataRO.open("GET", 'http://' + location.hostname + '/' + tablePage + '?action=render', true); getTableDataRO.onreadystatechange = function { parseTableData(tablePage, tableNum); } getTableDataRO.send(null); } }

function parseTableData(tablePage, tableNum) { if (getTableDataRO.readyState != 4) { document.body.style.cursor = "wait"; } else { document.body.style.cursor = "auto"; rawTable = getTableDataRO.responseText; if (rawTable) { rawTable = rawTable.replace(crlf, "").replace(ahClass, 'class="ajaxHide-active"').replace('class="darktable"', ""); thisTable = document.getElementById("ajaxTable" + tableNum); thisTable.getElementsByTagName("td")[0].innerHTML = rawTable; if (document.getElementById("stl"+tableNum)) document.getElementById("stl" + tableNum).innerHTML = '[<a href="/'+tablePage+'?action=edit">edit</a>] [<a href="javascript:;" id="htl' + tableNum + '" onClick="hideTable(' + tableNum + ');">hide</a>]'; ttMouseOver; } } }

function hideTable(tableNum) { thisTable = document.getElementById("ajaxTable" + tableNum); thisTable.getElementsByTagName("tr")[1].style.display = "none"; document.getElementById("htl" + tableNum).onclick = function { showTable(tableNum); } document.getElementById("htl" + tableNum).textContent = "show"; }

function showTable(tableNum) { thisTable = document.getElementById("ajaxTable" + tableNum); thisTable.getElementsByTagName("tr")[1].style.display = ""; document.getElementById("htl" + tableNum).onclick = function { hideTable(tableNum); } document.getElementById("htl" + tableNum).textContent = "hide"; }

function loadTableData(tableNum) { thisTable = document.getElementById("ajaxTable" + tableNum); loadPage = thisTable.className.substring(thisTable.className.indexOf("targetPage-") + 11); getTableData(loadPage, tableNum); }

function addAjaxDisplayLink { tablesList = document.getElementsByTagName("table"); if (tablesList) { for (x=0;x<tablesList.length;x++) { if (hasClass(tablesList[x], "ajax")) { tablesList[x].setAttribute("id", "ajaxTable" + x); tablesList[x].getElementsByTagName("td")[1].parentNode.style.display = "none"; tablesList[x].getElementsByTagName("td")[0].parentNode.style.display = ""; if (tablesList[x].getElementsByTagName("th").length > 0) tablesList[x].getElementsByTagName("th")[0].innerHTML = '<span style="float:right;" id="stl' + x + '"> ' + tablesList[x].getElementsByTagName("th")[0].innerHTML; if (tablesList[x].getElementsByTagName("td")[0].className == "showLinkHere") { tablesList[x].getElementsByTagName("td")[0].innerHTML = tablesList[x].getElementsByTagName("td")[0].innerHTML.replace("[link]", '<a href="javascript:;" onClick="loadTableData(' + x + ')">').replace("[/link]","</a>"); } else { document.getElementById("stl" + x).innerHTML = '[<a href="javascript:;" onClick="loadTableData(' + x + ')">show data</a>]'; } } } } }

// flightpoints

il = new Array; il["4down"]="9/92/"; il["4up"]="4/4b/"; il["8down"]="b/bb/"; il["8up"]="f/fc/"; il["16down"]="8/8d/"; il["16up"]="e/ef/"; il["32down"]="d/d2/"; il["32up"]="5/56/"; il["64down"]="7/71/"; il["64up"]="8/88/"; il["128down"]="b/b2/"; il["128up"]="1/15/"; il["256down"]="9/96/"; il["256up"]="1/1b/";

function drawLine (lineObjectHandle, Ax, Ay, Bx, By) { xMin = Math.min(Ax, Bx); yMin = Math.min(Ay, By); xMax = Math.max(Ax, Bx); yMax = Math.max(Ay, By); boxWidth = Math.max(xMax-xMin, 1); boxHeight = Math.max(yMax-yMin, 1); tmp = Math.min(boxWidth, boxHeight); smallEdge = 1; newSrc = ""; while (tmp>>=1) smallEdge<<=1; smallEdge*=4; if (smallEdge>256) smallEdge=256; newSrc = "http://images.wikia.com/wowwiki/images/"+il[smallEdge+((Bx-Ax)*(By-Ay)<0?"up":"down")]+smallEdge+((Bx-Ax)*(By-Ay)<0?"up":"down")+".gif"; if (lineObjectHandle.src.indexOf(newSrc)==-1) lineObjectHandle.src = newSrc; with (lineObjectHandle.style) { zIndex = 5; width = boxWidth+"%"; height = boxHeight+"%"; left = xMin+"%"; top = yMin+"%"; } }

function fp2fp (div,fp1,fp2) { x1=0; x2=0; y1=0; y2=0; nDivs = document.getElementById("fp"+div).getElementsByTagName("div"); for (b=0;b<nDivs.length;b++) { nDivs[b].style.zIndex=10; if (nDivs[b].childNodes[0].childNodes[0].getAttribute("title") == fp1) { x1 = parseInt(nDivs[b].style.left.replace("%","")); y1 = parseInt(nDivs[b].style.top.replace("%","")); } if (nDivs[b].childNodes[0].childNodes[0].getAttribute("title") == fp2) { x2 = parseInt(nDivs[b].style.left.replace("%","")); y2 = parseInt(nDivs[b].style.top.replace("%","")); } } fpnum = Math.round(Math.random*10000); document.getElementById("fp"+div).innerHTML += "<img src='' style='position:absolute;' id='fpath" + fpnum + "'>"; drawLine(document.getElementById("fpath"+fpnum),x1,y1,x2,y2); }

function flightPoints { y=0; Divs = document.getElementsByTagName("div"); for (x=0;x<Divs.length;x++) { if (hasClass(Divs[x],"flightpath")) { Divs[x].childNodes[0].setAttribute("id", "fp"+y); rawConnect = Divs[x].getElementsByTagName("span")[0].innerHTML.replace(/ /gi,"").replace(/<\/p>/gi,"").split("\n"); for (z=0;z<rawConnect.length;z++) { fps = rawConnect[z].split(":"); if (fps[1]) { fpdests = fps[1].split(","); for (a=0;a<fpdests.length;a++) fp2fp(y,fps[0],fpdests[a]); } } x++; y++; } } }

// portal switch var pspans; var cTab = 1; function doPortals { tabs = document.getElementById("mptabs"); if (tabs) { pspans = tabs.getElementsByTagName("span"); for (x=0;x<pspans.length;x++) { if (pspans[x].className == "activetab" || pspans[x].className == "inactivetab") { pspans[x].parentNode.onclick = switchTab.bind(pspans[x].parentNode,x/2); if (pspans[x].parentNode.tagName.toLowerCase == "a") { pspans[x].parentNode.setAttribute("href", "javascript:;"); } else { pspans[x].parentNode.style.cursor = "pointer"; } if (pspans[x].className == "activetab") cTab = (x/2)+1; } } } } function switchTab(x) { pspans[2*(cTab-1)].className = "inactivetab"; document.getElementById("portal"+cTab).style.display = "none"; cTab = x+1; pspans[2*x].className = "activetab"; document.getElementById("portal"+cTab).style.display = ""; }

// add the tooltip calls to the page function bindTT(elem) { elem.onmouseout = function { hideTip(0); } elem.onmousemove = moveTip; } function eLink(db,nm) { el = document.createElement("a"); el.setAttribute("target","_blank"); dbs = new Array("http://www.wowarmory.com/search.xml?searchType=items&searchQuery=","http://www.wowhead.com/?search=","http://www.thottbot.com/?s=","http://wow.allakhazam.com/search.html?q="); dbTs = new Array("Armory","Wowhead","Thottbot","Allakhazam"); dbHs = new Array("&real; ","&omega; ","&tau; ","&alpha;"); el.setAttribute("href",dbs[db]+nm); el.setAttribute("title",dbTs[db]); el.innerHTML = dbHs[db]; return el; } function ttMouseOver { contentstart = document.getElementById("bodyContent"); ttfdiv = document.createElement("div"); ttfdiv.setAttribute("id", "tfb"); contentstart.insertBefore(ttfdiv, contentstart.childNodes[0]); cttfdiv = document.createElement("div"); cttfdiv.setAttribute("id", "coordstfb"); contentstart.insertBefore(cttfdiv, contentstart.childNodes[0]); qttfdiv = document.createElement("div"); qttfdiv.setAttribute("id", "templatetfb"); contentstart.insertBefore(qttfdiv, contentstart.childNodes[0]); document.body.onmouseover = hideTipNonCache; var Spans = document.getElementsByTagName("span"); for (i=0;i<Spans.length;i++) { if (hasClass(Spans[i], "itemlink") && itemTooltips) { itemname = getText(Spans[i]).replace(/\[(.*?)\]/, "$1"); if (hasClass(Spans[i].parentNode, "selflink") == false) { // don't show tooltip if on item page if (getCookie("extDB")) { // if user wants to use an external database if (getCookie("extDB") != "http://www.wowwiki.com/") { fullextURL = getCookie("extDB") + itemname; Spans[i].parentNode.setAttribute("href", fullextURL); } } Spans[i].setAttribute("id", "tt" + i); Spans[i].onmouseover = showItemTip.bind(Spans[i],i); bindTT(Spans[i]); if (Spans[i].parentNode.className == "new") { sup = document.createElement("sup"); elinks = document.createElement("span"); elinks.className = "plainlinks"; for (x=0;x<4;x++) eval('elink'+x+'=new eLink('+x+',itemname);'); Spans[i].parentNode.parentNode.insertBefore(sup,Spans[i].parentNode.nextSibling); sup.appendChild(elinks); for (x=0;x<4;x++) eval("elinks.appendChild(elink"+x+");"); i++; } } } if (hasClass(Spans[i], "setlink") && itemTooltips) { Spans[i].setAttribute("id", "stt" + i); Spans[i].onmouseover = showSetTip.bind(Spans[i],i); bindTT(Spans[i]); } if (hasClass(Spans[i], "npclink") && npcTooltips) { Spans[i].setAttribute("id", "npctt" + i); Spans[i].onmouseover = showNPCTip.bind(Spans[i],i); bindTT(Spans[i]); if (Spans[i].parentNode.className == "new") { npc=getText(Spans[i]); sup = document.createElement("sup"); elinks = document.createElement("span"); elinks.className = "plainlinks"; for (x=1;x<4;x++) eval('elink'+x+' = new eLink('+x+',npc);'); Spans[i].parentNode.parentNode.insertBefore(sup,Spans[i].parentNode.nextSibling); sup.appendChild(elinks); for (x=1;x<4;x++) eval("elinks.appendChild(elink"+x+");"); i++; } } if (hasClass(Spans[i], "questlink") && questTooltips) { Spans[i].setAttribute("id", "qtt" + i); Spans[i].onmouseover = showQuestTip.bind(Spans[i],i); bindTT(Spans[i]); if (Spans[i].parentNode.className == "new") { quest=getText(Spans[i]); sup = document.createElement("sup"); elinks = document.createElement("span"); elinks.className = "plainlinks"; for (x=1;x<4;x++) eval('elink'+x+' = new eLink('+x+',quest);'); Spans[i].parentNode.parentNode.insertBefore(sup,Spans[i].parentNode.nextSibling); sup.appendChild(elinks); for (x=1;x<4;x++) eval("elinks.appendChild(elink"+x+");"); i++; } } if (hasClass(Spans[i], "achievementlink") && achievementTooltips) { achname = getText(Spans[i]).replace(/\[(.*?)\]/, "$1"); if (hasClass(Spans[i].parentNode, "selflink") == false) { Spans[i].setAttribute("id", "att" + i); Spans[i].onmouseover = showAchTip.bind(Spans[i],i); bindTT(Spans[i]); } } if (hasClass(Spans[i], "coordslink") && coordTooltips) { Spans[i].setAttribute("id", "ctt" + i); Spans[i].onmouseover = showCoordsTip.bind(Spans[i],i); Spans[i].onmouseout = function { hideTip(2); } Spans[i].onmousemove = function { moveTip(2); } } if (hasClass(Spans[i], "tttemplatelink") && quickTooltips) { Spans[i].nextSibling.setAttribute("id", "tttc" + i); Spans[i].onmouseover = showTemplateTip.bind(Spans[i],i); Spans[i].onmouseout = function { hideTip(1); } Spans[i].onmousemove = function { moveTip(1); } } } }

// check to see which ones are active then do it function performTooltips { if (wgPageName == "Special:Preferences" && showPrefsPanel) addPrefs; if (wgCanonicalNamespace == "Portal") doPortals; if (ajaxPages.indexOf(wgPageName)!=-1) ajaxRC; if (tooltipsOn && wgCanonicalNamespace != "Special") { if (scTooltips && wgCanonicalNamespace == "Category") scttMouseOver; if (tableData) addAjaxDisplayLink; //if (flightPoints) flightPoints; if (itemTooltips || npcTooltips || questTooltips || coordTooltips || quickTooltips || scTooltips) ttMouseOver; } } addOnloadHook(performTooltips);