MediaWiki:Common.js

/* Any JavaScript here will be loaded for all users on every page load. */

/*** Glitch fix by User:Pcj ***/ function fixBlogLinks { if (wgPageName == "Special:RecentChanges") $("#bodyContent ul.special li:contains('article-comments-rc-blog-comment')").each(function (i) { oldHTML = $(this).html; lnk = $(this).find("a:contains('hist')").attr("href"); if (typeof(lnk) != "undefined") { rawID = lnk.replace(/.*curid=(.*?)&.*/,"$1"); bLink = "/wiki/User_blog:" + lnk.replace(/.*User_blog_comment:(.*?\/.*?)\/.*/,"$1") + "?showall=1#comm-" + rawID; newHTML = oldHTML.replace("&lt;article-comments-rc-blog-comment&gt;","(Blog comment) "); $(this).html(newHTML); } }); } function fbl { fixBlogLinks; $("#bodyContent").bind("ajaxPageLoad",fixBlogLinks); } addOnloadHook(fbl);

/* Test if an element has a certain class ************************************** * * Description: Uses regular expressions and caching for better performance. * Maintainers: User:Mike Dillon, User:R. Koot, User:SG */ var hasClass = (function {    var reCache = {};    return function (element, className) {        return (reCache[className] ? reCache[className] : (reCache[className] = new RegExp("(?:\\s|^)" + className + "(?:\\s|$)"))).test(element.className);   }; });

/** Collapsible tables ********************************************************* * * Description: Allows tables to be collapsed, showing only the header. See *              NavFrame. * Maintainers: User:R. Koot */ var autoCollapse = 2; var collapseCaption = "hide"; var expandCaption = "show"; function collapseTable( tableIndex ) {   var Button = document.getElementById( "collapseButton" + tableIndex ); var Table = document.getElementById( "collapsibleTable" + tableIndex ); if ( !Table || !Button ) { return false; }   var Rows = Table.rows; if ( Button.firstChild.data == collapseCaption ) { for ( var i = 1; i < Rows.length; i++ ) { Rows[i].style.display = "none"; }       Button.firstChild.data = expandCaption; } else { for ( var i = 1; i < Rows.length; i++ ) { Rows[i].style.display = Rows[0].style.display; }       Button.firstChild.data = collapseCaption; } } function createCollapseButtons {   var tableIndex = 0; var NavigationBoxes = new Object; var Tables = document.getElementsByTagName( "table" ); for ( var i = 0; i < Tables.length; i++ ) { if ( hasClass( Tables[i], "collapsible" ) ) { /* only add button and increment count if there is a header row to work with */ var HeaderRow = Tables[i].getElementsByTagName( "tr" )[0]; if (!HeaderRow) continue; var Header = HeaderRow.getElementsByTagName( "th" )[0]; if (!Header) continue; NavigationBoxes[ tableIndex ] = Tables[i]; Tables[i].setAttribute( "id", "collapsibleTable" + tableIndex ); var Button    = document.createElement( "span" ); var ButtonLink = document.createElement( "a" ); var ButtonText = document.createTextNode( collapseCaption ); Button.style.styleFloat = "right"; Button.style.cssFloat = "right"; Button.style.fontWeight = "normal"; Button.style.textAlign = "right"; Button.style.width = "6em"; ButtonLink.style.color = Header.style.color; ButtonLink.setAttribute( "id", "collapseButton" + tableIndex ); ButtonLink.setAttribute( "href", "javascript:collapseTable(" + tableIndex + ");" ); ButtonLink.appendChild( ButtonText ); Button.appendChild( document.createTextNode( "[" ) ); Button.appendChild( ButtonLink ); Button.appendChild( document.createTextNode( "]" ) ); Header.insertBefore( Button, Header.childNodes[0] ); tableIndex++; }   }    for ( var i = 0;  i < tableIndex; i++ ) { if ( hasClass( NavigationBoxes[i], "collapsed" ) || ( tableIndex >= autoCollapse && hasClass( NavigationBoxes[i], "autocollapse" ) ) ) { collapseTable( i ); }   } } addOnloadHook( createCollapseButtons );

/** Username replace function (Template:USERNAME) ******************************* * Inserts user name into * Originally by User:Splarka * New version by User:Spang * Fixed with JS provided by User:Grunny, thanks! */ function UserNameReplace { if(typeof(disableUsernameReplace) != 'undefined' && disableUsernameReplace || wgUserName == null) return; $('.insertusername').html(wgUserName); } addOnloadHook(UserNameReplace);

//Attempt at loading top icons function showRating {   var titleDiv = document.getElementById("title-rating"); if (titleDiv != null && titleDiv != undefined) {      var content = document.getElementById('article'); if (!content) {        var content = document.getElementById('content'); }

if (content) {         var hs = content.getElementsByTagName('h1'); var firstHeading; for (var i = 0; i < hs.length; i++){ if ( (' '+hs[i].className+' ').indexOf(' firstHeading ') != -1){ firstHeading=hs[i]; break; }         }          var cloneNode = titleDiv.cloneNode(true); firstHeading.insertBefore(cloneNode, firstHeading.childNodes[0]); cloneNode.style.display = "block"; cloneNode.style.visibility = "visible"; if (skin != "monaco") {           cloneNode.style.marginTop = "-11px"; }      }    } }

addOnloadHook( showRating );

$(function {	var nick = (wgUserName == null) ? ('IRC_visitor-' + Math.floor(Math.random * 10)) : wgUserName.replace(/ /g, '_'); 	$('#IRCReplace').html(' '); });

// Edit Menu // From http://www.sourcewatch.org/index.php?title=MediaWiki:Monobook.js#Edit_summary_stuff // Modify by User:Cizagna // The original value of the edit summary field is stored here var editsummOriginalSummary = new String; // A global ref to the dropdown with canned edit summaries var editsummDropdown = null; function editsummInitialize { var label = document.getElementById('wpSummaryLabel'); if(label == null) return; label.firstChild.style.cssText = 'display:none'; // Save the original value of the edit summary field editsummOriginalSummary = document.forms.editform.wpSummary.value; // For convenience, add a dropdown box with some canned edit // summaries to the form. var dropdown = document.createElement('select'); dropdown.setAttribute('title', 'Standard Summaries') dropdown.style.cssText = 'margin-top:3px;'; dropdown.onchange = new Function('editsummOnCannedSummarySelected'); addDropdownOption(dropdown,'','(Summary)'); addDropdownOption(dropdown,'','Refactoring:'); addDropdownOption(dropdown,'Cleanup','— Cleanup'); addDropdownOption(dropdown,'Formating','— Formatting'); addDropdownOption(dropdown,'HTML tidying','— HTML tidying'); addDropdownOption(dropdown,'Wikification','— Wikification'); addDropdownOption(dropdown,'','Content:'); addDropdownOption(dropdown,'Page created','— Page created'); addDropdownOption(dropdown,'Update with new info.','— Update with new info.'); addDropdownOption(dropdown,'Expansion','— Expansion'); addDropdownOption(dropdown,'Rewrite','— Rewrite'); addDropdownOption(dropdown,'Fix spelling/grammar','— Corrected spelling/grammar'); addDropdownOption(dropdown,'','Remove/Revert:'); addDropdownOption(dropdown,'Revert Vandalism','— Revert Vandalism'); addDropdownOption(dropdown,'-unverified info','— Remove unverified info'); addDropdownOption(dropdown,'','Templates:'); addDropdownOption(dropdown,'+Infobox','— Added Infobox'); addDropdownOption(dropdown,'Corrected template usage','— Corrected template usage'); addDropdownOption(dropdown,'','Categories:'); addDropdownOption(dropdown,'+Cat','— Added Category'); addDropdownOption(dropdown,'-Cat','— Remove Category'); addDropdownOption(dropdown,'Alphabetized ""','— Alphabetized '); /*addDropdownOption(dropdown,,); addDropdownOption(dropdown,,);*/ label.appendChild(dropdown); // Store a global ref to it   editsummDropdown = dropdown; var onMonaco = skin == 'monaco' ? true : false; if(onMonaco) { // even thougth this can be configure by MediaWiki pages its better this way so it only affects monaco pages document.getElementById('wpMinoredit').nextSibling.nextSibling.innerHTML = 'Minor'; document.getElementById('wpWatchthis').nextSibling.nextSibling.innerHTML = 'Watch'; }else { var wpSumamaryCssSize = document.getElementById('wpSummary'); wpSumamaryCssSize.style.cssText = 'width:70%'; //FF wpSumamaryCssSize.size = '60'; //IE } } // Adds options to the drop down menu on "editsummInitialize" function addDropdownOption(dropdown,optionValue,optionText) { var option = document.createElement('option'); option.setAttribute('value', optionValue) option.appendChild(document.createTextNode(optionText)); dropdown.appendChild(option); } // There's a cross-browser issue when accessing the selected text: // *In Firefox you can use: selectObj.value // *In IE, you have to use: selectObj.options[selectObj.selectedIndex].text // *The latter method also works in Firefox function editsummOnCannedSummarySelected { var newSummary = editsummOriginalSummary; if(newSummary.length!=0) newSummary += " - "; var idx = editsummDropdown.selectedIndex; var canned = editsummDropdown.options[idx].value; newSummary += canned; document.forms.editform.wpSummary.value = newSummary; } addOnloadHook(editsummInitialize); //test $('ul.tools li:first-child').after('Ask a question about LEGO!');

//Hiding spotlights from unregistered, thanks to User:VegaDark addOnloadHook(function {  if (wgUserName) {    footer = document.getElementById("WikiaFooter section"); if (footer) {      document.getElementById("WikiaFooter section").style.display ="inline";    }   }; });