summaryrefslogtreecommitdiff
path: root/www/wiki/resources/src/mediawiki/mediawiki.checkboxtoggle.js
blob: 76bc86c5c0178b038cd46f1b676a5664351a0c61 (plain)
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
/*!
 * Allows users to perform all / none / invert operations on a list of
 * checkboxes on the page.
 *
 * @licence GNU GPL v2+
 * @author Luke Faraone <luke at faraone dot cc>
 *
 * Based on ext.nuke.js from https://www.mediawiki.org/wiki/Extension:Nuke by
 * Jeroen De Dauw <jeroendedauw at gmail dot com>
 */

( function ( $ ) {
	'use strict';

	$( function () {
		// FIXME: This shouldn't be a global selector to avoid conflicts
		// with unrelated content on the same page. (T131318)
		var $checkboxes = $( 'li input[type="checkbox"]' );

		function selectAll( check ) {
			$checkboxes.prop( 'checked', check );
		}

		$( '.mw-checkbox-all' ).click( function () {
			selectAll( true );
		} );
		$( '.mw-checkbox-none' ).click( function () {
			selectAll( false );
		} );
		$( '.mw-checkbox-invert' ).click( function () {
			$checkboxes.prop( 'checked', function ( i, val ) {
				return !val;
			} );
		} );

	} );

}( jQuery ) );