forked from ChalmersGU-AI-course/shrdlite-course-project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
shrdlite-html.ts
67 lines (57 loc) · 2.11 KB
/
shrdlite-html.ts
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
///<reference path="Shrdlite.ts"/>
///<reference path="SVGWorld.ts"/>
///<reference path="ExampleWorlds.ts"/>
///<reference path="lib/jquery.d.ts" />
var defaultWorld = 'small';
var defaultSpeech = false;
$(function(){
var current = getURLParameter('world');
if (!(current in ExampleWorlds)) {
current = defaultWorld;
}
var speech = (getURLParameter('speech') || "").toLowerCase();
var useSpeech = (speech == 'true' || speech == '1' || defaultSpeech);
$('#currentworld').text(current);
$('<a>').text('reset')
.attr('href', '?world=' + current + '&speech=' + useSpeech)
.appendTo($('#resetworld'));
$('#otherworlds').empty();
for (var wname in ExampleWorlds) {
if (wname !== current) {
$('<a>').text(wname)
.attr('href', '?world=' + wname + '&speech=' + useSpeech)
.appendTo($('#otherworlds'))
.after(' ');
}
}
$('<a>').text(useSpeech ? 'turn off' : 'turn on')
.attr('href', '?world=' + current + '&speech=' + (!useSpeech))
.appendTo($('#togglespeech'));
var world = new SVGWorld(ExampleWorlds[current], useSpeech);
Shrdlite.interactive(world);
});
// Adapted from: http://www.openjs.com/scripts/events/exit_confirmation.php
function goodbye(e) {
if(!e) e = window.event;
// e.cancelBubble is supported by IE - this will kill the bubbling process.
e.cancelBubble = true;
// This is displayed in the dialog:
e.returnValue = 'Are you certain?\nYou cannot undo this, you know.';
// e.stopPropagation works in Firefox.
if (e.stopPropagation) {
e.stopPropagation();
e.preventDefault();
}
}
window.onbeforeunload = goodbye;
// Adapted from: http://www.jquerybyexample.net/2012/06/get-url-parameters-using-jquery.html
function getURLParameter(sParam) : string {
var sPageURL = window.location.search.slice(1);
var sURLVariables = sPageURL.split('&');
for (var i = 0; i < sURLVariables.length; i++) {
var sParameterName = sURLVariables[i].split('=');
if (sParameterName[0] == sParam) {
return sParameterName[1];
}
}
}