2010-10-27 15:02:18 +00:00
|
|
|
/**
|
|
|
|
|
* jQuery checkboxShiftClick
|
2010-11-12 23:10:58 +00:00
|
|
|
*
|
2010-10-27 15:02:18 +00:00
|
|
|
* This will enable checkboxes to be checked or unchecked in a row by clicking one, holding shift and clicking another one
|
2010-11-12 23:10:58 +00:00
|
|
|
*
|
2010-10-27 15:02:18 +00:00
|
|
|
* @author Krinkle <krinklemail@gmail.com>
|
|
|
|
|
* @license GPL v2
|
|
|
|
|
*/
|
2011-01-31 19:33:16 +00:00
|
|
|
( function( $ ) {
|
2011-01-10 05:33:03 +00:00
|
|
|
$.fn.checkboxShiftClick = function( text ) {
|
2010-10-27 15:02:18 +00:00
|
|
|
var prevCheckbox = null;
|
|
|
|
|
var $box = this;
|
|
|
|
|
// When our boxes are clicked..
|
2011-01-10 05:33:03 +00:00
|
|
|
$box.click( function( e ) {
|
2010-10-27 15:02:18 +00:00
|
|
|
// And one has been clicked before...
|
2011-01-10 05:33:03 +00:00
|
|
|
if ( prevCheckbox !== null && e.shiftKey ) {
|
2010-10-27 15:02:18 +00:00
|
|
|
// Check or uncheck this one and all in-between checkboxes
|
|
|
|
|
$box.slice(
|
2011-08-12 21:48:10 +00:00
|
|
|
Math.min( $box.index( prevCheckbox ), $box.index( e.target ) ),
|
|
|
|
|
Math.max( $box.index( prevCheckbox ), $box.index( e.target ) ) + 1
|
|
|
|
|
).prop( 'checked', e.target.checked ? true : false );
|
2010-10-27 15:02:18 +00:00
|
|
|
}
|
|
|
|
|
// Either way, update the prevCheckbox variable to the one clicked now
|
|
|
|
|
prevCheckbox = e.target;
|
2011-01-10 05:33:03 +00:00
|
|
|
} );
|
2010-10-27 15:02:18 +00:00
|
|
|
return $box;
|
2011-01-31 19:33:16 +00:00
|
|
|
};
|
|
|
|
|
} )( jQuery );
|