Skip to content
This repository has been archived by the owner on Aug 13, 2021. It is now read-only.

Commit

Permalink
add dynamic comments counter
Browse files Browse the repository at this point in the history
  • Loading branch information
fey committed Nov 18, 2018
1 parent f341082 commit 0dacd1a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
2 changes: 1 addition & 1 deletion resources/views/comments.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<br><br>


<p><span class="badge"><?= $countComments; ?></span> Comments:</p><br>
<p><span class="badge countComments"><?= $countComments; ?></span> Comments:</p><br>
<div class="comments" id="comment-0">

<?php if (!empty($comments)): Utilities\echoComments($comments); endif; ?>
Expand Down
27 changes: 16 additions & 11 deletions resources/views/foot.phtml
Original file line number Diff line number Diff line change
@@ -1,36 +1,41 @@
</div>

</div>
</div>

</body>
<?php if (isset($comments)): ?>
<script>
$( document ).ready(function() {
$(document).ready(function () {
$(this).on("click", ".answer", function () {
const linkedForm = $(this).next();
$('.comment > .answer-form').not(linkedForm).hide();
$('.comment > .answer-form').not(linkedForm).hide();
linkedForm.toggle();
});
$(this).on("submit", "form", function (event) {
const submitButton = $('button[type=submit], input[type=submit]');
submitButton.prop('disabled', true);
event.preventDefault();
const formData = $(this).serialize();
$.ajax({
type: "POST",
url: "",
data: formData,
type: "POST",
url: "",
data: formData,
dataType: "text",
success: function (response) {
const newComment = $.parseJSON(response);
$.get('', function(data) {
comment = $(data).find('#comment-' + newComment['id']);
$('#comment-' + newComment['parent_id']).append(comment);
$.get('', function (data) {

$('#comment-' + newComment['parent_id'])
.append($(data).find('#comment-' + newComment['id']));
const counter = $(data).find('.countComments');

$('.countComments').text($(data).find('.countComments').text());
submitButton.prop('disabled', false);
});
}
});
});
});


</script>
<?php endif; ?>
</html>

0 comments on commit 0dacd1a

Please sign in to comment.