Merge "Bump wikimedia/parsoid to 0.21.0-a11"
[mediawiki.git] / resources / src / mediawiki.special.watchlist / editwatchlist.js
blobd8e855c97eb15400e008a82237d6f8613b4e189f
1 /*!
2  * JavaScript for Special:EditWatchlist
3  */
4 ( function () {
5         $( () => {
6                 let checkAllChangeOngoing = false;
7                 let multiselectChangeOngoing = false;
9                 const checkAllCheckboxes = $( '.mw-watchlistedit-checkall .oo-ui-checkboxInputWidget' )
10                         .toArray()
11                         .map( ( element ) => OO.ui.infuse( element ) );
13                 const multiselects = $( '.mw-watchlistedit-check .oo-ui-checkboxMultiselectInputWidget' )
14                         .toArray()
15                         .map( ( element ) => OO.ui.infuse( element ).checkboxMultiselectWidget );
17                 checkAllCheckboxes.forEach( ( checkbox, index ) => {
18                         checkbox.on( 'change', ( isChecked ) => {
19                                 if ( multiselectChangeOngoing ) {
20                                         return;
21                                 }
22                                 checkAllChangeOngoing = true;
24                                 // Select or de-select all the title checkboxes for this namespace
25                                 const multiselect = multiselects[ index ];
26                                 multiselect.selectItems( isChecked ? multiselect.items : [] );
28                                 checkAllChangeOngoing = false;
29                         } );
30                 } );
32                 multiselects.forEach( ( multiselect, index ) => {
33                         multiselect.on( 'change', () => {
34                                 if ( checkAllChangeOngoing ) {
35                                         return;
36                                 }
37                                 multiselectChangeOngoing = true;
39                                 // Update the state of the check-all checkbox for this namespace
40                                 const checkAllCheckbox = checkAllCheckboxes[ index ];
41                                 const numSelectedItems = multiselect.findSelectedItems().length;
42                                 if ( numSelectedItems === multiselect.items.length ) {
43                                         checkAllCheckbox.setSelected( true );
44                                         checkAllCheckbox.setIndeterminate( false );
45                                 } else if ( numSelectedItems === 0 ) {
46                                         checkAllCheckbox.setSelected( false );
47                                         checkAllCheckbox.setIndeterminate( false );
48                                 } else {
49                                         checkAllCheckbox.setIndeterminate( true );
50                                 }
52                                 multiselectChangeOngoing = false;
53                         } );
54                 } );
55         } );
56 }() );