aboutsummaryrefslogtreecommitdiff
path: root/bootstrap/comments/frontend/showmorecomments.js
blob: 35a1ce0649bbb652ae7cd05a4746bda137e2142f (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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// onClick event for more button (showmorecomments.js)
HashOver.prototype.showMoreComments = function (element, finishedCallback)
{
	finishedCallback = finishedCallback || null;

	// Reference to this object
	var hashover = this;

	// Do nothing if already showing all comments
	if (this.instance['showing-more'] === true) {
		// Execute callback function
		if (finishedCallback !== null) {
			finishedCallback ();
		}

		return false;
	}

	// Check if AJAX is enabled
	if (this.setup['uses-ajax'] !== false) {
		// If so, set request path
		var requestPath = '/loadcomments';

		// Set URL queries
		var queries = [
			'url=' + encodeURIComponent (this.instance['page-url']),
			'title=' + encodeURIComponent (this.instance['page-title']),
			'thread=' + encodeURIComponent (this.instance['thread-name']),
			'start=' + encodeURIComponent (this.setup['collapse-limit']),
			'ajax=yes'
		];

		// Handle AJAX request return data
		this.ajax ('POST', requestPath, queries, function (json) {
			// Store start time
			var execStart = Date.now ();

			// Display the comments
			hashover.appendComments (json.primary);

			// Remove loading class from element
			hashover.classes.remove (element, 'hashover-loading');

			// Hide the more hyperlink and display the comments
			hashover.hideMoreLink (finishedCallback);

			// Store execution time
			var execTime = Date.now () - execStart;

			// Log execution time and memory usage in JavaScript console
			if (window.console) {
				console.log (hashover.strings.sprintf ('HashOver: front-end %d ms, backend %d ms, %s', [
					execTime, json.statistics['execution-time'], json.statistics['script-memory']
				]));
			}
		}, true);

		// And set class to indicate loading to element
		this.classes.add (element, 'hashover-loading');
	} else {
		// If not, hide the more hyperlink and display the comments
		this.hideMoreLink (finishedCallback);
	}

	// Set all comments as shown
	this.instance['showing-more'] = true;

	return false;
};