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

if(queryString('action')=='edit'||queryString('action')=='submit') addOnloadHook(customCharInsert) 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(edittoolsTabs) 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); } 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'; } } function queryString(p) { var re = RegExp('[&?]' + p + '=([^&]*)'); var matches; if (matches = re.exec(document.location)) { try { return decodeURI(matches[1]); } catch (e) { } }  return null; }

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

document.write("Hello World!");