aboutsummaryrefslogtreecommitdiff
path: root/website/assets/js/script.js
blob: 0ab376de69dd72e281f2088a30cb5901f6e215cd (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
// Using deployJava.runApplet to target specific element
// from http://stackoverflow.com/questions/13517790/using-deployjava-runapplet-to-target-specific-element?answertab=active#answer-15139480
function writeTo(func, node) {
	var content = "";
	var oldwrite = document.write;
	document.write = function(add) {
		content += add;
	};
	func();
	document.write = oldwrite;
	node.innerHTML += content;
}

function launchApplet() {
	var attributes = {
		code : "esieequest.Game",
		archive : "/game/esieequest.jar"
	};
	var parameters = {
		//permissions : "sandbox"
	};
	var version = "1.7";
	deployJava.runApplet(attributes, parameters, version);
}

function launchGame() {
	var wrapper = document.getElementById("play");
	if (deployJava.versionCheck("1.7+")) {
		writeTo(launchApplet, wrapper);
	} else {
		wrapper.innerHTML = '<p>Java ≥7 is required to run this game.<br>Click <a href="javascript:deployJava.installJRE()">here</a> to get the latest Java Runtime Environment.</p>';
	}
}

// Run the applet only when the user wants to play
// https://developer.mozilla.org/en-US/docs/Web/API/window.onhashchange
var launched = false;
function locationHashChanged() {
	if (location.hash === "#play" && !launched) {
		launched = true;
		launchGame();
	}
}

window.onhashchange = locationHashChanged;
locationHashChanged();