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.
Built from https://develop.svn.wordpress.org/trunk@26889


git-svn-id: http://core.svn.wordpress.org/trunk@26772 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Andrew Ozz 2014-01-02 00:11:14 +00:00
parent 8a82e4c463
commit 2a68f85fa1
5 changed files with 93 additions and 70 deletions

View File

@ -1,4 +1,4 @@
/* global setUserSetting, ajaxurl, commonL10n, alert, confirm, toggleWithKeyboard, pagenow */ /* global setUserSetting, ajaxurl, commonL10n, alert, confirm, pagenow */
var showNotice, adminMenu, columns, validateForm, screenMeta; var showNotice, adminMenu, columns, validateForm, screenMeta;
( function( $, window, undefined ) { ( function( $, window, undefined ) {
// Removed in 3.3. // Removed in 3.3.
@ -346,32 +346,39 @@ $(document).ready( function() {
return true; return true;
}); });
$('thead, tfoot').find('.check-column :checkbox').click( function(e) { $('thead, tfoot').find('.check-column :checkbox').on( 'click.wp-toggle-checkboxes', function( event ) {
var c = $(this).prop('checked'), var $this = $(this),
kbtoggle = 'undefined' == typeof toggleWithKeyboard ? false : toggleWithKeyboard, $table = $this.closest( 'table' ),
toggle = e.shiftKey || kbtoggle; controlChecked = $this.prop('checked'),
toggle = event.shiftKey || $this.data('wp-toggle');
$(this).closest( 'table' ).children( 'tbody' ).filter(':visible') $table.children( 'tbody' ).filter(':visible')
.children().children('.check-column').find(':checkbox') .children().children('.check-column').find(':checkbox')
.prop('checked', function() { .prop('checked', function() {
if ( $(this).is(':hidden') ) if ( $(this).is(':hidden') ) {
return false; return false;
if ( toggle ) }
return $(this).prop( 'checked' );
else if (c) if ( toggle ) {
return true; return ! $(this).prop( 'checked' );
return false; } else if ( controlChecked ) {
}); return true;
}
$(this).closest('table').children('thead, tfoot').filter(':visible')
.children().children('.check-column').find(':checkbox')
.prop('checked', function() {
if ( toggle )
return false; return false;
else if (c) });
return true;
return false; $table.children('thead, tfoot').filter(':visible')
}); .children().children('.check-column').find(':checkbox')
.prop('checked', function() {
if ( toggle ) {
return false;
} else if ( controlChecked ) {
return true;
}
return false;
});
}); });
// Show row actions on keyboard focus of its parent container element or any other elements contained within // Show row actions on keyboard focus of its parent container element or any other elements contained within

File diff suppressed because one or more lines are too long

View File

@ -1,6 +1,5 @@
/* global adminCommentsL10n, thousandsSeparator, list_args, QTags, ajaxurl, wpAjax */ /* global adminCommentsL10n, thousandsSeparator, list_args, QTags, ajaxurl, wpAjax */
var setCommentsList, theList, theExtraList, commentReply, var setCommentsList, theList, theExtraList, commentReply;
toggleWithKeyboard = false;
(function($) { (function($) {
var getCount, updateCount, updatePending, dashboardTotals; var getCount, updateCount, updatePending, dashboardTotals;
@ -594,9 +593,7 @@ $(document).ready(function(){
}; };
toggle_all = function() { toggle_all = function() {
toggleWithKeyboard = true; $('#cb-select-all-1').data( 'wp-toggle', 1 ).trigger( 'click' ).removeData( 'wp-toggle' );
$('input:checkbox', '#cb').click().prop('checked', false);
toggleWithKeyboard = false;
}; };
make_bulk = function(value) { make_bulk = function(value) {
@ -609,12 +606,28 @@ $(document).ready(function(){
$.table_hotkeys( $.table_hotkeys(
$('table.widefat'), $('table.widefat'),
['a', 'u', 's', 'd', 'r', 'q', 'z', ['e', edit_comment], ['shift+x', toggle_all], [
['shift+a', make_bulk('approve')], ['shift+s', make_bulk('spam')], 'a', 'u', 's', 'd', 'r', 'q', 'z',
['shift+d', make_bulk('delete')], ['shift+t', make_bulk('trash')], ['e', edit_comment],
['shift+z', make_bulk('untrash')], ['shift+u', make_bulk('unapprove')]], ['shift+x', toggle_all],
{ highlight_first: adminCommentsL10n.hotkeys_highlight_first, highlight_last: adminCommentsL10n.hotkeys_highlight_last, ['shift+a', make_bulk('approve')],
prev_page_link_cb: make_hotkeys_redirect('prev'), next_page_link_cb: make_hotkeys_redirect('next') } ['shift+s', make_bulk('spam')],
['shift+d', make_bulk('delete')],
['shift+t', make_bulk('trash')],
['shift+z', make_bulk('untrash')],
['shift+u', make_bulk('unapprove')]
],
{
highlight_first: adminCommentsL10n.hotkeys_highlight_first,
highlight_last: adminCommentsL10n.hotkeys_highlight_last,
prev_page_link_cb: make_hotkeys_redirect('prev'),
next_page_link_cb: make_hotkeys_redirect('next'),
hotkeys_opts: {
disableInInput: true,
type: 'keypress',
noDisable: '.check-column input[type="checkbox"]'
}
}
); );
} }
}); });

File diff suppressed because one or more lines are too long

View File

@ -1,19 +1,19 @@
/****************************************************************************************************************************** /******************************************************************************************************************************
* @ Original idea by by Binny V A, Original version: 2.00.A * @ Original idea by by Binny V A, Original version: 2.00.A
* @ http://www.openjs.com/scripts/events/keyboard_shortcuts/ * @ http://www.openjs.com/scripts/events/keyboard_shortcuts/
* @ Original License : BSD * @ Original License : BSD
* @ jQuery Plugin by Tzury Bar Yochay * @ jQuery Plugin by Tzury Bar Yochay
mail: tzury.by@gmail.com mail: tzury.by@gmail.com
blog: evalinux.wordpress.com blog: evalinux.wordpress.com
face: facebook.com/profile.php?id=513676303 face: facebook.com/profile.php?id=513676303
(c) Copyrights 2007 (c) Copyrights 2007
* @ jQuery Plugin version Beta (0.0.2) * @ jQuery Plugin version Beta (0.0.2)
* @ License: jQuery-License. * @ License: jQuery-License.
TODO: TODO:
add queue support (as in gmail) e.g. 'x' then 'y', etc. add queue support (as in gmail) e.g. 'x' then 'y', etc.
add mouse + mouse wheel events. add mouse + mouse wheel events.
@ -21,23 +21,23 @@ TODO:
USAGE: USAGE:
$.hotkeys.add('Ctrl+c', function(){ alert('copy anyone?');}); $.hotkeys.add('Ctrl+c', function(){ alert('copy anyone?');});
$.hotkeys.add('Ctrl+c', {target:'div#editor', type:'keyup', propagate: true},function(){ alert('copy anyone?');});> $.hotkeys.add('Ctrl+c', {target:'div#editor', type:'keyup', propagate: true},function(){ alert('copy anyone?');});>
$.hotkeys.remove('Ctrl+c'); $.hotkeys.remove('Ctrl+c');
$.hotkeys.remove('Ctrl+c', {target:'div#editor', type:'keypress'}); $.hotkeys.remove('Ctrl+c', {target:'div#editor', type:'keypress'});
******************************************************************************************************************************/ ******************************************************************************************************************************/
(function (jQuery){ (function (jQuery){
this.version = '(beta)(0.0.3)'; this.version = '(beta)(0.0.3)';
this.all = {}; this.all = {};
this.special_keys = { this.special_keys = {
27: 'esc', 9: 'tab', 32:'space', 13: 'return', 8:'backspace', 145: 'scroll', 20: 'capslock', 27: 'esc', 9: 'tab', 32:'space', 13: 'return', 8:'backspace', 145: 'scroll', 20: 'capslock',
144: 'numlock', 19:'pause', 45:'insert', 36:'home', 46:'del',35:'end', 33: 'pageup', 144: 'numlock', 19:'pause', 45:'insert', 36:'home', 46:'del',35:'end', 33: 'pageup',
34:'pagedown', 37:'left', 38:'up', 39:'right',40:'down', 112:'f1',113:'f2', 114:'f3', 34:'pagedown', 37:'left', 38:'up', 39:'right',40:'down', 112:'f1',113:'f2', 114:'f3',
115:'f4', 116:'f5', 117:'f6', 118:'f7', 119:'f8', 120:'f9', 121:'f10', 122:'f11', 123:'f12'}; 115:'f4', 116:'f5', 117:'f6', 118:'f7', 119:'f8', 120:'f9', 121:'f10', 122:'f11', 123:'f12'};
this.shift_nums = { "`":"~", "1":"!", "2":"@", "3":"#", "4":"$", "5":"%", "6":"^", "7":"&", this.shift_nums = { "`":"~", "1":"!", "2":"@", "3":"#", "4":"$", "5":"%", "6":"^", "7":"&",
"8":"*", "9":"(", "0":")", "-":"_", "=":"+", ";":":", "'":"\"", ",":"<", "8":"*", "9":"(", "0":")", "-":"_", "=":"+", ";":":", "'":"\"", ",":"<",
".":">", "/":"?", "\\":"|" }; ".":">", "/":"?", "\\":"|" };
this.add = function(combi, options, callback) { this.add = function(combi, options, callback) {
if (jQuery.isFunction(options)){ if (jQuery.isFunction(options)){
callback = options; callback = options;
@ -47,8 +47,8 @@ USAGE:
defaults = {type: 'keydown', propagate: false, disableInInput: false, target: jQuery('html')[0]}, defaults = {type: 'keydown', propagate: false, disableInInput: false, target: jQuery('html')[0]},
that = this; that = this;
opt = jQuery.extend( opt , defaults, options || {} ); opt = jQuery.extend( opt , defaults, options || {} );
combi = combi.toLowerCase(); combi = combi.toLowerCase();
// inspect if keystroke matches // inspect if keystroke matches
var inspector = function(event) { var inspector = function(event) {
// WP: not needed with newer jQuery // WP: not needed with newer jQuery
@ -57,11 +57,14 @@ USAGE:
// @ TextNode -> nodeType == 3 // @ TextNode -> nodeType == 3
// WP: not needed with newer jQuery // WP: not needed with newer jQuery
// element = (element.nodeType==3) ? element.parentNode : element; // element = (element.nodeType==3) ? element.parentNode : element;
if(opt['disableInInput']) { // Disable shortcut keys in Input, Textarea fields if ( opt['disableInInput'] ) { // Disable shortcut keys in Input, Textarea fields
var target = jQuery(element); var target = jQuery(element);
if( target.is("input") || target.is("textarea")){
return; if ( ( target.is('input') || target.is('textarea') ) &&
( ! opt.noDisable || ! target.is( opt.noDisable ) ) ) {
return;
} }
} }
var code = event.which, var code = event.which,
@ -74,11 +77,11 @@ USAGE:
meta = event.metaKey, meta = event.metaKey,
propagate = true, // default behaivour propagate = true, // default behaivour
mapPoint = null; mapPoint = null;
// in opera + safari, the event.target is unpredictable. // in opera + safari, the event.target is unpredictable.
// for example: 'keydown' might be associated with HtmlBodyElement // for example: 'keydown' might be associated with HtmlBodyElement
// or the element where you last clicked with your mouse. // or the element where you last clicked with your mouse.
// WP: needed for all browsers // WP: needed for all browsers
// if (jQuery.browser.opera || jQuery.browser.safari){ // if (jQuery.browser.opera || jQuery.browser.safari){
while (!that.all[element] && element.parentNode){ while (!that.all[element] && element.parentNode){
element = element.parentNode; element = element.parentNode;
@ -106,7 +109,7 @@ USAGE:
return false; return false;
} }
} }
}; };
// first hook for this element // first hook for this element
if (!this.all[opt.target]){ if (!this.all[opt.target]){
this.all[opt.target] = {events:{}}; this.all[opt.target] = {events:{}};
@ -114,18 +117,18 @@ USAGE:
if (!this.all[opt.target].events[opt.type]){ if (!this.all[opt.target].events[opt.type]){
this.all[opt.target].events[opt.type] = {callbackMap: {}} this.all[opt.target].events[opt.type] = {callbackMap: {}}
jQuery.event.add(opt.target, opt.type, inspector); jQuery.event.add(opt.target, opt.type, inspector);
} }
this.all[opt.target].events[opt.type].callbackMap[combi] = {cb: callback, propagate:opt.propagate}; this.all[opt.target].events[opt.type].callbackMap[combi] = {cb: callback, propagate:opt.propagate};
return jQuery; return jQuery;
}; };
this.remove = function(exp, opt) { this.remove = function(exp, opt) {
opt = opt || {}; opt = opt || {};
target = opt.target || jQuery('html')[0]; target = opt.target || jQuery('html')[0];
type = opt.type || 'keydown'; type = opt.type || 'keydown';
exp = exp.toLowerCase(); exp = exp.toLowerCase();
delete this.all[target].events[type].callbackMap[exp] delete this.all[target].events[type].callbackMap[exp]
return jQuery; return jQuery;
}; };
jQuery.hotkeys = this; jQuery.hotkeys = this;
return jQuery; return jQuery;
})(jQuery); })(jQuery);