Add l10n thousands delimiter and decimal point to JS, fix updating of comments numbers on the dashboard and keyboard shortcuts for comments moderation (t = trash, z = restore/undo)

git-svn-id: http://svn.automattic.com/wordpress/trunk@12015 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
azaozz 2009-10-09 09:02:22 +00:00
parent 41099f6e33
commit 4b53a32f07
6 changed files with 118 additions and 92 deletions

View File

@ -41,7 +41,7 @@ $admin_body_class = preg_replace('/[^a-z0-9_-]+/i', '-', $hook_suffix);
//<![CDATA[
addLoadEvent = function(func){if(typeof jQuery!="undefined")jQuery(document).ready(func);else if(typeof wpOnload!='function'){wpOnload=func;}else{var oldonload=wpOnload;wpOnload=function(){oldonload();func();}}};
var userSettings = {'url':'<?php echo SITECOOKIEPATH; ?>','uid':'<?php if ( ! isset($current_user) ) $current_user = wp_get_current_user(); echo $current_user->ID; ?>','time':'<?php echo time() ?>'};
var ajaxurl = '<?php echo admin_url('admin-ajax.php'); ?>', pagenow = '<?php echo substr($pagenow, 0, -4); ?>', adminpage = '<?php echo $admin_body_class; ?>';
var ajaxurl = '<?php echo admin_url('admin-ajax.php'); ?>', pagenow = '<?php echo substr($pagenow, 0, -4); ?>', adminpage = '<?php echo $admin_body_class; ?>', thousandsSeparator = '<?php echo $wp_locale->number_format['thousands_sep']; ?>', decimalPoint = '<?php echo $wp_locale->number_format['decimal_point']; ?>';
//]]>
</script>
<?php

View File

@ -236,7 +236,7 @@ function wp_dashboard_right_now() {
*/
// Total Comments
$num = number_format_i18n($num_comm->total_comments);
$num = '<span class="total-count">' . number_format_i18n($num_comm->total_comments) . '</span>';
$text = _n( 'Comment', 'Comments', $num_comm->total_comments );
if ( current_user_can( 'moderate_comments' ) ) {
$num = "<a href='edit-comments.php'>$num</a>";
@ -258,7 +258,7 @@ function wp_dashboard_right_now() {
echo '<td class="t pages">' . $text . '</td>';
// Approved Comments
$num = number_format_i18n($num_comm->approved);
$num = '<span class="approved-count">' . number_format_i18n($num_comm->approved) . '</span>';
$text = _nc( 'Approved|Right Now', 'Approved', $num_comm->approved );
if ( current_user_can( 'moderate_comments' ) ) {
$num = "<a href='edit-comments.php?comment_status=approved'>$num</a>";
@ -280,10 +280,10 @@ function wp_dashboard_right_now() {
echo '<td class="t cats">' . $text . '</td>';
// Pending Comments
$num = number_format_i18n($num_comm->moderated);
$num = '<span class="pending-count">' . number_format_i18n($num_comm->moderated) . '</span>';
$text = _n( 'Pending', 'Pending', $num_comm->moderated );
if ( current_user_can( 'moderate_comments' ) ) {
$num = "<a href='edit-comments.php?comment_status=moderated'><span class='pending-count'>$num</span></a>";
$num = "<a href='edit-comments.php?comment_status=moderated'>$num</a>";
$text = "<a class='waiting' href='edit-comments.php?comment_status=moderated'>$text</a>";
}
echo '<td class="b b-waiting">' . $num . '</td>';

View File

@ -2158,7 +2158,7 @@ function _wp_comment_row( $comment_id, $mode, $comment_status, $checkbox = true,
if ( $user_can ) {
if ( 'trash' == $the_comment_status ) {
$actions['untrash'] = "<a href='$untrash_url' class='delete:the-comment-list:comment-$comment->comment_ID:ABF888:untrash=1 vim-t vim-destructive''>" . __( 'Restore' ) . '</a>';
$actions['untrash'] = "<a href='$untrash_url' class='delete:the-comment-list:comment-$comment->comment_ID:ABF888:untrash=1 vim-z vim-destructive'>" . __( 'Restore' ) . '</a>';
$actions['delete'] = "<a href='$delete_url' class='delete:the-comment-list:comment-$comment->comment_ID::delete=1 delete vim-d vim-destructive'>" . __('Delete Permanently') . '</a>';
} else {
$actions['approve'] = "<a href='$approve_url' class='dim:the-comment-list:comment-$comment->comment_ID:unapproved:e7e7d3:e7e7d3:new=approved vim-a' title='" . __( 'Approve this comment' ) . "'>" . __( 'Approve' ) . '</a>';

View File

@ -17,23 +17,22 @@ setCommentsList = function() {
c.find('div.comment_status').html('1')
$('span.pending-count').each( function() {
var a = $(this), n;
n = a.html().replace(/[ ,.]+/g, '');
var a = $(this), n, dif;
n = a.html().replace(/[^0-9]+/g, '');
n = parseInt(n,10);
if ( isNaN(n) ) return;
n = n + ( $('#' + settings.element).is('.' + settings.dimClass) ? 1 : -1 );
dif = $('#' + settings.element).is('.' + settings.dimClass) ? 1 : -1;
n = n + dif;
if ( n < 0 ) { n = 0; }
a.closest('#awaiting-mod')[ 0 == n ? 'addClass' : 'removeClass' ]('count-0');
n = n.toString();
if ( n.length > 3 )
n = n.substr(0, n.length-3)+' '+n.substr(-3);
a.html(n);
updateCount(a, n);
dashboardTotals();
});
};
// Send current total, page, per_page and url
delBefore = function( settings, list ) {
var cl = $(settings.target).attr('className'), id, el, n, h, a, author;
var cl = $(settings.target).attr('className'), id, el, n, h, a, to, author;
settings.data._total = totalInput.val() || 0;
settings.data._per_page = perPageInput.val() || 0;
@ -60,7 +59,7 @@ setCommentsList = function() {
$('strong', '#trashundo-' + id).html(author);
a = $('a.undo-trash', '#trashundo-' + id);
a.attr('href', 'comment.php?action=untrashcomment&c=' + id + '&_ajax_nonce=' + settings.data._ajax_nonce);
a.attr('className', 'delete:the-comment-list:comment-' + id + '::untrash=1 vim-t vim-destructive');
a.attr('className', 'delete:the-comment-list:comment-' + id + '::untrash=1 vim-z vim-destructive');
a.click(function(){
list.wpList.del(this);
@ -71,7 +70,7 @@ setCommentsList = function() {
return false;
});
window.setTimeout( function(){
to = window.setTimeout( function(){
$('#trashundo-' + id).fadeOut('slow', function(){ $(this).remove(); });
}, 200000 );
}
@ -81,31 +80,75 @@ setCommentsList = function() {
// Updates the current total (as displayed visibly)
updateTotalCount = function( total, time, setConfidentTime ) {
if ( time < lastConfidentTime ) {
if ( time < lastConfidentTime )
return;
}
totalInput.val( total.toString() );
if ( setConfidentTime ) {
if ( setConfidentTime )
lastConfidentTime = time;
}
totalInput.val( total.toString() );
$('span.total-type-count').each( function() {
var a = $(this), n;
n = totalInput.val().toString();
if ( n.length > 3 )
n = n.substr(0, n.length-3)+' '+n.substr(-3);
a.html(n);
updateCount( $(this), total );
});
};
function dashboardTotals(n) {
var dash = $('#dashboard_right_now'), total, appr, totalN, apprN;
n = n || 0;
if ( isNaN(n) || !dash.length )
return;
total = $('span.total-count', dash);
appr = $('span.approved-count', dash);
totalN = getCount(total);
apprN = getCount(appr);
if ( totalN ) {
totalN = totalN + n;
apprN = totalN - getCount( $('span.pending-count', dash) );
updateCount(total, totalN);
updateCount(appr, apprN);
}
}
function getCount(el) {
var n = parseInt( el.html().replace(/[^0-9]+/g, ''), 10 );
if ( isNaN(n) )
return 0;
return n;
}
function updateCount(el, n) {
if ( isNaN(n) )
return;
n = n < 1 ? '0' : n.toString();
if ( n.length > 3 )
n = n.substr(0, n.length-3) + thousandsSeparator + n.substr(-3);
el.html(n);
}
// In admin-ajax.php, we send back the unix time stamp instead of 1 on success
delAfter = function( r, settings ) {
var total, pageLinks, untrash = $(settings.target).parent().is('span.untrash');
var total, pageLinks, N, untrash = $(settings.target).parent().is('span.untrash'), spam, trash;
function getUpdate(s) {
if ( $(settings.target).parent().is('span.' + s) )
return 1;
else if ( $('#' + settings.element).is('.' + s) )
return -1;
return 0;
}
spam = getUpdate('spam');
trash = getUpdate('trash');
if ( untrash )
trash = -1;
$('span.pending-count').each( function() {
var a = $(this), n, unapproved = $('#' + settings.element).is('.unapproved');
n = a.html().replace(/[ ,.]+/g, '');
n = parseInt(n,10);
if ( isNaN(n) ) return;
var a = $(this), n = getCount(a), unapproved = $('#' + settings.element).is('.unapproved');
if ( $(settings.target).parent().is('span.unapprove') || ( untrash && unapproved ) ) { // we "deleted" an approved comment from the approved list by clicking "Unapprove"
n = n + 1;
} else if ( unapproved ) { // we deleted a formerly unapproved comment
@ -113,65 +156,41 @@ setCommentsList = function() {
}
if ( n < 0 ) { n = 0; }
a.closest('#awaiting-mod')[ 0 == n ? 'addClass' : 'removeClass' ]('count-0');
n = n.toString();
if ( n.length > 3 )
n = n.substr(0, n.length-3)+' '+n.substr(-3);
a.html(n);
updateCount(a, n);
dashboardTotals();
});
$('span.spam-count').each( function() {
var a = $(this), n;
n = a.html().replace(/[ ,.]+/g, '');
n = parseInt(n,10);
if ( isNaN(n) ) return;
if ( $(settings.target).parent().is( 'span.spam' ) ) { // we marked a comment as spam
n = n + 1;
} else if ( $('#' + settings.element).is('.spam') ) { // we approved, deleted, or destroyed a comment marked as spam
n = n - 1;
}
if ( n < 0 ) { n = 0; }
n = n.toString();
if ( n.length > 3 )
n = n.substr(0, n.length-3)+' '+n.substr(-3);
a.html(n);
var a = $(this), n = getCount(a) + spam;
updateCount(a, n);
});
$('span.trash-count').each( function() {
var a = $(this), n;
n = a.html().replace(/[ ,.]+/g, '');
n = parseInt(n,10);
if ( isNaN(n) ) return;
if ( $(settings.target).parent().is( 'span.trash' ) ) { // we trashed a comment
n = n + 1;
} else if ( $('#' + settings.element).is('.trash') || untrash ) { // we deleted or untrashed a trash comment
n = n - 1;
}
if ( n < 0 ) { n = 0; }
n = n.toString();
if ( n.length > 3 )
n = n.substr(0, n.length-3)+' '+n.substr(-3);
a.html(n);
var a = $(this), n = getCount(a) + trash;
updateCount(a, n);
});
// XML response
if ( ( 'object' == typeof r ) && lastConfidentTime < settings.parsed.responses[0].supplemental.time ) {
// Set the total to the known good value (even if this value is a little old, newer values should only be a few less, and so shouldn't mess up the page links)
total = settings.parsed.responses[0].supplemental.total || false;
pageLinks = settings.parsed.responses[0].supplemental.pageLinks || false;
if ( total && pageLinks ) {
updateTotalCount( total, settings.parsed.responses[0].supplemental.time, true );
if ( $.trim( pageLinks ) ) {
$('.tablenav-pages').find( '.page-numbers' ).remove().end().append( $( pageLinks ) );
} else {
$('.tablenav-pages').find( '.page-numbers' ).remove();
}
}
if ( $('#dashboard_right_now').length ) {
N = spam || trash || 0;
if ( N > 0 )
dashboardTotals(-1);
else if ( N < 0 )
dashboardTotals(1);
} else {
// Decrement the total
// XML response
if ( ( 'object' == typeof r ) && lastConfidentTime < settings.parsed.responses[0].supplemental.time ) {
pageLinks = settings.parsed.responses[0].supplemental.pageLinks || '';
if ( $.trim( pageLinks ) )
$('.tablenav-pages').find( '.page-numbers' ).remove().end().append( $( pageLinks ) );
else
$('.tablenav-pages').find( '.page-numbers' ).remove();
}
total = totalInput.val() ? parseInt( totalInput.val(), 10 ) : 0;
if ( total-- < 0 )
total = total - spam - trash;
if ( total < 0 )
total = 0;
updateTotalCount( total, r, false );
}
@ -420,26 +439,33 @@ $(document).ready(function(){
window.location = l[0].href.replace(/\&hotkeys_highlight_(first|last)=1/g, '')+'&hotkeys_highlight_'+first_last+'=1';
}
};
edit_comment = function(event, current_row) {
window.location = $('span.edit a', current_row).attr('href');
};
toggle_all = function() {
toggleWithKeyboard = true;
$('#comments-form thead #cb input:checkbox').click().attr('checked', '');
$('input:checkbox', '#cb').click().attr('checked', '');
toggleWithKeyboard = false;
}
};
make_bulk = function(value) {
return function(event, _) {
$('option[value='+value+']').attr('selected', 'selected');
$('form#comments-form')[0].submit();
return function() {
var scope = $('select[name="action"]');
$('option[value='+value+']', scope).attr('selected', 'selected');
$('#comments-form').submit();
}
};
$.table_hotkeys($('table.widefat'),['a', 'u', 's', 'd', 'r', 'q', ['e', edit_comment],
['shift+a', make_bulk('approve')], ['shift+s', make_bulk('markspam')],
['shift+d', make_bulk('delete')], ['shift+x', toggle_all],
['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')}
$.table_hotkeys(
$('table.widefat'),
['a', 'u', 's', 'd', 'r', 'q', 't', 'z', ['e', edit_comment], ['shift+x', toggle_all],
['shift+a', make_bulk('approve')], ['shift+s', make_bulk('markspam')],
['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') }
);
}
});

File diff suppressed because one or more lines are too long

View File

@ -256,7 +256,7 @@ function wp_default_scripts( &$scripts ) {
$scripts->add( 'user-profile', "/wp-admin/js/user-profile$suffix.js", array('jquery'), '20090514' );
$scripts->add_data( 'user-profile', 'group', 1 );
$scripts->add( 'admin-comments', "/wp-admin/js/edit-comments$suffix.js", array('wp-lists', 'jquery-ui-resizable', 'quicktags'), '20091007' );
$scripts->add( 'admin-comments', "/wp-admin/js/edit-comments$suffix.js", array('wp-lists', 'jquery-ui-resizable', 'quicktags'), '20091008' );
$scripts->add_data( 'admin-comments', 'group', 1 );
$scripts->localize( 'admin-comments', 'adminCommentsL10n', array(
'hotkeys_highlight_first' => isset($_GET['hotkeys_highlight_first']),