Comment hotkey: move to next or previous page on pressing next/prev at end of the current page. Prop nbachiyski. see #7643
git-svn-id: http://svn.automattic.com/wordpress/trunk@8789 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
027328b8a6
commit
0e6f150c24
|
@ -235,8 +235,23 @@ commentReply = {
|
|||
$(document).ready(function(){
|
||||
if ( typeof QTags != 'undefined' )
|
||||
ed_reply = new QTags('ed_reply', 'replycontent', 'replycontainer', 'more');
|
||||
if ( typeof $.table_hotkeys != 'undefined' )
|
||||
$.table_hotkeys($('table.widefat'), ['a', 'u', 's', 'd', 'r']);
|
||||
if ( typeof $.table_hotkeys != 'undefined' ) {
|
||||
var make_hotkeys_redirect = function(which) {
|
||||
return function() {
|
||||
var first_last = 'next' == which? 'first' : 'last';
|
||||
var l=$('.'+which+'.page-numbers');
|
||||
if (l.length)
|
||||
window.location = l[0].href.replace(/\&hotkeys_highlight_(first|last)=1/g, '')+'&hotkeys_highlight_'+first_last+'=1';
|
||||
}
|
||||
}
|
||||
$.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'),
|
||||
}
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
})(jQuery);
|
||||
})(jQuery);
|
|
@ -1,45 +1,66 @@
|
|||
(function($){
|
||||
$.fn.filter_visible = function(depth) {
|
||||
depth = depth || 3;
|
||||
var is_visible = function() {
|
||||
var p = $(this);
|
||||
for(i=0; i<depth-1; ++i) {
|
||||
if (!p.is(':visible')) return false;
|
||||
p = p.parent();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return this.filter(is_visible);
|
||||
};
|
||||
$.table_hotkeys = function(table, keys, opts) {
|
||||
opts = $.extend($.table_hotkeys.defaults, opts);
|
||||
var selected_class = opts.class_prefix + opts.selected_suffix;
|
||||
var destructive_class = opts.class_prefix + opts.destructive_suffix;
|
||||
var destructive_class = opts.class_prefix + opts.destructive_suffix;
|
||||
var set_current_row = function (tr) {
|
||||
if ($.table_hotkeys.current_row) $.table_hotkeys.current_row.removeClass(selected_class);
|
||||
tr.addClass(selected_class);
|
||||
tr[0].scrollIntoView(false);
|
||||
$.table_hotkeys.current_row = tr;
|
||||
};
|
||||
var next_row = function() {
|
||||
var next = get_adjacent_row('next');
|
||||
if (!next) return false;
|
||||
set_current_row($(next));
|
||||
return true;
|
||||
};
|
||||
var prev_row = function() {
|
||||
var prev = get_adjacent_row('prev');
|
||||
if (!prev) return false;
|
||||
set_current_row($(prev));
|
||||
var adjacent_row_callback = function(which) {
|
||||
if (!adjacent_row(which) && $.isFunction(opts[which+'_page_link_cb'])) {
|
||||
opts[which+'_page_link_cb']();
|
||||
}
|
||||
};
|
||||
var get_adjacent_row = function(which) {
|
||||
if (!$.table_hotkeys.current_row) {
|
||||
var first_row = get_first_row();
|
||||
$.table_hotkeys.current_row = first_row;
|
||||
return first_row[0];
|
||||
}
|
||||
var method = 'prev' == which? $.fn.prevAll : $.fn.nextAll;
|
||||
return method.call($.table_hotkeys.current_row, opts.cycle_expr).filter_visible()[0];
|
||||
};
|
||||
var adjacent_row = function(which) {
|
||||
var adj = get_adjacent_row(which);
|
||||
if (!adj) return false;
|
||||
set_current_row($(adj));
|
||||
return true;
|
||||
};
|
||||
var prev_row = function() { return adjacent_row('prev'); };
|
||||
var next_row = function() { return adjacent_row('next'); };
|
||||
var check = function() {
|
||||
$(opts.checkbox_expr, $.table_hotkeys.current_row).each(function() {
|
||||
this.checked = !this.checked;
|
||||
});
|
||||
};
|
||||
var get_adjacent_row = function(which) {
|
||||
if (!$.table_hotkeys.current_row) {
|
||||
var start_row_dom = $(opts.cycle_expr, table)[opts.start_row_index];
|
||||
$.table_hotkeys.current_row = $(start_row_dom);
|
||||
return start_row_dom;
|
||||
}
|
||||
var method = 'prev' == which? $.fn.prevAll : $.fn.nextAll;
|
||||
return method.call($.table_hotkeys.current_row, opts.cycle_expr).filter(':visible')[0];
|
||||
}
|
||||
var get_first_row = function() {
|
||||
return $(opts.cycle_expr, table).filter_visible().eq(opts.start_row_index);
|
||||
};
|
||||
var get_last_row = function() {
|
||||
var rows = $(opts.cycle_expr, table).filter_visible();
|
||||
console.log(rows[rows.length-1]);
|
||||
return rows.eq(rows.length-1);
|
||||
};
|
||||
var make_key_callback = function(expr) {
|
||||
return function() {
|
||||
if ( null == $.table_hotkeys.current_row ) return false;
|
||||
var clickable = $(expr, $.table_hotkeys.current_row).filter(':visible');
|
||||
if (!$($(clickable[0]).parent()[0]).is(':visible')) return false;
|
||||
var clickable = $(expr, $.table_hotkeys.current_row).filter_visible();
|
||||
if (!clickable.length) return false;
|
||||
if (clickable.is('.'+destructive_class)) next_row() || prev_row();
|
||||
clickable.click();
|
||||
}
|
||||
|
@ -59,9 +80,15 @@
|
|||
}
|
||||
return {key: key, expr: expr};
|
||||
};
|
||||
if (!$(opts.cycle_expr, table).length) return;
|
||||
jQuery.hotkeys.add(opts.next_key, opts.hotkeys_opts, next_row);
|
||||
jQuery.hotkeys.add(opts.prev_key, opts.hotkeys_opts, prev_row);
|
||||
var first_row = get_first_row();
|
||||
if (!first_row.length) return;
|
||||
if (opts.highlight_first) {
|
||||
set_current_row(first_row);
|
||||
} 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);
|
||||
|
@ -73,5 +100,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};
|
||||
start_row_index: 1, highlight_first: false, highlight_last: false, next_page_link_cb: function() {}, prev_page_link_cb: function() {}};
|
||||
})(jQuery);
|
|
@ -160,7 +160,9 @@ function wp_default_scripts( &$scripts ) {
|
|||
) );
|
||||
$scripts->add( 'admin-comments', '/wp-admin/js/edit-comments.js', array('wp-lists', 'jquery-ui-draggable', 'jquery-ui-resizable', 'quicktags'), '20080828' );
|
||||
$scripts->localize( 'admin-comments', 'adminCommentsL10n', array(
|
||||
'pending' => __('%i% pending') // must look like: "# blah blah"
|
||||
'pending' => __('%i% pending'), // must look like: "# blah blah"
|
||||
'hotkeys_highlight_first' => isset($_GET['hotkeys_highlight_first']),
|
||||
'hotkeys_highlight_last' => isset($_GET['hotkeys_highlight_last']),
|
||||
) );
|
||||
$scripts->add( 'admin-users', '/wp-admin/js/users.js', array('wp-lists'), '20070823' );
|
||||
$scripts->add( 'admin-forms', '/wp-admin/js/forms.js', array('jquery'), '20080729');
|
||||
|
|
Loading…
Reference in New Issue