Changeset 8789
- Timestamp:
- 09/01/2008 05:28:41 AM (18 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
-
wp-admin/js/edit-comments.js (modified) (1 diff)
-
wp-includes/js/jquery/jquery.table-hotkeys.js (modified) (5 diffs)
-
wp-includes/script-loader.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/js/edit-comments.js
r8780 r8789 236 236 if ( typeof QTags != 'undefined' ) 237 237 ed_reply = new QTags('ed_reply', 'replycontent', 'replycontainer', 'more'); 238 if ( typeof $.table_hotkeys != 'undefined' ) 239 $.table_hotkeys($('table.widefat'), ['a', 'u', 's', 'd', 'r']); 238 if ( typeof $.table_hotkeys != 'undefined' ) { 239 var make_hotkeys_redirect = function(which) { 240 return function() { 241 var first_last = 'next' == which? 'first' : 'last'; 242 var l=$('.'+which+'.page-numbers'); 243 if (l.length) 244 window.location = l[0].href.replace(/\&hotkeys_highlight_(first|last)=1/g, '')+'&hotkeys_highlight_'+first_last+'=1'; 245 } 246 } 247 $.table_hotkeys($('table.widefat'), ['a', 'u', 's', 'd', 'r'], 248 { highlight_first: adminCommentsL10n.hotkeys_highlight_first, 249 highlight_last: adminCommentsL10n.hotkeys_highlight_last, 250 prev_page_link_cb: make_hotkeys_redirect('prev'), 251 next_page_link_cb: make_hotkeys_redirect('next'), 252 } 253 ); 254 } 240 255 }); 241 256 -
trunk/wp-includes/js/jquery/jquery.table-hotkeys.js
r8779 r8789 1 1 (function($){ 2 $.fn.filter_visible = function(depth) { 3 depth = depth || 3; 4 var is_visible = function() { 5 var p = $(this); 6 for(i=0; i<depth-1; ++i) { 7 if (!p.is(':visible')) return false; 8 p = p.parent(); 9 } 10 return true; 11 } 12 return this.filter(is_visible); 13 }; 2 14 $.table_hotkeys = function(table, keys, opts) { 3 15 opts = $.extend($.table_hotkeys.defaults, opts); 4 16 var selected_class = opts.class_prefix + opts.selected_suffix; 5 var destructive_class = opts.class_prefix + opts.destructive_suffix; 17 var destructive_class = opts.class_prefix + opts.destructive_suffix; 6 18 var set_current_row = function (tr) { 7 19 if ($.table_hotkeys.current_row) $.table_hotkeys.current_row.removeClass(selected_class); … … 10 22 $.table_hotkeys.current_row = tr; 11 23 }; 12 var next_row = function() { 13 var next = get_adjacent_row('next'); 14 if (!next) return false; 15 set_current_row($(next)); 24 var adjacent_row_callback = function(which) { 25 if (!adjacent_row(which) && $.isFunction(opts[which+'_page_link_cb'])) { 26 opts[which+'_page_link_cb'](); 27 } 28 }; 29 var get_adjacent_row = function(which) { 30 if (!$.table_hotkeys.current_row) { 31 var first_row = get_first_row(); 32 $.table_hotkeys.current_row = first_row; 33 return first_row[0]; 34 } 35 var method = 'prev' == which? $.fn.prevAll : $.fn.nextAll; 36 return method.call($.table_hotkeys.current_row, opts.cycle_expr).filter_visible()[0]; 37 }; 38 var adjacent_row = function(which) { 39 var adj = get_adjacent_row(which); 40 if (!adj) return false; 41 set_current_row($(adj)); 16 42 return true; 17 43 }; 18 var prev_row = function() { 19 var prev = get_adjacent_row('prev'); 20 if (!prev) return false; 21 set_current_row($(prev)); 22 return true; 23 }; 44 var prev_row = function() { return adjacent_row('prev'); }; 45 var next_row = function() { return adjacent_row('next'); }; 24 46 var check = function() { 25 47 $(opts.checkbox_expr, $.table_hotkeys.current_row).each(function() { … … 27 49 }); 28 50 }; 29 var get_adjacent_row = function(which) { 30 if (!$.table_hotkeys.current_row) { 31 var start_row_dom = $(opts.cycle_expr, table)[opts.start_row_index]; 32 $.table_hotkeys.current_row = $(start_row_dom); 33 return start_row_dom; 34 } 35 var method = 'prev' == which? $.fn.prevAll : $.fn.nextAll; 36 return method.call($.table_hotkeys.current_row, opts.cycle_expr).filter(':visible')[0]; 37 } 51 var get_first_row = function() { 52 return $(opts.cycle_expr, table).filter_visible().eq(opts.start_row_index); 53 }; 54 var get_last_row = function() { 55 var rows = $(opts.cycle_expr, table).filter_visible(); 56 console.log(rows[rows.length-1]); 57 return rows.eq(rows.length-1); 58 }; 38 59 var make_key_callback = function(expr) { 39 60 return function() { 40 61 if ( null == $.table_hotkeys.current_row ) return false; 41 var clickable = $(expr, $.table_hotkeys.current_row).filter (':visible');42 if (! $($(clickable[0]).parent()[0]).is(':visible')) return false;62 var clickable = $(expr, $.table_hotkeys.current_row).filter_visible(); 63 if (!clickable.length) return false; 43 64 if (clickable.is('.'+destructive_class)) next_row() || prev_row(); 44 65 clickable.click(); … … 60 81 return {key: key, expr: expr}; 61 82 }; 62 if (!$(opts.cycle_expr, table).length) return; 63 jQuery.hotkeys.add(opts.next_key, opts.hotkeys_opts, next_row); 64 jQuery.hotkeys.add(opts.prev_key, opts.hotkeys_opts, prev_row); 83 var first_row = get_first_row(); 84 if (!first_row.length) return; 85 if (opts.highlight_first) { 86 set_current_row(first_row); 87 } else if (opts.highlight_last) { 88 set_current_row(get_last_row()); 89 }; 90 jQuery.hotkeys.add(opts.prev_key, opts.hotkeys_opts, function() {return adjacent_row_callback('prev')}); 91 jQuery.hotkeys.add(opts.next_key, opts.hotkeys_opts, function() {return adjacent_row_callback('next')}); 65 92 jQuery.hotkeys.add(opts.mark_key, opts.hotkeys_opts, check); 66 93 jQuery.each(keys, function() { … … 74 101 destructive_suffix: 'destructive', hotkeys_opts: {disableInInput: true, type: 'keypress'}, 75 102 checkbox_expr: ':checkbox', next_key: 'j', prev_key: 'k', mark_key: 'x', 76 start_row_index: 1 };103 start_row_index: 1, highlight_first: false, highlight_last: false, next_page_link_cb: function() {}, prev_page_link_cb: function() {}}; 77 104 })(jQuery); -
trunk/wp-includes/script-loader.php
r8784 r8789 161 161 $scripts->add( 'admin-comments', '/wp-admin/js/edit-comments.js', array('wp-lists', 'jquery-ui-draggable', 'jquery-ui-resizable', 'quicktags'), '20080828' ); 162 162 $scripts->localize( 'admin-comments', 'adminCommentsL10n', array( 163 'pending' => __('%i% pending') // must look like: "# blah blah" 163 'pending' => __('%i% pending'), // must look like: "# blah blah" 164 'hotkeys_highlight_first' => isset($_GET['hotkeys_highlight_first']), 165 'hotkeys_highlight_last' => isset($_GET['hotkeys_highlight_last']), 164 166 ) ); 165 167 $scripts->add( 'admin-users', '/wp-admin/js/users.js', array('wp-lists'), '20070823' );
Note: See TracChangeset
for help on using the changeset viewer.