Simplify JavaScript

Change-Id: Idfbb623c23a1b202869293e0b89cb83e6d41f4ad
This commit is contained in:
Fomafix 2021-09-14 20:07:34 +00:00 committed by Thiemo Kreuz (WMDE)
parent be484f6f0e
commit 6c36a1a3d7

View file

@ -34,12 +34,13 @@
function expandNode( $link ) { function expandNode( $link ) {
// Show the children node // Show the children node
var $children = $link.parents( '.CategoryTreeItem' ) var $children = $link.parents( '.CategoryTreeItem' )
.siblings( '.CategoryTreeChildren' ); .siblings( '.CategoryTreeChildren' )
$children.show(); .show();
$link $link.attr( {
.attr( 'title', mw.msg( 'categorytree-collapse' ) ) title: mw.msg( 'categorytree-collapse' ),
.attr( 'data-ct-state', 'expanded' ); 'data-ct-state': 'expanded'
} );
if ( !$link.data( 'ct-loaded' ) ) { if ( !$link.data( 'ct-loaded' ) ) {
loadChildren( $link, $children ); loadChildren( $link, $children );
@ -54,11 +55,13 @@
function collapseNode( $link ) { function collapseNode( $link ) {
// Hide the children node // Hide the children node
$link.parents( '.CategoryTreeItem' ) $link.parents( '.CategoryTreeItem' )
.siblings( '.CategoryTreeChildren' ).hide(); .siblings( '.CategoryTreeChildren' )
.hide();
$link $link.attr( {
.attr( 'title', mw.msg( 'categorytree-expand' ) ) title: mw.msg( 'categorytree-expand' ),
.attr( 'data-ct-state', 'collapsed' ); 'data-ct-state': 'collapsed'
} );
} }
/** /**
@ -164,33 +167,20 @@
data = data.categorytree.html; data = data.categorytree.html;
if ( data === '' ) { if ( data === '' ) {
switch ( ctMode ) { $data = $( '<i>' ).addClass( 'CategoryTreeNotice' )
// CategoryTreeMode::CATEGORIES = 0 // eslint-disable-next-line mediawiki/msg-doc
case 0: .text( mw.msg( {
data = mw.msg( 'categorytree-no-subcategories' ); 0: 'categorytree-no-subcategories',
break; 10: 'categorytree-no-pages',
// CategoryTreeMode::PAGES = 10 100: 'categorytree-no-parent-categories'
case 10: }[ ctMode ] || 'categorytree-nothing-found' ) );
data = mw.msg( 'categorytree-no-pages' );
break;
// CategoryTreeMode::PARENTS = 100
case 100:
data = mw.msg( 'categorytree-no-parent-categories' );
break;
// CategoryTreeMode::ALL = 20
default:
data = mw.msg( 'categorytree-nothing-found' );
}
$data = $( '<i>' ).addClass( 'CategoryTreeNotice' ).text( data );
} else { } else {
$data = $( $.parseHTML( data ) ); $data = $( $.parseHTML( data ) );
attachHandler( $data ); attachHandler( $data );
} }
$children.empty().append( $data ); $children.empty().append( $data );
} ) } ).fail( error );
.fail( error );
}; };
// Register click events // Register click events