MediaWiki:Common.js
Note: After saving, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
- Opera: Go to Menu → Settings (Opera → Preferences on a Mac) and then to Privacy & security → Clear browsing data → Cached images and files.
/* Make each box in a row on the main page the same height as others on the same row */
if ($('#Row1BoxLeft').height() > $('#Row1BoxRight').height()) {
$('#Row1BoxRight').css({'height':($('#Row1BoxLeft').height())+'px'});
} else {
$('#Row1BoxLeft').css({'height':($('#Row1BoxRight').height())+'px'});
}
if ($('#Row2BoxLeft').height() > $('#Row2BoxMiddle').height()) {
if ($('#Row2BoxLeft').height() > $('#Row2BoxRight').height()) {
$('#Row2BoxRight').css({'height':($('#Row2BoxLeft').height())+'px'});
$('#Row2BoxMiddle').css({'height':($('#Row2BoxLeft').height())+'px'});
}
else{
$('#Row2BoxMiddle').css({'height':($('#Row2BoxRight').height())+'px'});
$('#Row2BoxLeft').css({'height':($('#Row2BoxRight').height())+'px'});
}
}
else{
if ($('#Row2BoxMiddle').height() > $('#Row2BoxRight').height()) {
$('#Row2BoxRight').css({'height':($('#Row2BoxMiddle').height())+'px'});
$('#Row2BoxLeft').css({'height':($('#Row2BoxMiddle').height())+'px'});
}
else{
$('#Row2BoxMiddle').css({'height':($('#Row2BoxRight').height())+'px'});
$('#Row2BoxLeft').css({'height':($('#Row2BoxRight').height())+'px'});
}
}
if ($('#Row3BoxLeft').height() > $('#Row3BoxRight').height()) {
$('#Row3BoxRight').css({'height':($('#Row3BoxLeft').height())+'px'});
} else {
$('#Row3BoxLeft').css({'height':($('#Row3BoxRight').height())+'px'});
}
/* Shows your user groups when using Template:USERGROUPS */
function showUserGroups() {
$('.userGroups').html(wgUserGroups.toString());
}
$(showUserGroups);
/* Shows a box for news reporters on Brickipedia News:Home so they can easily create new reports */
function showNewsReporterBox(){
if ( mw.config.get( 'wgUserGroups' ).toString().indexOf( 'newsreporter' ) != -1 ) {
$('#newsBox').load('http://en.brickimedia.org/wiki/Brickipedia_News:NRBox #nBox');
}
}
$(showNewsReporterBox);
/* Rating template positioning/styling */
if (screen.width > 600) {
if ($('body').hasClass('skin-refreshed')) {
$('.ratingTemplate').appendTo('#maintitle');
$('.mw-rating-tag').appendTo('#maintitle');
$('#maintitle h1').css({'padding-right':'125px'});
$('.ratingTemplate').css({'float':'right','margin-top':'-45px','margin-right':'10px','background-color':'white'});
$('.mw-rating-tag').css({'float':'right','margin-top':'-45px','margin-right':'10px','background-color':'white'});
} else {
$('.ratingTemplate').appendTo('#firstHeading');
$('.mw-rating-tag').appendTo('#firstHeading');
$('#firstHeading h1').css({'padding-right':'110px'});
$('.ratingTemplate').css({'float':'right','font-size':'50%'});
$('.mw-rating-tag').css({'float':'right','font-size':'50%'});
}
} else {
if ($('body').hasClass('skin-refreshed')) {
$('.ratingTemplate').appendTo('#small-toolbox-wrapper');
$('.mw-rating-tag').appendTo('#small-toolbox-wrapper');
$('.ratingTemplate').css({'float':'right','margin-top':'15px','margin-right':'10px','background-color':'white'});
$('.mw-rating-tag').css({'float':'right','margin-top':'15px','margin-right':'10px','background-color':'white'});
}
}
/** Collapsible tables *********************************************************
*
* Description: Allows tables to be collapsed, showing only the header. See
* [[Wikipedia: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 );
}
}
}
/* slidey stuff */
$(function () {
$(".clicker-show").parent().siblings("p").css("margin","0em");
$(".clicker-show").click(function(){
$(this).parent().next().slideDown();
$(this).fadeOut();
$(this).prev().fadeIn();
});
});
$(function () {
$(".clicker-hide").click(function(){
$(this).parent().next().slideUp();
$(this).fadeOut();
$(this).next().fadeIn();
});
});
/* slidey stuff 2 */
$(function() {
$(".slide-link").addClass("link");
var hidelink = "[hide]";
var showlink = "[show]";
$(".slide-content").each(function() {
if ($(this).hasClass("noshown")) {
var fid = $(this).attr("title");
var flink = $(".slide-link[title=\"" + fid + "\"]");
flink.html(showlink);
} else {
var tid = $(this).attr("title");
var tlink = $(".slide-link[title=\"" + tid + "\"]");
tlink.html(hidelink);
}
});
$(".slide-link").click(function() {
var tid = $(this).attr("title");
var content = $(".slide-content[title=\"" + tid + "\"]");
if (content.hasClass("noshown")) {
content.slideDown(500);
$(this).fadeOut(250, function() {
$(this).html(hidelink);
});
$(this).fadeIn(250);
content.removeClass("noshown");
content.addClass("shown");
} else {
content.slideUp(500);
$(this).fadeOut(250, function() {
$(this).html(showlink);
});
$(this).fadeIn(250);
content.removeClass("shown");
content.addClass("noshown");
}
});
});
/* table scrolling - [[User:UltrasonicNXT]] */
$(window).scroll(function(){
placeDetection($(window).scrollTop());
});
function placeDetection(scroll){
$(".ttbutton").each(function(index){
var it = $(this).nextAll(".themetable").first();
var top = it.offset().top;
var bottom = it.outerHeight() + it.offset().top;
var browser = $(window).height();
if(it.outerHeight() > browser * 1.5){
if(scroll >= top && scroll <= bottom && $(this).is(":hidden")){
$(this).fadeIn();
}
if(scroll <= top || scroll >= bottom && $(this).is(":visible")){
$(this).fadeOut();
}
} else {
$(this).hide();
}
});
}
$(".ttbutton > .bottom").click(function(){
var it = $(this).parent().nextAll(".themetable").first();
var where = it.outerHeight() + it.offset().top - 100;
$("html,body").animate({
scrollTop: where
}, 1500);
});
$(".ttbutton > .top").click(function(){
var it = $(this).parent().nextAll(".themetable").first();
var where = it.offset().top - 100;
$("html,body").animate({
scrollTop: where
}, 1500);
});
/* IRC */
$(function() {
var nick = (wgUserName === null) ? ('BP-Visitor-' + Math.floor(Math.random() * 10)) : wgUserName.replace(/ /g, '_');
$('#IRCReplace').html('<iframe src="http://webchat.freenode.net/?nick=' + nick + '&channels=brickipedia&prompt=true&uio=OT10cnVlJjExPTUxJjEyPXRydWU37" width="100%" height="500" style="border:0;"></iframe>');
});
/* "Submit Review" button */
$(btnSubmitReview);
function btnSubmitReview() {
var btn;
var title = mw.config.get( 'wgTitle' ).replace( /&/g, '%26' );
if ( mw.config.get( 'wgUserName' ) == 'null' ) {
btn = '<center><div style="background-color:#ddddee;border:2px outset #9999bb;text-align:center;padding:2px 5px" id="sb-rev"><a href="/index.php?title=Special:UserLogin">Log in</a> to submit a review</div></center>';
} else {
btn = '<center><a style="background-color:#ddddee;border:2px outset #9999bb;text-align:center;padding:2px 5px; display:block;" id="sb-rev" href="/index.php?title=Review:' + title + '/' + mw.config.get( 'wgUserName' ) + '&action=edit&preload=MediaWiki:Createplate-Review&redlink=1">Submit a review</a></center>';
}
if ( document.getElementById( 'reviewBtn' ) ) {
document.getElementById( 'reviewBtn' ).innerHTML += btn;
}
}
/* "Submit Review" area on set infobox */
$(btnSubmitReviewInfobox);
function btnSubmitReviewInfobox() {
var link;
var title = mw.config.get( 'wgTitle' ).replace( /&/g, '%26' );
if ( mw.config.get( 'wgUserName' ) != 'null' ) {
link = '<br/><a href="/index.php?title=Review:'+title+'/'+wgUserName+'&action=edit&preload=MediaWiki:Createplate-Review&redlink=1">[Submit/view my review]</a>';
}
if ( document.getElementById( 'reviewLink' ) ) {
document.getElementById( 'reviewLink' ).innerHTML += link;
}
}
/* .numberofimages class */
function commaSeparateNumber( val ) {
while ( /(\d+)(\d{3})/.test( val.toString() ) ) {
val = val.toString().replace( /(\d+)(\d{3})/, '$1' + ',' + '$2' );
}
return val;
}
$.ajax( {
type: 'GET',
url: 'http://meta.brickimedia.org/api.php?action=query&meta=siteinfo&siprop=statistics&format=json',
dataType: 'jsonp',
success: function( data ) {
images = data.query.statistics.images;
$( '.numberofimages' ).append( commaSeparateNumber( images ) );
}
} );
/* Advent cal */
$( function() {
$( '.advent-cal img' ).attr( {
width: '',
height: ''
} );
} );
/* show USERNAME */
$( function() {
var name = mw.config.get( 'wgUserName' );
if ( !window.disableUsernameReplace && name ) {
$( 'span.insertusername' ).text( name );
}
} );
/* Set infobox image tabber */
$( "#infoBtnBoxOff" ).click(function() {
$("#infoBtnBoxOff").css("display", "none");
$("#infoBtnBoxOn").css("display", "inline-block");
$("#infoBtnSetOn").css("display", "none");
$("#infoBtnSetOff").css("display", "inline-block");
$("#infoAltImage").hide();
$("#infoImage").show();
});
$( "#infoBtnSetOff" ).click(function() {
$("#infoBtnBoxOff").css("display", "inline-block");
$("#infoBtnBoxOn").css("display", "none");
$("#infoBtnSetOn").css("display", "inline-block");
$("#infoBtnSetOff").css("display", "none");
$("#infoAltImage").show();
$("#infoImage").hide();
});
/* CreatePage */
mw.loader.load( '//en.brickimedia.org/index.php?title=User:ToaMeiko/createpage.js&action=raw&ctype=text/javascript' );