aboutsummaryrefslogtreecommitdiff
path: root/bootstrap/comments/frontend/instantiator.js
blob: 830321bbb9d18d5908878755018d394b15bb9785 (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
// Real constructor (instantiator.js)
HashOver.instantiator = function (options)
{
	// Get backend queries
	var queries = HashOver.getBackendQueries (options);

	// Check if we're instantiating the first HashOver object
	if (HashOver.prepared !== true) {
		// If so, set query indicating a request for backend information
		queries.push ('prepare=true');
	}

	// Reference to this object
	var hashover = this;

	// Increment HashOver instance count
	HashOver.instanceCount++;

	// Backend request path
	var requestPath = '/commentsajax';

	// Handle backend request
	this.ajax ('POST', requestPath, queries, function (json) {
		// Handle error messages
		if (json.message !== undefined) {
			hashover.displayError (json);
			return;
		}

		// Set the backend information
		if (HashOver.prepared !== true) {
			// Locales from HashOver backend
			HashOver.prototype.locale = json.locale;

			// Setup information from HashOver back-end
			HashOver.prototype.setup = json.setup;

			// UI HTML from HashOver back-end
			HashOver.prototype.ui = json.ui;

			// Mark HashOver as prepared
			HashOver.prepared = true;
		}

		// Thread information from HashOver back-end
		hashover.instance = json.instance;

		// Backend execution time and memory usage statistics
		hashover.statistics = json.statistics;

		// Initiate HashOver
		hashover.init ();
	}, true);

	// Set instance number to current instance count
	this.instanceNumber = HashOver.instanceCount;

	// Add parent proterty to all prototype objects
	for (var name in this) {
		var value = this[name];

		if (value && value.constructor === Object) {
			value.parent = this;
		}
	}
};