aboutsummaryrefslogtreecommitdiff
path: root/bootstrap/comments/frontend/addratings.js
blob: c69bd0a7d6d6f2c4542d08ac3f243882d6753cae (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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Add Like/Dislike link and count to template (addratings.js)
HashOver.prototype.comments.addRatings = function (comment, template, action, commentKey)
{
	// Reference to the parent object
	var hashover = this.parent;

	// The opposite action
	var opposite = (action === 'like') ? 'dislike' : 'like';

	// Check if the comment doesn't belong to the logged in user
	if (comment['user-owned'] === undefined) {
		// Check whether this comment was liked/disliked by the visitor
		if (comment[action + 'd'] !== undefined) {
			// If so, setup indicators that comment was liked/disliked
			var className = 'hashover-' + action + 'd';
			var title = hashover.locale[action + 'd-comment'];
			var text = hashover.locale[action + 'd'];
		} else {
			// If not, setup indicators that comment can be liked/disliked
			var className = 'hashover-' + action;
			var title = hashover.locale[action + '-comment'];
			var text = hashover.locale[action][0];
		}

		// Append class to indicate dislikes are enabled
		if (hashover.setup['allows-' + opposite + 's'] === true) {
			className += ' hashover-' + opposite + 's-enabled';
		}

		// Add like/dislike link to HTML template
		template[action + '-link'] = hashover.strings.parseTemplate (hashover.ui[action + '-link'], {
			permalink: commentKey,
			class: className,
			title: title,
			text: text
		});
	}

	// Check if the comment has been likes/dislikes
	if (comment[action + 's'] !== undefined) {
		// Add likes/dislikes to HTML template
		template[action + 's'] = comment[action + 's'];

		// Get "X Like/Dislike(s)" locale
		var plural = (comment[action + 's'] === 1 ? 0 : 1);
		var count = comment[action + 's'] + ' ' + hashover.locale[action][plural];
	}

	// Add like count to HTML template
	template[action + '-count'] = hashover.strings.parseTemplate (hashover.ui[action + '-count'], {
		permalink: commentKey,
		text: count || ''
	});
};