forked from Khan/khan-exercises
-
Notifications
You must be signed in to change notification settings - Fork 0
/
exercise-event-logger.js
111 lines (85 loc) · 3.46 KB
/
exercise-event-logger.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
101
102
103
104
105
106
107
108
109
110
111
/* This is a Curriki specific document and listens to events
* of exercsies which are bound to the Khan exercise interface
* in "interface.js" around line 45.
*/
$(document).ready(function(){
$(Exercises).on("problemTemplateRendered", function(event){
var iframeId = $.getUrlVar('iframeId');
$(window.parent.document.getElementById(iframeId)).height(document.body.scrollHeight+50);
});
$(Exercises).on("newProblem", function(event){
// alert("Event triggered: newProblem \n" +
// "UserActivityLog: \n" + stringifyUserActivityLog());
});
$(Exercises).on("problemDone", function(event){
var log = Exercises.userActivityLog;
var lastActivty = log[log.length - 1][0];
var emptyCheckIcons = $("#check-icons").children(".icon-check-empty");
var isComplete = (emptyCheckIcons.length == 1 && lastActivty == "correct-activity") || emptyCheckIcons.length == 0;
var hasNotified = $("#exerciseDone").css("display") != "none";
if(isComplete && !hasNotified){
try{
top.jQuery("#khan-exercise-success-modal").modal("show");
top.Curriki.logEvent(['Khan-Exercise', 'exercise-complete', location.pathname])
} catch(exception){
console.log(exception);
alert("You got 5 correct in a row. Good job!");
}
$("#doExercise").css("display","none")
$("#exerciseDone").css("display","inline")
}
var nextEmptyCheckIcon = emptyCheckIcons[0];
if(nextEmptyCheckIcon != undefined){
nextEmptyCheckIcon.setAttribute("class","icon-check");
}
});
$(Exercises).on("checkAnswer", function(event){
var log = Exercises.userActivityLog;
var lastActivty = log[log.length - 1][0];
var hasNotified = $("#exerciseDone").css("display") != "none";
if(lastActivty == "incorrect-activity" && !hasNotified){
$("#check-icons").children(".icon-check").each(function(element){
this.setAttribute("class","icon-check-empty");
});
}
});
$(Exercises).on("hintShown", function(event){
var iframeId = $.getUrlVar('iframeId');
$(window.parent.document.getElementById(iframeId)).height(document.body.scrollHeight+50);
});
$(Exercises).on("readyForNextProblem", function(event){
// alert("Event triggered: readyForNextProblem \n" +
// "UserActivityLog: \n" + stringifyUserActivityLog());
});
$(Exercises).on("warning", function(event){
// alert("Event triggered: warning \n" +
// "UserActivityLog: \n" + stringifyUserActivityLog());
});
$(Exercises).on("upcomingExercise", function(event){
// alert("Event triggered: upcomingExercise \n" +
// "UserActivityLog: \n" + stringifyUserActivityLog());
});
$(Exercises).on("gotoNextProblem", function(event){
// alert("Event triggered: gotoNextProblem \n" +
// "UserActivityLog: \n" + stringifyUserActivityLog());
});
$(Exercises).on("updateUserExercise", function(event){
// alert("Event triggered: updateUserExercise \n" +
// "UserActivityLog: \n" + stringifyUserActivityLog());
});
$(Exercises).on("clearExistingProblem", function(event){
// alert("Event triggered: clearExistingProblem \n" +
// "UserActivityLog: \n" + stringifyUserActivityLog());
});
function stringifyUserActivityLog(){
var log = Exercises.userActivityLog;
if(log == undefined || log.length == 0) return "Empty";
var result = "";
for(var i = 0; i < log.length; i++){
result += "Type: " + log[i][0];
result += "\t\t Input: " + log[i][1];
result += "\t\t Time since last check: " + log[i][2] + "\n";
}
return result;
}
});