MediaWiki:Gadget-SeparateSpecialCategories.js
Poznámka: Po zveřejnění musíte vyprázdnit cache vašeho prohlížeče, jinak změny neuvidíte.
- Firefox / Safari: Při kliknutí na Aktualizovat držte Shift nebo stiskněte Ctrl-F5 nebo Ctrl-R (na Macu ⌘-R)
- Google Chrome: Stiskněte Ctrl-Shift-R (na Macu ⌘-Shift-R)
- Internet Explorer / Edge: Při kliknutí na Aktualizovat držte Ctrl nebo stiskněte Ctrl-F5
- Opera: Stiskněte Ctrl-F5.
/**
* @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.
* Na Special:WantedCategories umožní odfiltrování speciálních typů kategorií.
*
* @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
i,
categoryTypes,
categoryTypesLength,
categoryPrefixes,
rgxCategoryPrefixes;
categoryTypes = [
{
id: 'AuthorCats',
prefix: 'Autoři:',
infoPage: new mw.Title( 'Project:Autoři' ),
infoText: 'Autoři',
removePrefix: true,
treatAsExisting: true
}, {
id: 'MetadataCats',
prefix: 'Metadata:',
infoPage: new mw.Title( 'Project:Metadata' ),
infoText: 'Metadata',
removePrefix: true,
treatAsExisting: true
}, {
id: 'MaintenanceCats',
prefix: 'Údržba:',
infoPage: new mw.Title( 'Project:Údržba' ),
infoText: 'Údržba',
removePrefix: true,
treatAsExisting: false
}, {
id: 'WikidataCats',
prefix: 'Wikidata:',
infoPage: new mw.Title( 'Project:Wikidata' ),
infoText: 'Wikidata',
removePrefix: true,
treatAsExisting: true
}, {
id: 'MonitoringCats',
prefix: 'Monitoring:',
infoPage: new mw.Title( 'Project:Monitoring' ),
infoText: 'Monitoring',
removePrefix: true,
treatAsExisting: true
}
];
categoryTypesLength = categoryTypes.length;
categoryPrefixes = categoryTypes[0].prefix;
for ( i = 1; i < categoryTypesLength; i++ ) {
categoryPrefixes += '|' + categoryTypes[i].prefix;
}
rgxCategoryPrefixes = new RegExp( '^(' + categoryPrefixes + ')' );
if (
(
!mw.config.get( 'wgIsArticle' )
|| mw.config.get( 'wgIsRedirect' )
|| ( mw.config.get( 'wgNamespaceNumber' ) === 14 && rgxCategoryPrefixes.test( mw.config.get( 'wgTitle' ) ) )
|| !$.grep( mw.config.get( 'wgCategories' ), function ( item ) { return rgxCategoryPrefixes.test( item ); } ).length
)
&& !( mw.config.get( 'wgNamespaceNumber' ) === -1 && mw.config.get( 'wgCanonicalSpecialPageName' ) === 'Wantedcategories' )
) {
return;
}
function makeClickHandler( categoryFullPrefix ) {
return function () {
$( 'body.mw-special-Wantedcategories div.mw-spcontent ol li a[title^="' + categoryFullPrefix + '"]' )
.closest( 'li' )
.toggle( $( this ).prop( 'checked' ) )
;
};
}
function makeSpecialCategoryLink( categoryType ) {
return function () {
$( this )
.find( '> a' )
.each( function () {
if ( categoryType.removePrefix ) {
$( this ).text( $( this ).text().replace( categoryType.prefix, '' ) );
}
if ( $( this ).hasClass( 'new' ) && categoryType.treatAsExisting ) {
$( this )
.removeClass( 'new' )
.attr( 'href', function ( index, value ) {
return new mw.Title( new mw.Uri( value ).query.title ).getUrl();
})
;
}
})
;
};
}
$( document ).ready( function () {
var
categoryNamespaceName,
categoryType,
elementId,
categoryPrefix,
categoryFullPrefix;
categoryNamespaceName = mw.config.get( 'wgFormattedNamespaces' )[14];
for ( i = 0; i < categoryTypesLength; i++ ) {
categoryType = categoryTypes[i];
elementId = 'mwg-' + categoryType.id;
categoryPrefix = categoryType.prefix;
categoryFullPrefix = categoryNamespaceName + ':' + categoryPrefix;
if (
mw.config.get( 'wgNamespaceNumber' ) === -1
&& mw.config.get( 'wgCanonicalSpecialPageName' ) === 'Wantedcategories'
&& $( 'div.mw-spcontent ol.special a[title^="' + categoryFullPrefix + '"]' ).length
) {
$( 'div.mw-spcontent ol.special' ).before(
$( '<input>' )
.attr({
id: elementId,
type: 'checkbox',
checked: 'checked'
})
.click(
makeClickHandler( categoryFullPrefix )
),
' ',
$( '<label>' )
.attr({
'for': elementId
})
.text( categoryPrefix )
);
} else if ( $( '#catlinks ul a[title^="' + categoryFullPrefix + '"]' ).length ) {
$( '<div>' )
.attr({
'class': 'catlinks mwg-specialcatlinks',
'id': elementId
})
.append(
$( '<a>' )
.attr({
href: categoryType.infoPage.getUrl(),
title: categoryType.infoPage.getPrefixedText()
})
.text( categoryType.infoText )
,
': ',
$( '<ul>' )
)
.insertAfter( $( '.catlinks' ).last() )
.children( 'ul' )
.append(
$( '#catlinks ul li' )
.has( 'a[title^="' + categoryFullPrefix + '"]' )
.each( makeSpecialCategoryLink( categoryType ) )
)
;
}
}
$( '#mw-normal-catlinks' ).has( 'ul:empty' ).remove();
$( '#mw-hidden-catlinks' ).has( 'ul:empty' ).remove();
$( '#catlinks:empty' ).remove();
});
}( mediaWiki, jQuery ) );