mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/CategoryTree
synced 2024-11-27 09:43:06 +00:00
Remove redundant closure for all modules with packageFiles
Modules loaded with packageFiles are always executed in module scope (with a closure), even in debug mode. The behaviour of non-packageFiles debug mode is the only reason files have closures. https://www.mediawiki.org/wiki/Manual:Coding_conventions/JavaScript#Closure Change-Id: I7ea2057029a63148a96333af7ff09a7885d2daa8
This commit is contained in:
parent
0eb9b7d86c
commit
9c5ccf4b74
|
@ -22,15 +22,14 @@
|
|||
* @author Daniel Kinzler, brightbyte.de
|
||||
*/
|
||||
|
||||
( function () {
|
||||
const config = require( './data.json' );
|
||||
const config = require( './data.json' );
|
||||
|
||||
/**
|
||||
/**
|
||||
* Expands a given node (loading it's children if not loaded)
|
||||
*
|
||||
* @param {jQuery} $link
|
||||
*/
|
||||
function expandNode( $link ) {
|
||||
function expandNode( $link ) {
|
||||
// Show the children node
|
||||
const $children = $link.parents( '.CategoryTreeItem' )
|
||||
.siblings( '.CategoryTreeChildren' )
|
||||
|
@ -44,14 +43,14 @@
|
|||
if ( !$link.data( 'ct-loaded' ) ) {
|
||||
loadChildren( $link, $children );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Collapses a node
|
||||
*
|
||||
* @param {jQuery} $link
|
||||
*/
|
||||
function collapseNode( $link ) {
|
||||
function collapseNode( $link ) {
|
||||
// Hide the children node
|
||||
$link.parents( '.CategoryTreeItem' )
|
||||
.siblings( '.CategoryTreeChildren' )
|
||||
|
@ -61,14 +60,14 @@
|
|||
title: mw.msg( 'categorytree-expand' ),
|
||||
'aria-expanded': 'false'
|
||||
} );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Handles clicks on the expand buttons, and calls the appropriate function
|
||||
*
|
||||
* @param {jQuery.Event} e
|
||||
*/
|
||||
function handleNode( e ) {
|
||||
function handleNode( e ) {
|
||||
e.preventDefault();
|
||||
|
||||
const $link = $( this );
|
||||
|
@ -77,14 +76,14 @@
|
|||
} else {
|
||||
collapseNode( $link );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Attach click handler to buttons
|
||||
*
|
||||
* @param {jQuery} $content
|
||||
*/
|
||||
function attachHandler( $content ) {
|
||||
function attachHandler( $content ) {
|
||||
$content.find( '.CategoryTreeToggle' )
|
||||
.on( 'click', handleNode )
|
||||
.attr( {
|
||||
|
@ -98,15 +97,15 @@
|
|||
}
|
||||
} )
|
||||
.addClass( 'CategoryTreeToggleHandlerAttached' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Loads children for a node via an HTTP call
|
||||
*
|
||||
* @param {jQuery} $link
|
||||
* @param {jQuery} $children
|
||||
*/
|
||||
function loadChildren( $link, $children ) {
|
||||
function loadChildren( $link, $children ) {
|
||||
/**
|
||||
* Error callback
|
||||
*/
|
||||
|
@ -180,19 +179,17 @@
|
|||
|
||||
$children.empty().append( $data );
|
||||
} ).fail( error );
|
||||
}
|
||||
}
|
||||
|
||||
// Register click events
|
||||
mw.hook( 'wikipage.content' ).add( attachHandler );
|
||||
// Register click events
|
||||
mw.hook( 'wikipage.content' ).add( attachHandler );
|
||||
|
||||
// Attach click handler for categories.
|
||||
// This is needed when wgCategoryTreeHijackPageCategories is enabled.
|
||||
mw.hook( 'wikipage.categories' ).add( attachHandler );
|
||||
// Attach click handler for categories.
|
||||
// This is needed when wgCategoryTreeHijackPageCategories is enabled.
|
||||
mw.hook( 'wikipage.categories' ).add( attachHandler );
|
||||
|
||||
$( () => {
|
||||
$( () => {
|
||||
// Attach click handler for sidebar
|
||||
// eslint-disable-next-line no-jquery/no-global-selector
|
||||
attachHandler( $( '#p-categorytree-portlet' ) );
|
||||
} );
|
||||
|
||||
}() );
|
||||
} );
|
||||
|
|
Loading…
Reference in a new issue