aboutsummaryrefslogtreecommitdiff
path: root/bootstrap/comments/frontend/ajaxedit.js
blob: 29c5656b4e081bfcfb7842d909827f84f2c7359f (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
26
27
28
29
// For editing comments (ajaxedit.js)
HashOver.prototype.AJAXEdit = function (json, permalink, destination, isReply)
{
	// Get old comment element nodes
	var comment = this.elements.get (permalink, true);
	var oldNodes = comment.childNodes;
	var oldComment = this.permalinks.getComment (permalink, this.instance.comments.primary);

	// Get new comment element nodes
	var newNodes = this.HTMLToNodeList (this.comments.parse (json.comment));
	    newNodes = newNodes[0].childNodes;

	// Replace old comment with edited comment
	for (var i = 0, il = newNodes.length; i < il; i++) {
		if (typeof (oldNodes[i]) === 'object'
		    && typeof (newNodes[i]) === 'object')
		{
			comment.replaceChild (newNodes[i], oldNodes[i]);
		}
	}

	// Add controls back to the comment
	this.addControls (json.comment);

	// Update old in array comment with edited comment
	for (var attribute in json.comment) {
		oldComment[attribute] = json.comment[attribute];
	}
};