Bulk action hot keys for comments. Props nbachiyski. see #7643

git-svn-id: http://svn.automattic.com/wordpress/trunk@8804 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2008-09-04 17:53:14 +00:00
parent 0933020641
commit 390172ba94
3 changed files with 31 additions and 28 deletions

View File

@ -243,13 +243,26 @@ $(document).ready(function(){
if (l.length)
window.location = l[0].href.replace(/\&hotkeys_highlight_(first|last)=1/g, '')+'&hotkeys_highlight_'+first_last+'=1';
}
};
var edit_comment = function(event, current_row) {
window.location = $('span.edit a', current_row).attr('href');
};
var toggle_all = function() {
var master_checkbox = $('form#comments-form .check-column :checkbox:first');
master_checkbox.attr('checked', master_checkbox.attr('checked')? '' : 'checked');
checkAll('form#comments-form');
}
$.table_hotkeys($('table.widefat'), ['a', 'u', 's', 'd', 'r'],
{ 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'),
var make_bulk = function(value) {
return function(event, _) {
$('option[value='+value+']').attr('selected', 'selected');
$('form#comments-form')[0].submit();
}
};
$.table_hotkeys($('table.widefat'),['a', 'u', 's', 'd', 'r', ['e', edit_comment],
['shift+a', make_bulk('approve')], ['shift+s', make_bulk('markspam')],
['shift+d', make_bulk('delete')], ['shift+x', toggle_all]],
{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')}
);
}
});

View File

@ -23,4 +23,4 @@ jQuery( function($) {
$( 'thead :checkbox' ).click( function() {
checkAll( $(this).parents( 'form:first' ) );
} );
} );
} );

View File

@ -64,34 +64,24 @@
clickable.click();
}
};
var make_key_expr = function(elem) {
if (typeof elem.key == 'string') {
key = elem.key;
if (typeof elem.expr == 'string')
expr = elem.expr;
else if (typeof elem.suffix == 'string')
expr = '.'+opts.class_prefix+elem.suffix;
else
expr = '.'+opts.class_prefix+elem.key;
} else {
key = elem;
expr = '.'+opts.class_prefix+elem;
}
return {key: key, expr: expr};
};
var first_row = get_first_row();
if (!first_row.length) return;
if (opts.highlight_first) {
if (!first_row.length) return;
if (opts.highlight_first)
set_current_row(first_row);
} else if (opts.highlight_last) {
else if (opts.highlight_last)
set_current_row(get_last_row());
};
jQuery.hotkeys.add(opts.prev_key, opts.hotkeys_opts, function() {return adjacent_row_callback('prev')});
jQuery.hotkeys.add(opts.next_key, opts.hotkeys_opts, function() {return adjacent_row_callback('next')});
jQuery.hotkeys.add(opts.mark_key, opts.hotkeys_opts, check);
jQuery.each(keys, function() {
var key_expr = make_key_expr(this);
jQuery.hotkeys.add(key_expr.key, opts.hotkeys_opts, make_key_callback(key_expr.expr));
if ($.isFunction(this[1])) {
var callback = this[1];
var key = this[0];
jQuery.hotkeys.add(key, opts.hotkeys_opts, function(event) { return callback(event, $.table_hotkeys.current_row); });
} else {
var key = this;
jQuery.hotkeys.add(key, opts.hotkeys_opts, make_key_callback('.'+opts.class_prefix+key));
}
});
};
@ -99,5 +89,5 @@
$.table_hotkeys.defaults = {cycle_expr: 'tr', class_prefix: 'vim-', selected_suffix: 'current',
destructive_suffix: 'destructive', hotkeys_opts: {disableInInput: true, type: 'keypress'},
checkbox_expr: ':checkbox', next_key: 'j', prev_key: 'k', mark_key: 'x',
start_row_index: 1, highlight_first: false, highlight_last: false, next_page_link_cb: function() {}, prev_page_link_cb: function() {}};
start_row_index: 1, highlight_first: false, highlight_last: false, next_page_link_cb: false, prev_page_link_cb: false};
})(jQuery);