Make WordPress Core

Ticket #6541: shiftcheckbox.diff

File shiftcheckbox.diff, 4.4 KB (added by sillybean, 10 years ago)

restores ability to select consecutive checkboxes by shift-clicking

  • wp-includes/js/jquery/jquery.shiftcheckbox.js

     
     1/**
     2 * JQuery shiftcheckbox plugin
     3 *
     4 * shiftcheckbox provides a simpler and faster way to select/unselect multiple checkboxes within a given range with just two clicks.
     5 * Inspired from GMail checkbox functionality
     6 *
     7 * Just call $('.<class-name>').shiftcheckbox() in $(document).ready
     8 *
     9 * @name shiftcheckbox
     10 * @type jquery
     11 * @cat Plugin/Form
     12 * @return JQuery
     13 *
     14 * @URL http://www.sanisoft.com/blog/2009/07/02/jquery-shiftcheckbox-plugin
     15 *
     16 * Copyright (c) 2009 Aditya Mooley <adityamooley@sanisoft.com>
     17 * Dual licensed under the MIT (MIT-LICENSE.txt) and GPL (GPL-LICENSE.txt) licenses
     18 */
     19
     20(function ($) {
     21    $.fn.shiftcheckbox = function()
     22    {
     23        var prevChecked = null;
     24
     25        selectorStr = this;
     26
     27        $(selectorStr).bind("click", handleClick);
     28    };
     29
     30    function handleClick(event)
     31    {
     32        var val = this.value;
     33        var checkStatus = this.checked;
     34        //get the checkbox number which the user has checked
     35
     36        //check whether user has pressed shift
     37        if (event.shiftKey) {
     38            if (prevChecked != 'null') {
     39                //get the current checkbox number
     40                var ind = 0, found = 0, currentChecked;
     41                currentChecked = getSelected(val);
     42
     43                ind = 0;
     44                if (currentChecked < prevChecked) {
     45                    $(selectorStr).each(function(i) {
     46                        if (ind >= currentChecked && ind <= prevChecked) {
     47                            this.checked = checkStatus;
     48                        }
     49                        ind++;
     50                    });
     51                } else {
     52                    $(selectorStr).each(function(i) {
     53                        if (ind >= prevChecked && ind <= currentChecked) {
     54                            this.checked = checkStatus;
     55                        }
     56                        ind++;
     57                    });
     58                }
     59
     60                prevChecked = currentChecked;
     61            }
     62        } else {
     63            if (checkStatus) {
     64                prevChecked = getSelected(val);
     65            }
     66        }
     67    };
     68
     69    function getSelected(val)
     70    {
     71        var ind = 0, found = 0, checkedIndex;
     72
     73        $(selectorStr).each(function(i) {
     74            if (val == this.value && found != 1) {
     75                checkedIndex = ind;
     76                found = 1;
     77            }
     78            ind++;
     79        });
     80
     81        return checkedIndex;
     82    };
     83})(jQuery);
     84 No newline at end of file
  • wp-includes/script-loader.php

     
    185185        $scripts->add( 'jquery-table-hotkeys', "/wp-includes/js/jquery/jquery.table-hotkeys$suffix.js", array('jquery', 'jquery-hotkeys'), false, 1 );
    186186        $scripts->add( 'jquery-touch-punch', "/wp-includes/js/jquery/jquery.ui.touch-punch.js", array('jquery-ui-widget', 'jquery-ui-mouse'), '0.2.2', 1 );
    187187        $scripts->add( 'jquery-masonry', "/wp-includes/js/jquery/jquery.masonry.min.js", array('jquery'), '2.1.05', 1 );
     188        $scripts->add( 'jquery-shiftcheckbox', "/wp-includes/js/jquery/jquery.shiftcheckbox.min.js", array('jquery'), false, 1 );
    188189
    189190        $scripts->add( 'thickbox', "/wp-includes/js/thickbox/thickbox.js", array('jquery'), '3.1-20121105', 1 );
    190191        did_action( 'init' ) && $scripts->localize( 'thickbox', 'thickboxL10n', array(
  • wp-admin/js/common.js

     
    326326                        return false;
    327327                });
    328328        });
     329       
     330        $('th.check-column input').shiftcheckbox();
    329331
    330332        $('#default-password-nag-no').click( function() {
    331333                setUserSetting('default_password_nag', 'hide');
  • wp-admin/admin-header.php

     
    4545wp_enqueue_style( 'colors' );
    4646wp_enqueue_style( 'ie' );
    4747wp_enqueue_script('utils');
     48wp_enqueue_script( 'jquery-shiftcheckbox' );
    4849
    4950$admin_body_class = preg_replace('/[^a-z0-9_-]+/i', '-', $hook_suffix);
    5051?>