MediaWiki:Gadget-SeparateSpecialCategories.js

Poznámka: Po uložení musíte vyprázdnit mezipaměť vašeho prohlížeče, jinak změny neuvidíte.

/** * @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';vari,categoryTypes,categoryTypesLength,categoryPrefixes,rgxCategoryPrefixes;categoryTypes = [{id: 'MaintenanceCats',prefix: 'Údržba:',infoPage: new mw.Title( 'Project:Údržba' ),infoText: 'Údržba',removePrefix: true,treatAsExisting: false}, {id: 'MonitoringCats',prefix: 'Monitoring:',infoPage: new mw.Title( 'Project:Monitoring' ),infoText: 'Monitoring',removePrefix: true,treatAsExisting: false}];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 ( categoryType.treatAsExisting ) {$( this ).removeClass( 'new' ).attr( 'href', function ( index, value ) {return new mw.Title( new mw.Uri( value ).query.title ).getUrl();});}});};}$( document ).ready( function () {varcategoryNamespaceName,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 ) );