Make WordPress Core

Changeset 26889


Ignore:
Timestamp:
01/02/2014 12:10:20 AM (13 years ago)
Author:
azaozz
Message:

Comment moderation shortcuts:

  • Fix "toggle checkboxes" (shift+x).
  • Add noDisable selector and use it to stop disabling the shortcuts when a select-comment checkbox is focused.

See #26755.

Location:
trunk/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/js/common.js

    r26785 r26889  
    1 /* global setUserSetting, ajaxurl, commonL10n, alert, confirm, toggleWithKeyboard, pagenow */
     1/* global setUserSetting, ajaxurl, commonL10n, alert, confirm, pagenow */
    22var showNotice, adminMenu, columns, validateForm, screenMeta;
    33( function( $, window, undefined ) {
     
    347347        });
    348348
    349         $('thead, tfoot').find('.check-column :checkbox').click( function(e) {
    350                 var c = $(this).prop('checked'),
    351                         kbtoggle = 'undefined' == typeof toggleWithKeyboard ? false : toggleWithKeyboard,
    352                         toggle = e.shiftKey || kbtoggle;
    353 
    354                 $(this).closest( 'table' ).children( 'tbody' ).filter(':visible')
    355                 .children().children('.check-column').find(':checkbox')
    356                 .prop('checked', function() {
    357                         if ( $(this).is(':hidden') )
     349        $('thead, tfoot').find('.check-column :checkbox').on( 'click.wp-toggle-checkboxes', function( event ) {
     350                var $this = $(this),
     351                        $table = $this.closest( 'table' ),
     352                        controlChecked = $this.prop('checked'),
     353                        toggle = event.shiftKey || $this.data('wp-toggle');
     354
     355                $table.children( 'tbody' ).filter(':visible')
     356                        .children().children('.check-column').find(':checkbox')
     357                        .prop('checked', function() {
     358                                if ( $(this).is(':hidden') ) {
     359                                        return false;
     360                                }
     361
     362                                if ( toggle ) {
     363                                        return ! $(this).prop( 'checked' );
     364                                } else if ( controlChecked ) {
     365                                        return true;
     366                                }
     367
    358368                                return false;
    359                         if ( toggle )
    360                                 return $(this).prop( 'checked' );
    361                         else if (c)
    362                                 return true;
    363                         return false;
    364                 });
    365 
    366                 $(this).closest('table').children('thead,  tfoot').filter(':visible')
    367                 .children().children('.check-column').find(':checkbox')
    368                 .prop('checked', function() {
    369                         if ( toggle )
     369                        });
     370
     371                $table.children('thead,  tfoot').filter(':visible')
     372                        .children().children('.check-column').find(':checkbox')
     373                        .prop('checked', function() {
     374                                if ( toggle ) {
     375                                        return false;
     376                                } else if ( controlChecked ) {
     377                                        return true;
     378                                }
     379
    370380                                return false;
    371                         else if (c)
    372                                 return true;
    373                         return false;
    374                 });
     381                        });
    375382        });
    376383
  • trunk/src/wp-admin/js/edit-comments.js

    r26550 r26889  
    11/* global adminCommentsL10n, thousandsSeparator, list_args, QTags, ajaxurl, wpAjax */
    2 var setCommentsList, theList, theExtraList, commentReply,
    3         toggleWithKeyboard = false;
     2var setCommentsList, theList, theExtraList, commentReply;
    43
    54(function($) {
     
    595594
    596595                toggle_all = function() {
    597                         toggleWithKeyboard = true;
    598                         $('input:checkbox', '#cb').click().prop('checked', false);
    599                         toggleWithKeyboard = false;
     596                        $('#cb-select-all-1').data( 'wp-toggle', 1 ).trigger( 'click' ).removeData( 'wp-toggle' );
    600597                };
    601598
     
    610607                $.table_hotkeys(
    611608                        $('table.widefat'),
    612                         ['a', 'u', 's', 'd', 'r', 'q', 'z', ['e', edit_comment], ['shift+x', toggle_all],
    613                         ['shift+a', make_bulk('approve')], ['shift+s', make_bulk('spam')],
    614                         ['shift+d', make_bulk('delete')], ['shift+t', make_bulk('trash')],
    615                         ['shift+z', make_bulk('untrash')], ['shift+u', make_bulk('unapprove')]],
    616                         { highlight_first: adminCommentsL10n.hotkeys_highlight_first, highlight_last: adminCommentsL10n.hotkeys_highlight_last,
    617                         prev_page_link_cb: make_hotkeys_redirect('prev'), next_page_link_cb: make_hotkeys_redirect('next') }
     609                        [
     610                                'a', 'u', 's', 'd', 'r', 'q', 'z',
     611                                ['e', edit_comment],
     612                                ['shift+x', toggle_all],
     613                                ['shift+a', make_bulk('approve')],
     614                                ['shift+s', make_bulk('spam')],
     615                                ['shift+d', make_bulk('delete')],
     616                                ['shift+t', make_bulk('trash')],
     617                                ['shift+z', make_bulk('untrash')],
     618                                ['shift+u', make_bulk('unapprove')]
     619                        ],
     620                        {
     621                                highlight_first: adminCommentsL10n.hotkeys_highlight_first,
     622                                highlight_last: adminCommentsL10n.hotkeys_highlight_last,
     623                                prev_page_link_cb: make_hotkeys_redirect('prev'),
     624                                next_page_link_cb: make_hotkeys_redirect('next'),
     625                                hotkeys_opts: {
     626                                        disableInInput: true,
     627                                        type: 'keypress',
     628                                        noDisable: '.check-column input[type="checkbox"]'
     629                                }
     630                        }
    618631                );
    619632        }
  • trunk/src/wp-includes/js/jquery/jquery.hotkeys.js

    r21592 r26889  
    11/******************************************************************************************************************************
    22
    3  * @ Original idea by by Binny V A, Original version: 2.00.A 
     3 * @ Original idea by by Binny V A, Original version: 2.00.A
    44 * @ http://www.openjs.com/scripts/events/keyboard_shortcuts/
    55 * @ Original License : BSD
    6  
    7  * @ jQuery Plugin by Tzury Bar Yochay 
     6
     7 * @ jQuery Plugin by Tzury Bar Yochay
    88        mail: tzury.by@gmail.com
    99        blog: evalinux.wordpress.com
    1010        face: facebook.com/profile.php?id=513676303
    11        
     11
    1212        (c) Copyrights 2007
    13        
     13
    1414 * @ jQuery Plugin version Beta (0.0.2)
    1515 * @ License: jQuery-License.
    16  
     16
    1717TODO:
    1818    add queue support (as in gmail) e.g. 'x' then 'y', etc.
     
    2222    $.hotkeys.add('Ctrl+c', function(){ alert('copy anyone?');});
    2323    $.hotkeys.add('Ctrl+c', {target:'div#editor', type:'keyup', propagate: true},function(){ alert('copy anyone?');});>
    24     $.hotkeys.remove('Ctrl+c'); 
    25     $.hotkeys.remove('Ctrl+c', {target:'div#editor', type:'keypress'}); 
    26    
     24    $.hotkeys.remove('Ctrl+c');
     25    $.hotkeys.remove('Ctrl+c', {target:'div#editor', type:'keypress'});
     26
    2727******************************************************************************************************************************/
    2828(function (jQuery){
     
    3030        this.all = {};
    3131    this.special_keys = {
    32         27: 'esc', 9: 'tab', 32:'space', 13: 'return', 8:'backspace', 145: 'scroll', 20: 'capslock', 
    33         144: 'numlock', 19:'pause', 45:'insert', 36:'home', 46:'del',35:'end', 33: 'pageup', 
    34         34:'pagedown', 37:'left', 38:'up', 39:'right',40:'down', 112:'f1',113:'f2', 114:'f3', 
     32        27: 'esc', 9: 'tab', 32:'space', 13: 'return', 8:'backspace', 145: 'scroll', 20: 'capslock',
     33        144: 'numlock', 19:'pause', 45:'insert', 36:'home', 46:'del',35:'end', 33: 'pageup',
     34        34:'pagedown', 37:'left', 38:'up', 39:'right',40:'down', 112:'f1',113:'f2', 114:'f3',
    3535        115:'f4', 116:'f5', 117:'f6', 118:'f7', 119:'f8', 120:'f9', 121:'f10', 122:'f11', 123:'f12'};
    36        
    37     this.shift_nums = { "`":"~", "1":"!", "2":"@", "3":"#", "4":"$", "5":"%", "6":"^", "7":"&", 
    38         "8":"*", "9":"(", "0":")", "-":"_", "=":"+", ";":":", "'":"\"", ",":"<", 
     36
     37    this.shift_nums = { "`":"~", "1":"!", "2":"@", "3":"#", "4":"$", "5":"%", "6":"^", "7":"&",
     38        "8":"*", "9":"(", "0":")", "-":"_", "=":"+", ";":":", "'":"\"", ",":"<",
    3939        ".":">",  "/":"?",  "\\":"|" };
    40        
     40
    4141    this.add = function(combi, options, callback) {
    4242        if (jQuery.isFunction(options)){
     
    4848            that = this;
    4949        opt = jQuery.extend( opt , defaults, options || {} );
    50         combi = combi.toLowerCase();       
    51        
     50        combi = combi.toLowerCase();
     51
    5252        // inspect if keystroke matches
    5353        var inspector = function(event) {
     
    5858            // WP: not needed with newer jQuery
    5959            // element = (element.nodeType==3) ? element.parentNode : element;
    60            
    61             if(opt['disableInInput']) { // Disable shortcut keys in Input, Textarea fields
     60
     61            if ( opt['disableInInput'] ) { // Disable shortcut keys in Input, Textarea fields
    6262                var target = jQuery(element);
    63                 if( target.is("input") || target.is("textarea")){
    64                     return;
     63
     64                                if ( ( target.is('input') || target.is('textarea') ) &&
     65                                        ( ! opt.noDisable || ! target.is( opt.noDisable ) ) ) {
     66
     67                                        return;
    6568                }
    6669            }
     
    7578                propagate = true, // default behaivour
    7679                mapPoint = null;
    77            
     80
    7881            // in opera + safari, the event.target is unpredictable.
    79             // for example: 'keydown' might be associated with HtmlBodyElement 
     82            // for example: 'keydown' might be associated with HtmlBodyElement
    8083            // or the element where you last clicked with your mouse.
    81             // WP: needed for all browsers 
     84            // WP: needed for all browsers
    8285            // if (jQuery.browser.opera || jQuery.browser.safari){
    8386                while (!that.all[element] && element.parentNode){
     
    107110                }
    108111            }
    109                 };       
     112                };
    110113        // first hook for this element
    111114        if (!this.all[opt.target]){
     
    115118            this.all[opt.target].events[opt.type] = {callbackMap: {}}
    116119            jQuery.event.add(opt.target, opt.type, inspector);
    117         }       
    118         this.all[opt.target].events[opt.type].callbackMap[combi] =  {cb: callback, propagate:opt.propagate};               
     120        }
     121        this.all[opt.target].events[opt.type].callbackMap[combi] =  {cb: callback, propagate:opt.propagate};
    119122        return jQuery;
    120         };   
     123        };
    121124    this.remove = function(exp, opt) {
    122125        opt = opt || {};
    123126        target = opt.target || jQuery('html')[0];
    124127        type = opt.type || 'keydown';
    125                 exp = exp.toLowerCase();       
    126         delete this.all[target].events[type].callbackMap[exp]       
     128                exp = exp.toLowerCase();
     129        delete this.all[target].events[type].callbackMap[exp]
    127130        return jQuery;
    128131        };
    129132    jQuery.hotkeys = this;
    130     return jQuery;   
     133    return jQuery;
    131134})(jQuery);
Note: See TracChangeset for help on using the changeset viewer.