2009-06-02 17:09:25 +02:00
|
|
|
jq(document).ready(function() {
|
2009-06-20 18:00:36 +02:00
|
|
|
|
|
|
|
/*****************************************************************
|
|
|
|
* Show the reply button only when Javascript is enabled.
|
2009-06-02 17:09:25 +02:00
|
|
|
* Otherwise hide it, since the reply functions relies on jQuery.
|
2009-06-20 18:00:36 +02:00
|
|
|
*****************************************************************/
|
|
|
|
jq(".reply-to-comment-button").css("display" , "inline");
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************
|
|
|
|
* Create reply to comment form.
|
|
|
|
*****************************************************************/
|
|
|
|
jq(".reply-to-comment-button").bind("click", function(e){
|
|
|
|
|
|
|
|
var comment_div = jq(this).parents().filter(".comment");
|
|
|
|
var comment_id = comment_div.attr("id");
|
|
|
|
|
|
|
|
var reply_button = comment_div.find(".reply-to-comment-button");
|
|
|
|
|
|
|
|
/* Clone the reply div at the end of the page template that contains
|
|
|
|
* the regular comment form and insert it after the reply button of the
|
|
|
|
* current comment.
|
|
|
|
*/
|
|
|
|
var reply_div = jq("#commenting").clone(true);
|
|
|
|
reply_div.appendTo(comment_div).css("display", "none");
|
|
|
|
|
|
|
|
/* Remove id="reply" attribute, since we use it to uniquely
|
|
|
|
the main reply form. */
|
|
|
|
reply_div.removeAttr("id")
|
|
|
|
|
|
|
|
/* Hide the reply button (only hide, because we may want to show it
|
|
|
|
* again if the user hits the cancel button).
|
|
|
|
*/
|
|
|
|
jq(reply_button).css("display", "none");
|
|
|
|
|
|
|
|
/* Fetch the reply form inside the reply div */
|
|
|
|
var reply_form = reply_div.find("form");
|
|
|
|
|
|
|
|
/* Add a hidden field with the id of the comment */
|
|
|
|
reply_form.append("<input type=\"hidden\" value=\"" + comment_id + "\" name=\"form.reply_to_comment_id\"");
|
|
|
|
|
|
|
|
/* Change the form action to @@reply-to-comment */
|
|
|
|
var old_action = reply_form.attr("action");
|
|
|
|
var new_action = old_action.replace("@@add-comment", "@@reply-to-comment");
|
|
|
|
reply_form.attr("action", new_action);
|
|
|
|
|
|
|
|
/* Add a remove-reply-to-comment Javascript function to remove the form */
|
|
|
|
var cancel_reply_button = reply_div.find(".cancelreplytocomment");
|
|
|
|
cancel_reply_button.attr("id", comment_id);
|
|
|
|
|
|
|
|
/* Remove already typed in text from the reply form. */
|
|
|
|
reply_form.find(".field").find("input").attr("value", "")
|
|
|
|
reply_form.find(".field").find("textarea").attr("value", "")
|
|
|
|
|
|
|
|
/* Show the reply layer with a slide down effect */
|
|
|
|
reply_div.slideDown("slow");
|
|
|
|
|
|
|
|
/* Show the cancel button in the reply-to-comment form */
|
|
|
|
cancel_reply_button.css("display", "inline");
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************
|
|
|
|
* Remove reply to comment form.
|
|
|
|
*****************************************************************/
|
|
|
|
jq(".cancelreplytocomment").bind("click", function(e){
|
|
|
|
|
|
|
|
reply_to_comment_button = jq(this).parents().filter(".comment").find(".reply-to-comment-button");
|
|
|
|
|
|
|
|
/* Find the reply-to-comment form and hide and remove it again. */
|
|
|
|
reply_to_comment_form = jq(this).parents().filter(".reply")
|
|
|
|
reply_to_comment_form.slideUp("slow", function() { jq(this).remove(); } );
|
|
|
|
|
|
|
|
/* Show the reply-to-comment button again. */
|
|
|
|
reply_to_comment_button.css("display", "inline");
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|