No-JS mode for replying to comments and some improvements/cleanup of comment-reply.js, includes patch by Viper007Bond, see #7635

git-svn-id: http://svn.automattic.com/wordpress/trunk@9112 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
azaozz 2008-10-09 07:37:05 +00:00
parent f6984aa832
commit 2bd7d9960d
4 changed files with 59 additions and 29 deletions

View File

@ -44,10 +44,10 @@
<div id="respond">
<h3>Leave a Reply</h3>
<h3><?php comment_form_title( 'Leave a Reply', 'Leave a Reply to %s' ); ?></h3>
<div id="cancel-comment-reply" style="display: none;">
<small><?php echo cancel_comment_reply_link() ?></small>
<div class="cancel-comment-reply">
<small><?php cancel_comment_reply_link(); ?></small>
</div>
<?php if ( get_option('comment_registration') && !$user_ID ) : ?>
@ -79,7 +79,7 @@
<p><input name="submit" type="submit" id="submit" tabindex="5" value="Submit Comment" />
<input type="hidden" name="comment_post_ID" value="<?php echo $id; ?>" />
<input type="hidden" name="comment_parent" id="comment-parent" value="0" />
<?php comment_parent_field(); ?>
</p>
<?php do_action('comment_form', $post->ID); ?>

View File

@ -908,9 +908,9 @@ function comment_reply_link($args = array(), $comment = null, $post = null) {
$link = '';
if ( get_option('comment_registration') && !$user_ID )
$link = '<a href="' . site_url('wp-login.php?redirect_to=' . get_permalink()) . '">' . $login_text . '</a>';
$link = '<a rel="nofollow" href="' . site_url('wp-login.php?redirect_to=' . get_permalink()) . '">' . $login_text . '</a>';
else
$link = "<a href='#' onclick='moveAddCommentForm(\"$add_below-$comment->comment_ID\", $comment->comment_ID, \"$respond_id\"); return false;'>$reply_text</a>";
$link = "<a rel='nofollow' href='" . wp_specialchars( add_query_arg( 'replytocom', $comment->comment_ID ) ) . "#respond' onclick='moveAddCommentForm(\"$add_below-$comment->comment_ID\", $comment->comment_ID, \"$respond_id\"); return false;'>$reply_text</a>";
return $before . $link . $after;
}
@ -920,14 +920,48 @@ function comment_reply_link($args = array(), $comment = null, $post = null) {
*
* @since 2.7.0
*
* @param string $text Optional. Text to display for cancel reply.
* @param string $respond_id Optional. HTML ID attribute for JS cancelCommentReply function.
* @param string $respond_root Optional. Second parameter for JS cancelCommentReply function.
* @param string $text Optional. Text to display for cancel reply link.
*/
function cancel_comment_reply_link($text = '', $respond_id = 'respond', $respond_root = 'content') {
function cancel_comment_reply_link($text = '') {
if ( empty($text) )
$text = __('Click here to cancel reply.');
echo '<a href="#" onclick="cancelCommentReply(\'' . $respond_id . '\', \'' . $respond_root . '\'); return false;">' . $text . '</a>';
$style = isset($_GET['replytocom']) ? '' : ' style="display:none;"';
echo '<a rel="nofollow" id="cancel-comment-reply-link" href="' . wp_specialchars( remove_query_arg('replytocom') ) . '#respond"' . $style . '>' . $text . '</a>';
}
/**
* Output hidden input HTML for replying to comments.
*
* @since 2.7.0
*/
function comment_parent_field() {
$replytoid = isset($_GET['replytocom']) ? (int) $_GET['replytocom'] : 0;
echo "<input type='hidden' name='comment_parent' id='comment-parent' value='$replytoid' />\n";
}
/**
* Display text based on comment reply status. Only affects users with Javascript disabled.
*
* @since 2.7.0
*
* @param string $noreplytext Optional. Text to display when not replying to a comment.
* @param string $replytext Optional. Text to display when replying to a comment. Accepts "%s" for the author of the comment being replied to.
* @param string $linktoparent Optional. Boolean to control making the author's name a link to their comment.
*/
function comment_form_title( $noreplytext = 'Leave a Reply', $replytext = 'Leave a Reply to %s', $linktoparent = TRUE ) {
global $comment;
$replytoid = isset($_GET['replytocom']) ? (int) $_GET['replytocom'] : 0;
if ( 0 == $replytoid )
echo $noreplytext;
else {
$comment = get_comment($replytoid);
$author = ( $linktoparent ) ? '<a href="#comment-' . get_comment_ID() . '">' . get_comment_author() . '</a>' : get_comment_author();
printf( $replytext, $author );
}
}
/**
@ -1046,7 +1080,7 @@ class Walker_Comment extends Walker {
<?php echo apply_filters('comment_text', get_comment_text()) ?>
<div class="reply" style="display:none">
<div class="reply">
<?php echo comment_reply_link(array('add_below' => $add_below, 'depth' => $depth, 'max_depth' => $args['depth'])) ?>
<?php if ( 'ul' == $args['style'] ) : ?>
</div>

View File

@ -1,17 +1,13 @@
function moveAddCommentForm(theId,threadId,respondId){
jQuery("#"+respondId).appendTo("#"+theId);
jQuery("#comment-parent").val(threadId);
jQuery("#cancel-comment-reply").show();
function moveAddCommentForm(commId, parentId, respondId) {
var div = document.createElement('div');
jQuery("#"+respondId).before( jQuery(div).attr('id', 'wp-temp-form-div').hide() ).appendTo("#"+commId);
jQuery("#comment-parent").val(parentId);
jQuery("#cancel-comment-reply-link").show().click(function(){
jQuery("#comment-parent").val("0");
jQuery('#wp-temp-form-div').after( jQuery("#"+respondId) ).remove();
jQuery(this).hide();
return false;
});
jQuery("#comment").focus();
}
function cancelCommentReply(respondId,respondRoot){
jQuery("#cancel-comment-reply").hide();
jQuery("#"+respondId).appendTo("#"+respondRoot);
document.location.href="#respond";
jQuery("#comment").focus();
jQuery("#comment-parent").val("0");
}
jQuery(document).ready(function($){
$(".thread-odd").find("div.reply").show();
$(".thread-even").find("div.reply").show();
});
}

View File

@ -139,7 +139,7 @@ function wp_default_scripts( &$scripts ) {
$scripts->add( 'jquery-ui-resizable', '/wp-includes/js/jquery/ui.resizable.js', array('jquery-ui-core'), '1.5.2' );
$scripts->add( 'jquery-ui-dialog', '/wp-includes/js/jquery/ui.dialog.js', array('jquery-ui-resizable', 'jquery-ui-draggable'), '1.5.2' );
$scripts->add( 'comment-reply', '/wp-includes/js/comment-reply.js', array('jquery'), '20080929');
$scripts->add( 'comment-reply', '/wp-includes/js/comment-reply.js', array('jquery'), '20081009');
if ( is_admin() ) {
$scripts->add( 'ajaxcat', '/wp-admin/js/cat.js', array( 'wp-lists' ), '20071101' );