Few more return types
[mediawiki.git] / resources / jquery / jquery.checkboxShiftClick.js
blobcfa696d479cef5e621b484aacb9074a0aa290727
1 /**
2  * jQuery checkboxShiftClick
3  *
4  * This will enable checkboxes to be checked or unchecked in a row by clicking one, holding shift and clicking another one
5  *
6  * @author Krinkle <krinklemail@gmail.com>
7  * @license GPL v2
8  */
9 ( function( $ ) {
10 $.fn.checkboxShiftClick = function( text ) {
11         var prevCheckbox = null;
12         var $box = this;
13         // When our boxes are clicked..
14         $box.click( function( e ) {
15                 // And one has been clicked before...
16                 if ( prevCheckbox !== null && e.shiftKey ) {
17                         // Check or uncheck this one and all in-between checkboxes
18                         $box.slice(
19                           Math.min( $box.index( prevCheckbox ), $box.index( e.target ) ),
20                           Math.max( $box.index( prevCheckbox ), $box.index( e.target ) ) + 1
21                         ).attr( {checked: e.target.checked ? 'checked' : ''} );
22                 }
23                 // Either way, update the prevCheckbox variable to the one clicked now
24                 prevCheckbox = e.target;
25         } );
26         return $box;
28 } )( jQuery );