Debian Codegraph @

resources/src/mediawiki.page.ready/checkboxShift.js

raw symbols SCIP
1 /**
2 * Enable checkboxes to be checked or unchecked in a row by clicking one,
3 * holding shift and clicking another one.
4 *
5 * @method checkboxShift
6 * @memberof module:mediawiki.page.ready
7 * @param {jQuery} $box
8 */
9 module.exports = function ( $box ) {
10 let prev;
11 // When our boxes are clicked..
12 $box.on( 'click', ( e ) => {
13 // And one has been clicked before...
14 if ( prev && e.shiftKey ) {
15 // Check or uncheck this one and all in-between checkboxes,
16 // except for disabled ones
17 $box
18 .slice(
19 Math.min( $box.index( prev ), $box.index( e.target ) ),
20 Math.max( $box.index( prev ), $box.index( e.target ) ) + 1
21 )
22 .filter( function () {
23 return !this.disabled && this.checked !== e.target.checked;
24 } )
25 .prop( 'checked', e.target.checked )
26 // Since the state change is a consequence of direct user action,
27 // fire the 'change' event (see T313077).
28 .trigger( 'change' );
29 }
30 // Either way, remember this as the last clicked one
31 prev = e.target;
32 } );
33 };