aboutsummaryrefslogtreecommitdiff
path: root/website/assets/js/script.js
diff options
context:
space:
mode:
Diffstat (limited to 'website/assets/js/script.js')
-rw-r--r--website/assets/js/script.js48
1 files changed, 48 insertions, 0 deletions
diff --git a/website/assets/js/script.js b/website/assets/js/script.js
new file mode 100644
index 0000000..94e38ea
--- /dev/null
+++ b/website/assets/js/script.js
@@ -0,0 +1,48 @@
1// Using deployJava.runApplet to target specific element
2// from http://stackoverflow.com/questions/13517790/using-deployjava-runapplet-to-target-specific-element?answertab=active#answer-15139480
3function writeTo(func, node) {
4 var content = "";
5 var oldwrite = document.write;
6 document.write = function(add) {
7 content += add;
8 };
9 func();
10 document.write = oldwrite;
11 node.innerHTML += content;
12}
13
14function launchApplet() {
15 var attributes = {
16 //code : "esieequest.Main",
17 //archive : "/game/esieequest.jar"
18 code : "java2d.Java2DemoApplet.class",
19 archive : "http://docs.oracle.com/javase/tutorial/deployment/deploymentInDepth/examples/dist/depltoolkit_Java2Demo/Java2Demo.jar"
20 };
21 var parameters = {
22 permissions : "sandbox"
23 };
24 var version = "1.7";
25 deployJava.runApplet(attributes, parameters, version);
26}
27
28function launchGame() {
29 var wrapper = document.getElementById("play");
30 if (deployJava.versionCheck("1.7+")) {
31 writeTo(launchApplet, wrapper);
32 } else {
33 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>';
34 }
35}
36
37// Run the applet only when the user wants to play
38// https://developer.mozilla.org/en-US/docs/Web/API/window.onhashchange
39var launched = false;
40function locationHashChanged() {
41 if (location.hash === "#play" && !launched) {
42 launched = true;
43 launchGame();
44 }
45}
46
47window.onhashchange = locationHashChanged;
48locationHashChanged();