Difference between revisions of "MediaWiki:Common.js"
From Brickipedia, the LEGO Wiki
m |
|||
Line 348: | Line 348: | ||
$( 'span.insertusername' ).text( name ); |
$( 'span.insertusername' ).text( name ); |
||
} |
} |
||
− | } ); |
||
− | |||
− | /* encouraging editing from chat */ |
||
− | var counter = 0; |
||
− | var max = 15; |
||
− | $( $( '#mwchat-type input' )[0] ).keydown( function( e ) { |
||
− | if ( e.which == 13 && e.shiftKey ) { |
||
− | return false; |
||
− | } else if ( e.which == 13 ) { // Enter |
||
− | counter++; |
||
− | if ( counter > max ) { |
||
− | counter = 0; |
||
− | max += 10; |
||
− | $( "<div>You've done lots of chatting, why not do some editing here too? Check out our <a href='/wiki/Brickipedia:Things_to_do' target='_blank'>list of things to do</a>, or try <a href='/wiki/Special:Random' target='_blank'>this page</a>, <a href='/wiki/Special:Random' target='_blank'>this page</a>, or <a href='/wiki/Special:Random' target='_blank'>this page</a>.<br><small><a href='javascript:;' onclick='$(this).parent().parent().remove()'>(dismiss)</a></small></div>" ).appendTo( $( 'body' ) ) |
||
− | .css( { 'background-color': '#CCC', 'position': 'fixed', 'top': '50px', 'left': '50%', 'margin-left': '-120px', 'width': '240px', 'z-index': 5, 'padding': '10px', } ); |
||
− | } |
||
− | } |
||
} ); |
} ); |
||
Revision as of 21:21, 11 April 2015
/* Make each box in a row on the main page the same height as others on the same row */
var FirstRowLeftBox = $('.LeftBox.MPBoxesFirstRow').height();
var FirstRowRightBox = $('.RightBox.MPBoxesFirstRow').height();
var SecondRowLeftBox = $('.LeftBox.MPBoxesSecondRow').height();
var SecondRowRightBox = $('.RightBox.MPBoxesSecondRow').height();
var ThirdRowLeftBox = $('.LeftBox.MPBoxesThirdRow').height();
var ThirdRowRightBox = $('.RightBox.MPBoxesThirdRow').height();
if (FirstRowLeftBox > FirstRowRightBox) {
$('.RightBox.MPBoxesFirstRow').css({'height':($('.LeftBox.MPBoxesFirstRow').height())+'px'});
} else {
$('.LeftBox.MPBoxesFirstRow').css({'height':($('.RightBox.MPBoxesFirstRow').height())+'px'});
}
if (SecondRowLeftBox > SecondRowRightBox) {
$('.RightBox.MPBoxesSecondRow').css({'height':($('.LeftBox.MPBoxesSecondRow').height())+'px'});
} else {
$('.LeftBox.MPBoxesSecondRow').css({'height':($('.RightBox.MPBoxesSecondRow').height())+'px'});
}
if (ThirdRowLeftBox > ThirdRowRightBox) {
$('.RightBox.MPBoxesThirdRow').css({'height':($('.LeftBox.MPBoxesThirdRow').height())+'px'});
} else {
$('.LeftBox.MPBoxesThirdRow').css({'height':($('.RightBox.MPBoxesThirdRow').height())+'px'});
}
/* Mainpage nav */
$("#MP-theme-nav").mouseenter(function() {
$("#MP-theme-nav-body").slideDown("medium");
$("#MP-theme-nav-header").css("background", "#3333FF");
$("#MP-theme-nav-header a").css("color", "#FFFFFF");
$("#MP-theme-nav-header span").css("color", "#FFFFFF");
}).mouseleave(function() {
$("#MP-theme-nav-body").slideUp("medium");
$("#MP-theme-nav-header").css("background", "#FFFFFF");
$("#MP-theme-nav-header a").css("color", "#3333FF");
$("#MP-theme-nav-header span").css("color", "#3333FF");
});
$("#MP-comm-nav").mouseenter(function() {
$("#MP-comm-nav-body").slideDown("medium");
$("#MP-comm-nav-header").css("background", "#3333FF");
$("#MP-comm-nav-header a").css("color", "#FFFFFF");
$("#MP-comm-nav-header span").css("color", "#FFFFFF");
}).mouseleave(function() {
$("#MP-comm-nav-body").slideUp("medium");
$("#MP-comm-nav-header").css("background", "#FFFFFF");
$("#MP-comm-nav-header a").css("color", "#3333FF");
$("#MP-comm-nav-header span").css("color", "#3333FF");
});
$("#MP-links-nav").mouseenter(function() {
$("#MP-links-nav-body").slideDown("medium");
$("#MP-links-nav-header").css("background", "#3333FF");
$("#MP-links-nav-header a").css("color", "#FFFFFF");
$("#MP-links-nav-header span").css("color", "#FFFFFF");
}).mouseleave(function() {
$("#MP-links-nav-body").slideUp("medium");
$("#MP-links-nav-header").css("background", "#FFFFFF");
$("#MP-links-nav-header a").css("color", "#3333FF");
$("#MP-links-nav-header span").css("color", "#3333FF");
});
/* 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('#smalltoolboxwrapper');
$('.mw-rating-tag').appendTo('#smalltoolboxwrapper');
$('.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="400" 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();
});