aboutsummaryrefslogtreecommitdiff
path: root/bootstrap/comments/frontend/getallcomments.js
diff options
context:
space:
mode:
Diffstat (limited to 'bootstrap/comments/frontend/getallcomments.js')
-rw-r--r--bootstrap/comments/frontend/getallcomments.js25
1 files changed, 25 insertions, 0 deletions
diff --git a/bootstrap/comments/frontend/getallcomments.js b/bootstrap/comments/frontend/getallcomments.js
new file mode 100644
index 0000000..b5df6b0
--- /dev/null
+++ b/bootstrap/comments/frontend/getallcomments.js
@@ -0,0 +1,25 @@
+// "Flatten" the comments object (getallcomments.js)
+HashOver.prototype.getAllComments = function (comments)
+{
+ var commentsCopy = this.cloneObject (comments);
+ var output = [];
+
+ function descend (comment)
+ {
+ output.push (comment);
+
+ if (comment.replies !== undefined) {
+ for (var reply = 0, total = comment.replies.length; reply < total; reply++) {
+ descend (comment.replies[reply]);
+ }
+
+ delete comment.replies;
+ }
+ }
+
+ for (var comment = 0, total = commentsCopy.length; comment < total; comment++) {
+ descend (commentsCopy[comment]);
+ }
+
+ return output;
+};