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 */

/* No Account No Edit Category - Start */ // Prevent users that are not logged in from adding Categories through the special interace addOnloadHook(function { if( wgUserName == null || wgUserName == "") {   var addCat = document.getElementById("csAddCategorySwitch");   if( !addCat ) { return; }   addCat.style.display = 'none'; } }); /* No Account No Edit Category - End */

if (wgAction == 'view' || wgAction == 'submit' || wgAction == 'purge') { /* Color Transcripts */ $('table.npc_chat_div_r div.m3, table.npc_chat_div div.m3').each(function{$(this).html(' '+($(this).html.replace(/|| /gi, ' ').replace(/player:|player<\/i>:|player:/gi, ' -:pL:-').replace(/-:pL:-/g, ' Player :').replace(/::/g, ':').replace(/\{/g, ).replace(/\}/g, ))+' ');}); /* End of Color Transcripts */ /* Outfiter */ if (wgPageName == 'Outfiter') { addOnloadHook(function { $.ajax({ url: '/index.php?title=Outfiter/Code&action=raw',success: function(text) { var otext = text; text = text.slice(text.search('id="pre_outfiter1">')+19, text.search('<\/pre>')); $('body:first').append(''+text+' '); text = otext.slice(otext.search(' ')+4); text = text.slice(text.search('id="pre_outfiter2">')+19, text.search(' ')); $('#outfiter_container').html(text); text = otext.slice(otext.search(' ')+4); text = text.slice(text.search(' ')+4); text = text.slice(text.search('id="pre_outfiter3">')+19, text.search(' ')); $('#outfiter_script').append(''+text+' '); }}); }); } /* End of Outfiter */ /* Mapper */ addOnloadHook(function { if (wgPageName == 'Mapper' || $('a[href*="http://tibia.wikia.com/wiki/Mapper"]').size) { $.ajax({ url: '/index.php?title=Mapper/Code&action=raw', success: function(text) { text = text.slice(text.search('id="pre_mapper">')+16, text.search('<\/pre>')); $('body:first').append(''+text+' '); }}); } }); /* End Mapper */ /* Loot Statistics */ if (wgPageName == 'Loot_Statistics') { addOnloadHook(function { $.ajax({ url: '/index.php?title=Loot_Statistics/Lootparserloot&action=raw', cache: false, success: function(text) { text = text.slice(text.search('id="pre_lootparser">')+21, text.search('<\/pre>')); $('#lootparser_loot_script').append(''+text+' '); }}); }); } /* End of Loot Statistics */ /* TibiaWiki:Creature_Statistics */ if (wgPageName === 'TibiaWiki:Creature_Statistics') { addOnloadHook(function { $.ajax({ url: '/index.php?title=TibiaWiki:Creature_Statistics/Code&action=raw', dataType:'text', cache: false, success: function(text) { text = text.slice(text.search('id="pre_statsparser">')+22, text.search('<\/pre>')); $('body:first').append(''+text+' '); }}); }); } /* TibiaWiki:Creature_Statistics End */ /* NPC Chat Windows */ addOnloadHook(function { $('.npc_chat_div .t3, .npc_chat_div_r .t3') .append($('Collapse')) .append($('Expand</a>')) .append($(' - ')) .append($('Switch Color</a>')); $('.npc_chat_div_exp').click(function { $(this).parents('.npc_chat_div, .npc_chat_div_r').first.find('.m_tr').show; $(this).parent.find('.npc_chat_div_ttoggle').toggle; return false;}); $('.npc_chat_div_coll').click(function { $(this).parents('.npc_chat_div, .npc_chat_div_r').first.find('.m_tr').hide; $(this).parent.find('.npc_chat_div_ttoggle').toggle; return false;}); $('.npc_chat_div_swcol').click(function { var writeCookie = function(data) {var date=new Date;date.setTime(date.getTime+(30*24*60*60*1000));date=date.toGMTString;document.cookie='npc_transcript_color='+data+';expires='+date+';path=/';}; if ($('.npc_chat_div').size) { $('.npc_chat_div').removeClass('npc_chat_div').addClass('npc_chat_div_r'); writeCookie('white'); } else { $('.npc_chat_div_r').removeClass('npc_chat_div_r').addClass('npc_chat_div'); writeCookie('tibia'); } return false; }); if (document.cookie.match(/npc_transcript_color[\s]?=[\s]?white/) !== null) { $('.npc_chat_div_swcol:first').click; } }); /* End of NPC Chat Windows */ /* Loot percentage data */ addOnloadHook(function { droppedby_perc_data = {}; loot_perc_data = {}; loot_perc_datao = ; loot_perc_datap = ; loot_perc_dataoa = true; loot_perc_sort = function(sid){ $('#'+sid).each(function{ var t=$(this).html; t = t.replace(/<img[^>]*id="(?:loot|droppedby)_perc_load"[^>]*>/, ''); var sp = t.match(/(<span[\s\S]*>[^\d]*?<\/span>)/i); sp = sp === null ?  : sp[1]; t = $.trim(t.replace(sp, )); while (t.substr(-1)=='.'){t=t.substr(0,t.length-1);} t = t.split(','); t.sort(function(a,b){b=(b.match(/\(([\d\.]+)%\)/)||[0,0])[1];a=(a.match(/\(([\d\.]+)%\)/)||[0,0])[1];return parseFloat(b)-parseFloat(a);}); $.each(t, function(i, v) { t[i]=$.trim(v); }); $(this).html(t.join(', ')+'. '+sp); }); }; loot_perc_put_data = function { if (typeof loot_perc_data.kills == 'undefined') {    var off = $('#loot_perc_text').offset;    $('body:first').append( $(' Not enough statistics information to show percentages ').attr('id', 'loot_perc_not_enough') .css({'display':'none', 'z-index':'999', 'top':(off.top-20)+'px', 'left':(off.left-35)+'px', 'position':'absolute',           'background-color':'#0038d8', 'border-radius':'4px', 'box-shadow':'0px 0px 5px', 'color':'#ffffff',            'margin':'0px', 'padding':'10px 20px'      }).fadeIn('slow', function { setTimeout(function { $('#loot_perc_text').hide; $('#loot_perc_not_enough').fadeOut('slow'); }, 4000); }) );   $('#loot_perc_loot').html(loot_perc_datao);  }  else {    $('#loot_perc_text').attr('title', 'Based on '+loot_perc_data.kills+' kills');    $('#loot_perc_loot a').each(function{ var ex = {'gp':'Gold Coin', 'skull (item)':'Skull', 'black skull (item)':'Black Skull', 'rusty armor (common)':'Rusty Armor', 'rusty armor (semi-rare)':'Rusty Armor', 'rusty armor (rare)':'Rusty Armor', 'rusty legs (common)':'Rusty Legs', 'rusty legs (semi-rare)':'Rusty Legs', 'rusty legs (rare)':'Rusty Legs', };     var t = unescape($(this).attr('href').replace(/.*\/(.*?)$.*/, '$1').replace(/_/g, ' ')); if (ex[t.toLowerCase]) { t = ex[t.toLowerCase]; } if (loot_perc_data[t]) { $(this).after(' ('+loot_perc_data[t]+')'); } });   loot_perc_sort('loot_perc_loot');    loot_perc_datap = $('#loot_perc_loot').html;  } }; loot_perc_get_data = function(text) {  if (text !== false) {    var r = new RegExp('version[\\s]?=[\\s]?8\\.6[^}\\d]*?kills[\\s]?=[\\s]?(\\d*)([\\s\\S]*?)}'+'}');    var matches = text.match(r);    if (matches !== null && matches.length == 3 && parseInt(matches[1], 10) > 500) {      loot_perc_data.kills = parseInt(matches[1], 10);      var items = matches[2].split('|');      $.each(items, function(i, v) { if (!v.match(/times:/)) { return true; } loot_perc_data[$.trim(v.split(',')[0])] = (Math.round((parseInt(v.split('times:')[1].split(',')[0], 10) / parseInt(matches[1], 10))*10000)/100) + '%'; });   }  } }; loot_perc_loaded = function(text) {  loot_perc_get_data(text);  $('#loot_perc_load').hide;  loot_perc_put_data;  loot_perc_dataoa = false; }; loot_perc_load = function {  if (loot_perc_dataoa && loot_perc_datap === ) {  $('#loot_perc_loot').html($('#loot_perc_loot').html.replace(/[\s]?\((?:semi-|very )?rare\)[\s]?/g, ))  .prepend('<img id="loot_perc_load" src="http://images4.wikia.nocookie.net/tibia/en/images/8/87/Ajax_Load_Image.gif" alt="Loading %s" />');  $.ajax({url:'/index.php?title=Loot_Statistics:'+wgTitle+'&action=raw', dataType:'text', timeout:15000, success:function(text) { loot_perc_loaded(text); }, error: function(text) { loot_perc_loaded(false); }}); }  else if (loot_perc_dataoa) { $('#loot_perc_loot').html(loot_perc_datap); loot_perc_dataoa = false; }  else { $('#loot_perc_loot').html(loot_perc_datao); loot_perc_dataoa = true; } }; loot_perc_datao = $('#loot_perc_tr>td:eq(0)') .append($('(Toggle % view)</a>').click(function{loot_perc_load;return false;})) .next.attr('id', 'loot_perc_loot').html;

droppedby_perc_put_data = function { $('#droppedby_perc_creat a').each(function{ var t = droppedby_perc_data[$(this).text]; if (t) { $(this).after($(' ('+t[0]+') ').attr('title', 'Based on '+t[1]+' kills').css('cursor','pointer'));  } } ); loot_perc_sort('droppedby_perc_creat'); $('#droppedby_perc_creat span').css('color','#0148C2').click(function { window.open('/wiki/Loot_Statistics:'+$(this).prev.text); }); }; droppedby_perc_get_data = function(text, item) { if (typeof item == 'undefined') { item = wgTitle; } if (text !== false) { var ex = {'skull (item)':'Skull', 'black skull (item)':'Black Skull', 'rusty armor (common)':'Rusty Armor', 'rusty armor (semi-rare)':'Rusty Armor', 'rusty armor (rare)':'Rusty Armor', 'rusty legs (common)':'Rusty Legs', 'rusty legs (semi-rare)':'Rusty Legs', 'rusty legs (rare)':'Rusty Legs', };   if (ex[item.toLowerCase]) { item = ex[item.toLowerCase]; } var r = new RegExp('version[\\s]?=[\\s]?8\\.6[^}\\d]*?kills[\\s]?=[\\s]?(\\d*)[^}]*?name[\\s]?=[\\s]?(.*)[|\\r\\n][^}]*?[|][\\s]?('+item+')[\\s]?,[^}\\r\\n]*?times:(\\d*)'); var matches = text.match(r); if (matches !== null && matches.length == 5 && matches[2] && parseInt(matches[1], 10) > 500) { droppedby_perc_data[matches[2]] = [(Math.round((parseInt(matches[4], 10) / parseInt(matches[1], 10))*10000)/100) + '%', parseInt(matches[1], 10)]; } } }; droppedby_perc_loaded = function(text) { droppedby_perc_loading--; droppedby_perc_get_data(text); if (droppedby_perc_loading < 1) { $('#droppedby_perc_load').hide; droppedby_perc_put_data; } }; droppedby_perc_load = function { $('#droppedby_perc_text').hide;var t = $('#droppedby_perc_creat').text.replace(/\./g, '').split(','); droppedby_perc_loading = t.length; $('#droppedby_perc_creat').prepend('<img id="droppedby_perc_load" src="http://images4.wikia.nocookie.net/tibia/en/images/8/87/Ajax_Load_Image.gif" alt="Loading %s" />'); $.each(t, function(i, v) {   t[i] = $.trim(v);    $.ajax({url:'/index.php?title=Loot_Statistics:'+t[i]+'&action=raw', dataType:'text', timeout:15000, success:function(text) { droppedby_perc_loaded(text); }, error: function(text) { droppedby_perc_loaded(false); }}); }); }; $('#droppedby_perc_tr>td:eq(0)') .append($('(Load %)</a>').click(function{droppedby_perc_load;return false;})) .next.attr('id', 'droppedby_perc_creat'); }); /* End of Loot percentage data */ /* Calculators */ if (wgPageName == 'Calculators') { addOnloadHook(function { $.ajax({ url: '/index.php?title=Calculators/Code&action=raw', success: function(text) { text = text.slice(text.search('id="pre_calculators">')+21, text.search('<\/pre>'));  $('body:first').append('<script type="text/javascript">'+text+' '); }}); }); } /* End of Calculators */ }