Permalink
Browse files

Warn when #comments element is missing.

Avoid unseen bugs, or hard to understand situations for developers.
  • Loading branch information...
1 parent c7dd194 commit 867b79f601637048975d41a7ac477e5f53dcfe1c @vdboor vdboor committed May 31, 2012
Showing with 12 additions and 3 deletions.
  1. +12 −3 fluent_comments/static/fluent_comments/js/ajaxcomments.js
@@ -171,8 +171,9 @@
// Show comment
var had_preview = removePreview();
- $('#comments').append(data['html']).removeClass('empty');
- var $new_comment = $("#comments > div.comment-item:last");
+ var $comments = getCommentsDiv();
+ $comments.append(data['html']).removeClass('empty');
+ var $new_comment = $comments.children("div.comment-item:last");
if( had_preview )
// Avoid double jump when preview was removed. Instead refade to final comment.
@@ -191,7 +192,7 @@
{
// If not explicitly added to the HTML, include a previewarea in the comments.
// This should at least give the same markup.
- $("#comments").append('<div id="comment-preview-area"></div>').addClass('has-preview');
+ getCommentsDiv().append('<div id="comment-preview-area"></div>').addClass('has-preview');
$previewarea = $("#comment-preview-area");
previewAutoAdded = true;
}
@@ -217,6 +218,14 @@
}
}
+ function getCommentsDiv()
+ {
+ var $comments = $("#comments");
+ if( $comments.length == 0 )
+ alert("Internal error - unable to display comment.\n\nreason: container is missing in the page.");
+ return $comments;
+ }
+
function removePreview()
{
var $previewarea = $("#comment-preview-area");

0 comments on commit 867b79f

Please sign in to comment.