This repository has been archived by the owner on Jul 16, 2019. It is now read-only.
forked from projectestac/moodle-mod_geogebra
-
Notifications
You must be signed in to change notification settings - Fork 0
/
geogebra_view.js
100 lines (82 loc) · 2.41 KB
/
geogebra_view.js
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
var adapter = {
startTime : Math.floor(new Date().getTime() / 1000),
applet : new Object(),
properties : new Array(),
propertyString : "",
initialized: false,
init : function() {
if (!this.initialized) {
tmp = this.propertyString.split('&');
for (i in tmp) {
tmppr = tmp[i].split('=');
this.properties[tmppr[0]] = tmppr[1];
}
if (this.properties['duration'] === undefined) {
this.properties['duration'] = 0;
}
if (this.properties['state'] != undefined) {
console.log('Geogebra data loaded');
this.applet.setBase64(unescape(this.properties['state']));
}
this.encodeProperties();
this.initialized = true;
}
},
doExit : function() {
duration = Math.floor(new Date().getTime() / 1000) - this.startTime;
this.properties['state'] = this.applet.getBase64();
this.properties['grade'] = this.applet.getValue('grade');
this.properties['duration'] = parseInt(this.properties['duration']) + duration;
this.encodeProperties();
},
encodeProperties : function() {
tmp = "";
for ( var i in this.properties) {
tmp += i + '=' + this.properties[i] + '&';
}
this.propertyString = tmp;
}
}
function geogebra_addEvent(object, eventName, callback) {
if (object == null) {
return;
}
if (object.addEventListener) {
object.addEventListener(eventName, callback, false);
} else {
object.attachEvent('on' + eventName, callback);
}
}
function geogebra_submit_attempt(){
var form = document.getElementById('geogebra_form');
adapter.doExit();
form.appletInformation.value = adapter.propertyString;
form.submit();
}
geogebra_addEvent(window, 'load', function() {
init_ggb();
});
function init_ggb() {
if (typeof ggbApplet == 'undefined') {
var applet = document.ggbApplet;
} else {
var applet = ggbApplet;
}
if (typeof applet == 'undefined') {
setTimeout(init_ggb, 1000);
return;
}
var form = document.getElementById('geogebra_form');
adapter.propertyString = form.prevAppletInformation.value;
adapter.applet = applet;
adapter.init();
var save = document.getElementById('geogebra_form_save');
geogebra_addEvent(save, 'click', function(e) {
return geogebra_submit_attempt();
});
var submit = document.getElementById('geogebra_form_submit');
geogebra_addEvent(submit, 'click', function(e) {
form.f.value = 1;
return geogebra_submit_attempt();
});
}