MediaWiki:Wikia.js: Difference between revisions
Appearance
Removed SocialButtons (outdated) moving image buttons to Common.js |
m Initial creating, taken from RuneScape Wikia |
||
| Line 1: | Line 1: | ||
/* This JavaScript file is meant for the Wikia-skin only. To see the other skin, see MediaWiki:Monobook.js. For use in global use see MediaWiki:Common.js.*/ | /* This JavaScript file is meant for the Wikia-skin only. To see the other skin, see MediaWiki:Monobook.js. For use in global use see MediaWiki:Common.js.*/ | ||
(function ($, mw, ed) { | |||
'use strict'; | |||
var conf = mw.config.get( [ | |||
'wgAction', | |||
'wgCanonicalSpecialPageName', | |||
'wgNamespaceNumber', | |||
'wgUserName' | |||
] ); | |||
var includes = { | |||
/** | |||
* Add custom masthead boxes to profile masthead | |||
* | |||
* @author Rappy 4187 (Aion Wiki) | |||
* @author Amaurice | |||
* @author Cqm | |||
*/ | |||
mastheadBoxes: { | |||
conditional: ( | |||
( | |||
conf.wgAction === 'view' && | |||
[2, 3].indexOf( conf.wgNamespaceNumber ) > -1 | |||
) || | |||
conf.wgCanonicalSpecialPageName === 'Contributions' | |||
), | |||
exec: function () { | |||
var title = mw.config.get( 'wgTitle' ), | |||
rights = { | |||
// awb | |||
// bot | |||
'KyoukoBot': 'BOT' | |||
// bureaucrat | |||
}, | |||
$masthead; | |||
// fix for [[Special:Contibutions/username]] | |||
if ( conf.wgCanonicalSpecialPageName === 'Contributions' ) { | |||
title = title.split( '/' )[1]; | |||
} | |||
if ( rights[title] ) { | |||
$masthead = $( '.UserProfileMasthead' ); | |||
// remove old rights | |||
$masthead | |||
.find( '.tag' ) | |||
.remove(); | |||
// add new rights | |||
$masthead | |||
.find( 'hgroup' ) | |||
.append( | |||
$( '<span>' ) | |||
.addClass( 'tag' ) | |||
.text( rights[ title ] ) | |||
); | |||
} | |||
} | |||
}, | |||
}; | |||
var loaded = []; | |||
// stripped down version of [[MediaWiki:Common.js]] loader | |||
// this is only designed to have functions in each include | |||
// imports should be done in [[MediaWiki:Common.js]] to cut down on http requests | |||
function init() { | |||
$.each( includes, function ( k, v ) { | |||
var check = $.isFunction( v.conditional ) ? v.conditional() : v.conditional; | |||
if ( check ) { | |||
// used for tracking which includes are loading | |||
loaded.push( 'oasis.' + k ); | |||
if ( v.exec ) { | |||
v.exec(); | |||
} | |||
} | |||
} ); | |||
// this should always be defined | |||
// but just in case ResourceLoader develops a quirk | |||
ed.loaded = ( ed.loaded || [] ).concat( loaded ); | |||
} | |||
$( init ); | |||
}( this.jQuery, this.mediaWiki, this.edwiki = this.edwiki || {} ) ); | |||
Revision as of 01:32, 9 June 2015
/* This JavaScript file is meant for the Wikia-skin only. To see the other skin, see MediaWiki:Monobook.js. For use in global use see MediaWiki:Common.js.*/
(function ($, mw, ed) {
'use strict';
var conf = mw.config.get( [
'wgAction',
'wgCanonicalSpecialPageName',
'wgNamespaceNumber',
'wgUserName'
] );
var includes = {
/**
* Add custom masthead boxes to profile masthead
*
* @author Rappy 4187 (Aion Wiki)
* @author Amaurice
* @author Cqm
*/
mastheadBoxes: {
conditional: (
(
conf.wgAction === 'view' &&
[2, 3].indexOf( conf.wgNamespaceNumber ) > -1
) ||
conf.wgCanonicalSpecialPageName === 'Contributions'
),
exec: function () {
var title = mw.config.get( 'wgTitle' ),
rights = {
// awb
// bot
'KyoukoBot': 'BOT'
// bureaucrat
},
$masthead;
// fix for [[Special:Contibutions/username]]
if ( conf.wgCanonicalSpecialPageName === 'Contributions' ) {
title = title.split( '/' )[1];
}
if ( rights[title] ) {
$masthead = $( '.UserProfileMasthead' );
// remove old rights
$masthead
.find( '.tag' )
.remove();
// add new rights
$masthead
.find( 'hgroup' )
.append(
$( '<span>' )
.addClass( 'tag' )
.text( rights[ title ] )
);
}
}
},
};
var loaded = [];
// stripped down version of [[MediaWiki:Common.js]] loader
// this is only designed to have functions in each include
// imports should be done in [[MediaWiki:Common.js]] to cut down on http requests
function init() {
$.each( includes, function ( k, v ) {
var check = $.isFunction( v.conditional ) ? v.conditional() : v.conditional;
if ( check ) {
// used for tracking which includes are loading
loaded.push( 'oasis.' + k );
if ( v.exec ) {
v.exec();
}
}
} );
// this should always be defined
// but just in case ResourceLoader develops a quirk
ed.loaded = ( ed.loaded || [] ).concat( loaded );
}
$( init );
}( this.jQuery, this.mediaWiki, this.edwiki = this.edwiki || {} ) );