MediaWiki:Common.js

/* Any JavaScript here will be loaded for all users on every page load. */ // Edit page tool selector // -> modified from http://commons.wikimedia.org/wiki/MediaWiki:Edittools.js

function queryString(p) { var re = RegExp('[&?]' + p + '=([^&]*)'); var matches; if ((matches = re.exec(document.location))) { try { return decodeURI(matches[1]); } catch (e) { } }  return null; }

function customCharInsert { if(!window.wgCustomCharInsert||!wgUserName) { return; } var spec = document.getElementById('specialchars'); var userp = document.createElement('p'); userp.className = 'specialbasic'; userp.id = 'Custom_Edittools'; userp.style.display='none'; for (var i=0;i<wgCustomCharInsert.length;i++) { var a = document.createElement('a'); a.href='#'; a.setAttribute('onclick', 'insertTags("' + wgCustomCharInsert[i].tagOpen + '","' + wgCustomCharInsert[i].tagClose + '","' + wgCustomCharInsert[i].sampleText + '"); return false;'); a.appendChild(document.createTextNode(wgCustomCharInsert[i].tagOpen + wgCustomCharInsert[i].tagClose)); userp.appendChild(a); if(i!=wgCustomCharInsert.length-1) { userp.appendChild(document.createTextNode(' · ')); } } spec.appendChild(userp); } if(queryString('action')=='edit'||queryString('action')=='submit') { addOnloadHook(customCharInsert); } function edittoolsTabs { var spec = document.getElementById('specialchars'); if(!spec) { return; } var sb = getElementsByClassName(spec,'p','specialbasic'); if(sb.length<=1) { return; } var sel = document.createElement('select'); sel.style.display = 'inline'; sel.setAttribute('onchange','chooseCharSubset(selectedIndex)'); for(var i=0;i<sb.length;i++) { var o = document.createElement('option'); o.appendChild(document.createTextNode(sb[i].id.replace(/_/g,' '))); sel.appendChild(o); } spec.insertBefore(sel,spec.firstChild.nextSibling); } if(queryString('action')=='edit'||queryString('action')=='submit') { addOnloadHook(edittoolsTabs); } function chooseCharSubset(seld) { var spec = document.getElementById('specialchars'); var sb = getElementsByClassName(spec,'p','specialbasic'); for (var i = 0; i < sb.length ; i++) { sb[i].style.display = i == seld ? 'inline' : 'none'; } }

/* Code for demo widgets */ addWidgets = function { var widgets = getElementsByClassName(document.getElementById('bodyContent'),'div','wikia_widget'); for(var i = 0; i < widgets.length; i++){ widgets[i].innerHTML = " <embed src='http://images.wikia.com/common/skins/common/flash_widgets/wikia_widget.swf' FlashVars='backgroundColor=000000&backgroundImage=&borderColor=92947c&dropShadow=on&headerColor=92947c&headerAlpha=.05&headerBorderColor=000000&headline1=The Vault presents&headline1Color=CCCCCC&headline2=Most Wanted DLC Items&headline2Color=FFFFFF&clickURL=http://fallout.wikia.com&wikiURLColor=FFFFFF&wikiaLogoColor=FFFFFF&type=slideshow&slideshowImages=http://images1.wikia.nocookie.net/fallout/images/8/8b/Widget_Auto-Axe.png,http://images3.wikia.nocookie.net/fallout/images/f/ff/Widget_Gauss-Rifle.png,http://images3.wikia.nocookie.net/fallout/images/6/6f/Widget_WidPower-Armor.png,http://images3.wikia.nocookie.net/fallout/images/1/1c/Get_Shock-Sword.png&=Preview images in the widget&' quality='high' wmode='transparent' width='300' height='250' align='middle' allowScriptAccess='always' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' name='wikia_widget' /> "; } };

addOnloadHook(addWidgets); /* End of code for demo widgets */

/* Force Preview JavaScript code - Start */ // Code slightly modified from http://www.mediawiki.org/w/index.php?title=Manual:Force_preview&oldid=250009 var permittedGroups = ["sysop", "bureaucrat", "rollback"]; var permittedUsers = ["Kwigon the sharpshooter", "Temahk"]; Array.prototype.intersects = function { //  //  Returns true if any element in the argument array // is the same as an element in this array //  if( !arguments.length ){ return false; } var array2 = arguments[0]; var len1 = this.length; var len2 = array2.length; if( len2 === 0 ){ return false; } for(var i=0; i<len1; i++){ for(var j=0; j<len2; j++) { if( this[i] === array2[j] ) { return true; }   }  }  return false; }; function forcePreview { if( wgAction != "edit") { return; }

if( wgUserGroups === null) { wgUserGroups = []; }

if( wgUserName === null) { wgUserName = []; }

var UserName = new Array(1); UserName[0] = wgUserName;

if( (wgUserGroups.intersects(permittedGroups)) || (UserName.intersects(permittedUsers)) ) { return; }

var saveButton = document.getElementById("wpSave"); if( !saveButton ) { return; } saveButton.disabled = true; saveButton.value = "Save page (use preview first)"; saveButton.style.fontWeight = "normal"; document.getElementById("wpPreview").style.fontWeight = "bold"; } addOnloadHook(forcePreview); /* Force Preview JavaScript code - End */

/* Code used for Outfiter */ function outfiter_ajax { getXmlHttpRequestObject = function { if (window.XMLHttpRequest) { return new XMLHttpRequest; } else if(window.ActiveXObject) { return new ActiveXObject("Microsoft.XMLHTTP"); } alert("Your browser doesn't support the XmlHttpRequest object. Update your browser."); return false; }; if (typeof (lootparser_loot_r = getXmlHttpRequestObject) == 'boolean') { return; } lootparser_loot_r.onreadystatechange = function { if (lootparser_loot_r.readyState != 4) { return; } var text = lootparser_loot_r.responseText; var otext = text;

text = text.slice(text.search('id="pre_outfiter1">')+19, text.search(' ')); newscript = document.createElement('style'); newscript.setAttribute("rel", "stylesheet"); newscript.setAttribute("type", "text/css"); document.getElementsByTagName("head")[0].appendChild(newscript); newscript.appendChild(document.createTextNode(text)); text = otext.slice(otext.search(' ')+4); text = text.slice(text.search('id="pre_outfiter2">')+19, text.search(' ')); text = text.replace(/&amp;/g,'&').replace(/ /g,' ').replace(/&lt;/g,'<').replace(/&gt;/g,'>').replace(/&quot;/g,'"');   document.getElementById('outfiter_container').innerHTML = text;

text = otext.slice(otext.search(' ')+4); text = text.slice(text.search(' ')+4); text = text.slice(text.search('id="pre_outfiter3">')+19, text.search(' ')); text = text.replace(/&amp;/g,'&').replace(/ /g,' ').replace(/&lt;/g,'<').replace(/&gt;/g,'>').replace(/&quot;/g,'"');   newscript = document.createElement('script');    newscript.setAttribute("type", "text/javascript");    newscript.text = text;    document.getElementById('outfiter_script').appendChild(newscript);  };  lootparser_loot_r.open('GET', '/wiki/Outfiter/Code');  lootparser_loot_r.send(null); } /* End of Code used for Outfiter */

/* Hook for Outfiter */ if (wgPageName == 'Outfiter' && (wgAction == 'view' || wgAction == 'submit' || wgAction == 'purge')) { addOnloadHook(function { outfiter_ajax; }); } /* End of Hook for Outfiter */

/* Code used for Loot_Statistics */ function lootparser_loot_ajax { getXmlHttpRequestObject = function { if (window.XMLHttpRequest) { return new XMLHttpRequest; } else if(window.ActiveXObject) { return new ActiveXObject("Microsoft.XMLHTTP"); } alert("Your browser doesn't support the XmlHttpRequest object. Update your browser."); return false; }; if (typeof (lootparser_loot_r = getXmlHttpRequestObject) == 'boolean') { return; } lootparser_loot_r.onreadystatechange = function { if (lootparser_loot_r.readyState != 4) { return; } var text = lootparser_loot_r.responseText; text = text.slice(text.search('id="pre_lootparser">')+20, text.search(' ')); text = text.replace(/&amp;/g,'&').replace(/ /g,' ').replace(/&lt;/g,'<').replace(/&gt;/g,'>').replace(/&quot;/g,'"');   newscript = document.createElement('script');    newscript.setAttribute("type", "text/javascript");    newscript.text = text;    document.getElementById('lootparser_loot_script').appendChild(newscript);  };  lootparser_loot_r.open('GET', '/wiki/Loot_Statistics/Lootparserloot');  lootparser_loot_r.send(null); } /* End of Code used for Loot_Statistics */ /* Hook for Loot_Statistics */ if (wgPageName == 'Loot_Statistics' && (wgAction == 'view' || wgAction == 'submit' || wgAction == 'purge')) {  addOnloadHook(function { lootparser_loot_ajax; }); } /* End of Hook for Loot_Statistics */

/* Code used for NPC Chat Windows */ addOnloadHook(function { var x, y, cont, o = document.getElementsByTagName('div');  for (x in o) { if (o[x].className == 'npc_chat_div' || o[x].className == 'npc_chat_div_r') {    cont = o[x].getElementsByTagName('div');    for (y in cont) { if (cont[y].className == 't3') {      var lc = document.createElement('a');lc.setAttribute('href','#');lc.innerHTML = 'Collapse';      lc.onclick = function {var x,o,t=this;while(t.className!='npc_chat_div'&&t.className!='npc_chat_div_r') {t=t.parentNode;}o=t.getElementsByTagName('tr');for(x in o) {if(o[x].className=='m_tr') {if(o[x].style.display=='none'){o[x].style.display='';this.innerHTML='Collapse';}else{o[x].style.display='none';this.innerHTML='Expand';}}}return false;};      var lm = document.createElement('span');lm.innerHTML = ' - ';      var ls = document.createElement('a');ls.setAttribute('href','#');ls.innerHTML = 'Switch Color';      ls.onclick = function {var writeCookie = function(data) {var date=new Date;date.setTime(date.getTime+(365*24*60*60*1000));date=date.toGMTString;document.cookie='npc_transcript_color='+data+';expires='+date+';path=/';};var x,o=document.getElementsByTagName('div');for(x in o){if(o[x].className=='npc_chat_div'){o[x].className='npc_chat_div_r';writeCookie('white');}else if(o[x].className=='npc_chat_div_r'){o[x].className='npc_chat_div';writeCookie('tibia');}}return false;}; cont[y].appendChild(ls);cont[y].appendChild(lm);cont[y].appendChild(lc); } } } }  if (document.cookie.indexOf('npc_transcript_color=white')!=-1) {o=document.getElementsByTagName('div');for(x in o){if(o[x].className=='npc_chat_div'){o[x].className='npc_chat_div_r';}}} }); /* End of code used for NPC Chat Windows */