Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for displaying multiple comment forms on the same page #1945

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions e107_handlers/comment_class.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,12 +276,12 @@ function form_comment($action, $table, $id, $subject, $content_type, $return = F
// -------------------------------------------------------------

$indent = ($action == 'reply') ? " class='media col-md-offset-1 offset1' " : " class='media' ";
$formid = ($action == 'reply') ? "e-comment-form-reply" : "e-comment-form";
$formclass = ($action == 'reply') ? "e-comment-form-reply" : "e-comment-form";

$text = "\n<div{$indent}>\n".e107::getMessage()->render('postcomment', true, false, false);//temporary here

// $text .= "Indent = ".$indent;
$text .= "<form id='{$formid}' method='post' action='".str_replace('http:', '', $_SERVER['REQUEST_URI'])."' >";
$text .= "<form class='{$formclass}' method='post' action='".str_replace('http:', '', $_SERVER['REQUEST_URI'])."' >";

$data = array(
'action' => $action,
Expand Down Expand Up @@ -1134,11 +1134,11 @@ function compose_comment($table, $action, $id, $width, $subject, $rate = FALSE,
if($text)
{
//XXX Do NOT add to template - too important to allow for modification.
$text = "<ul class='media-list' id='comments-container'>\n".$text."\n</ul>";
$text = "<ul class='media-list comments-container'>\n".$text."\n</ul>";
}
else
{
$text = "<ul class='media-list' id='comments-container'><li><!-- --></li></ul>";
$text = "<ul class='media-list comments-container'><li><!-- --></li></ul>";
}

$search = array("{MODERATE}","{COMMENTS}","{COMMENTFORM}","{COMMENTNAV}");
Expand All @@ -1154,7 +1154,7 @@ function compose_comment($table, $action, $id, $width, $subject, $rate = FALSE,
if ($tablerender)
{

echo $ns->tablerender("<span id='e-comment-total'>".$this->totalComments."</span> ".LAN_COMMENTS, $TEMPL, 'comment', TRUE);
echo $ns->tablerender("<span class='e-comment-total'>".$this->totalComments."</span> ".LAN_COMMENTS, $TEMPL, 'comment', TRUE);
}
else
{
Expand All @@ -1163,7 +1163,7 @@ function compose_comment($table, $action, $id, $width, $subject, $rate = FALSE,
}
elseif($return === 'html')
{
return $ns->tablerender("<span id='e-comment-total'>".$this->totalComments."</span> ".LAN_COMMENTS, $TEMPL, 'comment', true);
return $ns->tablerender("<span class='e-comment-total'>".$this->totalComments."</span> ".LAN_COMMENTS, $TEMPL, 'comment', true);
}
//echo $modcomment.$comment;
//echo $text;
Expand All @@ -1179,7 +1179,7 @@ function compose_comment($table, $action, $id, $width, $subject, $rate = FALSE,
$ret['comment'] = $text;

$ret['comment_form'] = $comment;
$ret['caption'] = "<span id='e-comment-total'>".$this->totalComments."</span> ".LAN_COMMENTS;
$ret['caption'] = "<span class='e-comment-total'>".$this->totalComments."</span> ".LAN_COMMENTS;

return (!$return) ? "" : $ret;
}
Expand Down
24 changes: 14 additions & 10 deletions e107_web/js/core/front.jquery.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,15 @@ $(document).ready(function()

$(document).on("click", ".e-comment-submit", function(){

var commentsParent = $(this).parent().parent().parent().parent().parent().parent().parent();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't work if you use custom templates for comments, because the HTML structure may be not the same. Use parents() instead. For example if you want to get the form, which contains your element, use something like this:

var $form = $(this).parents('form:first');

var url = $(this).attr("data-target");
var sort = $(this).attr("data-sort");
var pid = parseInt($(this).attr("data-pid"));
var formid = (pid != '0') ? "#e-comment-form-reply" : "#e-comment-form";
var data = $('form'+formid).serialize() ;
var total = parseInt($("#e-comment-total").text());
var formid = (pid != '0') ? ".e-comment-form-reply" : ".e-comment-form";
var data = $(commentsParent).find('form'+formid).serialize();
var total = parseInt($(commentsParent).find(".e-comment-total").text());
var commentsContainer = $(commentsParent).find(".comments-container");


$.ajax({
type: 'POST',
Expand All @@ -99,7 +102,7 @@ $(document).ready(function()

$("#comment").val('');

if($('#comments-container').length){
if($(commentsContainer).length){
// alert('true');
}else{
// $("#e-comment-form").parent().prepend("<div id='comments-container'></div>");
Expand All @@ -111,17 +114,17 @@ $(document).ready(function()
}
else if(sort == 'desc')
{
$('#comments-container').prepend(a.html).hide().slideDown(800); // FIXME - works in jquery 1.7, not 1.8
$(commentsContainer).prepend(a.html).hide().slideDown(800); // FIXME - works in jquery 1.7, not 1.8
}
else
{
$('#comments-container').append(a.html).hide().slideDown(800); // FIXME - works in jquery 1.7, not 1.8
$(commentsContainer).append(a.html).hide().slideDown(800); // FIXME - works in jquery 1.7, not 1.8
alert('Thank you for commenting'); // possibly needed as the submission may go unoticed by the user
}

if(!a.error)
{
$("#e-comment-total").text(total + 1);
$(commentsParent).find(".e-comment-total").text(total + 1);
if(pid != '0')
{
$(formid).hide();
Expand Down Expand Up @@ -152,7 +155,7 @@ $(document).ready(function()
var sp = $(this).attr('id').split("-");
var id = "#comment-" + sp[3];

var present = $('#e-comment-form-reply');
//var present = $('#e-comment-form-reply'); // NES: Not beign used?
// console.log(present);


Expand Down Expand Up @@ -270,10 +273,11 @@ $(document).ready(function()

$(document).on("click", ".e-comment-delete", function(){

var commentsParent = $(this).parent().parent().parent().parent().parent().parent().parent();
var url = $(this).attr("data-target");
var sp = $(this).attr('id').split("-");
var id = "#comment-" + sp[3];
var total = parseInt($("#e-comment-total").text());
var total = parseInt($(commentsParent).find(".e-comment-total").text());

$.ajax({
type: 'POST',
Expand All @@ -285,7 +289,7 @@ $(document).ready(function()
if(!a.error)
{
$(id).hide('slow');
$("#e-comment-total").text(total - 1);
$(commentsParent).find(".e-comment-total").text(total + 1);
}

}
Expand Down