WordPress.org

Ready to get started?Download WordPress

Forums

Adding javascript to comment_reply_link to change CSS (1 post)

  1. tropicaltidbits
    Member
    Posted 2 years ago #

    Hello,

    I am attempting to add a piece of javascript to comment reply links that will move one of my custom widget sidebars out of the way of the reply comment form by changing the sidebar's css position style. I found where comment_reply_link is invoked in the comments-template.php file:

    if ( get_option('comment_registration') && !$user_ID )
                    $link = '<a rel="nofollow" class="comment-reply-login" href="' . esc_url( wp_login_url( get_permalink() ) ) . '">' . $login_text . '</a>';
            else
                    $link = "<a class='comment-reply-link' href='" . esc_url( add_query_arg( 'replytocom', $comment->comment_ID ) ) . "#" . $respond_id . "' onclick=' return addComment.moveForm(\"$add_below-$comment->comment_ID\", \"$comment->comment_ID\", \"$respond_id\", \"$post->ID\")'>$reply_text</a>";
            return apply_filters('comment_reply_link', $before . $link . $after, $args, $comment, $post);
    }

    The js function addComment.moveForm is added to the links via the onclick event, and I want to include this js statement along with it:

    document.getElementById('widgets2').style.left='217px';

    This is meant to move the widgets2 div off to the right and out of the way, since it is already relatively-positioned. However, I can't figure out the proper syntax for implementing it. I have already tried this:

    $link = "<a class='comment-reply-link' href='" . esc_url( add_query_arg( 'replytocom', $comment->comment_ID ) ) . "#" . $respond_id . "' onclick=' return addComment.moveForm(\"$add_below-$comment->comment_ID\", \"$comment->comment_ID\", \"$respond_id\", \"$post->ID\"); document.getElementById('widgets2').style.left=\'217px\';'>$reply_text</a>";

    and this:

    $link = "<a class='comment-reply-link' href='" . esc_url( add_query_arg( 'replytocom', $comment->comment_ID ) ) . "#" . $respond_id . "' onclick='document.getElementById('widgets2').style.left=\'217px\'; return addComment.moveForm(\"$add_below-$comment->comment_ID\", \"$comment->comment_ID\", \"$respond_id\", \"$post->ID\")'>$reply_text</a>";

    Nothing seems to work. Any help would be appreciated.

Topic Closed

This topic has been closed to new replies.

About this Topic