MediaWiki:Gadget-SeparateSpecialCategories.js: Porovnání verzí
Smazaný obsah Přidaný obsah
Separace speciálních typů kategorií |
(Žádný rozdíl)
|
Verze z 8. 9. 2013, 14:07
/**
* @brief
* Separace speciálních typů kategorií
*
* @details
* Oddělí speciální typy kategorií do vlastních boxů pod hlavním kategorizačním boxem.
*
* @remark
* Relies on:
* * mediawiki.Title
* * mediawiki.Uri
*
* @author
* [[meta:User:Danny B.]]
*/
/*global mediaWiki, jQuery */
/*jslint browser: true, plusplus: true, white: true */
/*jshint browser:true, laxbreak:false, plusplus:false, white:false, undef:true, unused:true */
( function ( mw, $ ) {
'use strict';
var categoryTypes = [
{
boxId: 'mwg-MaintenanceCats',
prefix: 'Údržba:',
infoPage: new mw.Title( 'Project:Údržba' ),
infoText: 'Údržba',
removePrefix: true,
treatAsExisting: false
}, {
boxId: 'mwg-MonitoringCats',
prefix: 'Monitoring:',
infoPage: new mw.Title( 'Project:Monitoring' ),
infoText: 'Monitoring',
removePrefix: true,
treatAsExisting: true
}
];
var prefixes = categoryTypes[0].prefix;
for ( var i = 1; i < categoryTypes.length; i++ ) {
prefixes += '|' + categoryTypes[i].prefix;
}
var rgxPrefixes = new RegExp( '^(' + prefixes + ')' );
if (
!mw.config.get( 'wgIsArticle' )
||
mw.config.get( 'wgIsRedirect' )
||
!$.grep( mw.config.get( 'wgCategories' ), function ( item ) { return rgxPrefixes.test( item ); } ).length
) {
return;
}
$( document ).ready( function () {
var categoryPrefix;
for ( var i = 0; i < categoryTypes.length; i++ ) {
categoryPrefix = mw.config.get( 'wgFormattedNamespaces' )['14'] + ':' + categoryTypes[i].prefix;
if ( $( '#catlinks ul a[title^="' + categoryPrefix + '"]' ).length ) {
$( '<div>' )
.attr({
'class': 'catlinks mwg-specialcatlinks',
'id': categoryTypes[i].boxId
})
.html( '<a href="' + categoryTypes[i].infoPage.getUrl() + '" title="' + mw.html.escape( categoryTypes[i].infoPage.getPrefixedText() ) + '">' + categoryTypes[i].infoText + '</a>: <ul></ul>' )
.insertAfter( $( '.catlinks' ).last() )
.children( 'ul' )
.append(
$( '#catlinks ul li' )
.has( 'a[title^="' + categoryPrefix + '"]' )
.each( function () {
$( this )
.find( '> a' )
.each( function () {
if (categoryTypes[i].removePrefix ) {
$( this ).text( $( this ).text().replace( categoryTypes[i].prefix, '' ) );
}
if (categoryTypes[i].treatAsExisting ) {
$( this )
.removeClass( 'new' )
.attr( 'href', function ( index, value ) {
return new mw.Title( new mw.Uri( value ).query.title ).getUrl();
})
;
}
});
})
)
;
}
}
$( '#catlinks' )
.has( 'ul:empty' )
.remove()
;
});
}( mediaWiki, jQuery ) );