aboutsummaryrefslogtreecommitdiffstats
path: root/resources/src/mediawiki.special.recentchanges.js
blob: c62acd90caae7394d473352c8b0bbee0c5cb013e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*!
 * JavaScript for Special:RecentChanges
 */
( function () {
	var rc, $checkboxes, $select, namespaceDropdown;

	/**
	 * @class mw.special.recentchanges
	 * @singleton
	 */
	rc = {
		/**
		 * Handler to hide/show the namespace selector checkboxes when the
		 * special 'all' namespace is selected/unselected respectively.
		 */
		updateCheckboxes: function () {
			// The option element for the 'all' namespace has an empty value
			var value = $select.val(),
				isAllNS = value === 'all' || value === '';

			// Iterates over checkboxes and propagate the selected option
			$checkboxes.toggleClass( 'mw-input-hidden', isAllNS );
		},

		init: function () {
			$select = $( 'select#namespace' );
			$checkboxes = $( '#nsassociated, #nsinvert, .contribs-ns-filters' )
				.closest( '.mw-input-with-label' );

			if ( $select.length === 0 ) {
				$select = $( '#namespace select' );
				if ( $select.length > 0 ) {
					namespaceDropdown = OO.ui.infuse( $( '#namespace' ).closest( '[data-ooui]' ) );
					namespaceDropdown.on( 'change', rc.updateCheckboxes );
				}
			} else {
				// Bind to change event of the checkboxes.
				// The initial state is already set in HTML.
				$select.on( 'change', rc.updateCheckboxes );
			}
		}
	};

	$( rc.init );

	module.exports = rc;

}() );