[ Index ]

PHP Cross Reference of MediaWiki-1.24.0

title

Body

[close]

/resources/src/jquery/ -> jquery.checkboxShiftClick.js (source)

   1  /**
   2   * @class jQuery.plugin.checkboxShiftClick
   3   */
   4  ( function ( $ ) {
   5  
   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      };
  37  
  38      /**
  39       * @class jQuery
  40       * @mixins jQuery.plugin.checkboxShiftClick
  41       */
  42  
  43  }( jQuery ) );


Generated: Fri Nov 28 14:03:12 2014 Cross-referenced by PHPXref 0.7.1