Merge "Use lower memory limits"
[mediawiki.git] / resources / jquery / jquery.checkboxShiftClick.js
blobb206566541fe8272ea05878fcf9fe4b7bba1245c
1 /**
2  * jQuery checkboxShiftClick
3  *
4  * This will enable checkboxes to be checked or unchecked in a row by clicking one,
5  * holding shift and clicking another one.
6  *
7  * @author Timo Tijhof, 2011 - 2012
8  * @license GPL v2
9  */
10 ( function ( $ ) {
11         $.fn.checkboxShiftClick = function () {
12                 var prevCheckbox = null,
13                         $box = this;
14                 // When our boxes are clicked..
15                 $box.click( function ( e ) {
16                         // And one has been clicked before...
17                         if ( prevCheckbox !== null && e.shiftKey ) {
18                                 // Check or uncheck this one and all in-between checkboxes,
19                                 // except for disabled ones
20                                 $box
21                                         .slice(
22                                                 Math.min( $box.index( prevCheckbox ), $box.index( e.target ) ),
23                                                 Math.max( $box.index( prevCheckbox ), $box.index( e.target ) ) + 1
24                                         )
25                                         .filter( function () {
26                                                 return !this.disabled;
27                                         } )
28                                         .prop( 'checked', !!e.target.checked );
29                         }
30                         // Either way, update the prevCheckbox variable to the one clicked now
31                         prevCheckbox = e.target;
32                 } );
33                 return $box;
34         };
35 }( jQuery ) );