aboutsummaryrefslogtreecommitdiff
path: root/bootstrap/comments/frontend/getallcomments.js
blob: b5df6b05707a4aa1b04234c98656197497462d8d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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;
};