summaryrefslogtreecommitdiffstats
path: root/js/comments.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/comments.js')
-rw-r--r--js/comments.js65
1 files changed, 50 insertions, 15 deletions
diff --git a/js/comments.js b/js/comments.js
index e7163a0fd..12bc00d46 100644
--- a/js/comments.js
+++ b/js/comments.js
@@ -38,11 +38,11 @@ function updateCommentPrivacy(checkbox, id) {
function toggle_comment_display(link, comment_id) {
var comment = document.getElementById('comment_text_' + comment_id);
- var re = new RegExp(/\bcollapsed\b/);
- if (comment.className.match(re))
- expand_comment(link, comment);
- else
- collapse_comment(link, comment);
+ if (YAHOO.util.Dom.hasClass(comment, 'collapsed')) {
+ expand_comment(link, comment, comment_id);
+ } else {
+ collapse_comment(link, comment, comment_id);
+ }
}
function toggle_all_comments(action) {
@@ -55,24 +55,31 @@ function toggle_all_comments(action) {
var comment = comments[i];
if (!comment)
continue;
-
- var id = comments[i].id.match(/\d*$/);
+ var id = comment.id.match(/^comment_text_(\d*)$/);
+ if (!id)
+ continue;
+ id = id[1];
var link = document.getElementById('comment_link_' + id);
- if (action == 'collapse')
- collapse_comment(link, comment);
- else
- expand_comment(link, comment);
+ if (action == 'collapse') {
+ collapse_comment(link, comment, id);
+ } else {
+ expand_comment(link, comment, id);
+ }
}
}
-function collapse_comment(link, comment) {
+function collapse_comment(link, comment, comment_id) {
link.innerHTML = "[+]";
YAHOO.util.Dom.addClass(comment, 'collapsed');
+ YAHOO.util.Dom.addClass('comment_tag_' + comment_id, 'collapsed');
}
-function expand_comment(link, comment) {
+function expand_comment(link, comment, comment_id) {
link.innerHTML = "[-]";
+ YAHOO.util.Dom.addClass('cr' + comment_id, 'collapsed');
+ YAHOO.util.Dom.removeClass('c' + comment_id, 'bz_default_collapsed');
YAHOO.util.Dom.removeClass(comment, 'collapsed');
+ YAHOO.util.Dom.removeClass('comment_tag_' + comment_id, 'collapsed');
}
function wrapReplyText(text) {
@@ -125,11 +132,12 @@ function wrapReplyText(text) {
/* This way, we are sure that browsers which do not support JS
* won't display this link */
-function addCollapseLink(count, title) {
+function addCollapseLink(count, collapsed, title) {
document.write(' <a href="#" class="bz_collapse_comment"' +
' id="comment_link_' + count +
'" onclick="toggle_comment_display(this, ' + count +
- '); return false;" title="' + title + '">[-]<\/a> ');
+ '); return false;" title="' + title + '">[' +
+ (collapsed ? '+' : '&minus;') + ']<\/a> ');
}
function goto_add_comments( anchor ){
@@ -143,3 +151,30 @@ function goto_add_comments( anchor ){
},10);
return false;
}
+
+if (typeof Node == 'undefined') {
+ /* MSIE doesn't define Node, so provide a compatibility object */
+ window.Node = {
+ TEXT_NODE: 3,
+ ENTITY_REFERENCE_NODE: 5
+ };
+}
+
+/* Concatenates all text from element's childNodes. This is used
+ * instead of innerHTML because we want the actual text (and
+ * innerText is non-standard).
+ */
+function getText(element) {
+ var child, text = "";
+ for (var i=0; i < element.childNodes.length; i++) {
+ child = element.childNodes[i];
+ var type = child.nodeType;
+ if (type == Node.TEXT_NODE || type == Node.ENTITY_REFERENCE_NODE) {
+ text += child.nodeValue;
+ } else {
+ /* recurse into nodes of other types */
+ text += getText(child);
+ }
+ }
+ return text;
+}