Import: Handle uploads with sha1 starting with 0 properly
[mediawiki.git] / resources / src / jquery / jquery.checkboxShiftClick.js
blobd99e9f0a8bb44dd7b85c2d2939aba0518ed569aa
1 /**
2  * @class jQuery.plugin.checkboxShiftClick
3  */
4 ( function ( $ ) {
6         /**
7          * Enable checkboxes to be checked or unchecked in a row by clicking one,
8          * holding shift and clicking another one.
9          *
10          * @return {jQuery}
11          * @chainable
12          */
13         $.fn.checkboxShiftClick = function () {
14                 var prevCheckbox = null,
15                         $box = this;
16                 // When our boxes are clicked..
17                 $box.click( function ( e ) {
18                         // And one has been clicked before...
19                         if ( prevCheckbox !== null && e.shiftKey ) {
20                                 // Check or uncheck this one and all in-between checkboxes,
21                                 // except for disabled ones
22                                 $box
23                                         .slice(
24                                                 Math.min( $box.index( prevCheckbox ), $box.index( e.target ) ),
25                                                 Math.max( $box.index( prevCheckbox ), $box.index( e.target ) ) + 1
26                                         )
27                                         .filter( function () {
28                                                 return !this.disabled;
29                                         } )
30                                         .prop( 'checked', !!e.target.checked );
31                         }
32                         // Either way, update the prevCheckbox variable to the one clicked now
33                         prevCheckbox = e.target;
34                 } );
35                 return $box;
36         };
38         /**
39          * @class jQuery
40          * @mixins jQuery.plugin.checkboxShiftClick
41          */
43 }( jQuery ) );