Skip to content
This repository was archived by the owner on Jun 7, 2023. It is now read-only.

Commit f882f14

Browse files
committed
Fixed bug caused by non-unique khanex exercise names.
1 parent 455619a commit f882f14

2 files changed

Lines changed: 15 additions & 13 deletions

File tree

runestone/khanex/js/khan-exercise.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1964,11 +1964,12 @@ var Khan = (function() {
19641964
var curTime = new Date().getTime();
19651965
var data = buildAttemptData(pass, ++attempts, JSON.stringify(validator.guess), curTime);
19661966

1967-
// Save the answer to runestone
1968-
console.log("RAM DEBUG data = " + JSON.stringify(data));
1967+
// Save the answer to runestone // We reconstruct the unique function name
1968+
// console.log("RAM DEBUG data = " + JSON.stringify(data));
19691969
if (window.parent.component_factory) {
1970-
window.parent.component_factory.khanex(data);
1971-
console.log("RAM DEBUG saved to runestone");
1970+
var fn_name = "khanex_" + data['sha1'];
1971+
window.parent.component_factory[fn_name](data);
1972+
console.log("RAM DEBUG Khanex exercise saved to runestone");
19721973
}
19731974

19741975
request( "problems/" + problemNum + "/attempt", data, function() {

runestone/khanex/js/khanex.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export default class Khanex extends RunestoneBase {
3030
this.origElem = orig;
3131
this.divid = orig.id;
3232
this.resultsViewer = $(orig).data("results");
33-
this.getIFrame();
33+
this.getIFrameAndQuizname();
3434
this.renderKhanex(); //generates HTML
3535
// Checks localStorage to see if this khanex has already been completed by this user.
3636
// this.checkKhanexStorage();
@@ -39,13 +39,17 @@ export default class Khanex extends RunestoneBase {
3939
}
4040

4141
// The main content of the khanex node is the iframe.
42-
getIFrame() {
42+
getIFrameAndQuizname() {
4343
var html = $(this.origElem).html();
4444
var p1 = html.search('<iframe');
4545
var p2 = html.search('</iframe>');
4646
this.iframe = html.slice(p1,p2+8);
4747
if (DEBUG) console.log("DEBUG: getQuestionText() html = " + html);
4848
if (DEBUG) console.log("DEBUG: getQuestionText() iframe = " + this.iframe);
49+
p1 = html.search('khanex/qs/');
50+
p2 = html.search('.html');
51+
this.quizname = html.slice(p1+10,p2); // Grab the quizname from iframe
52+
if (DEBUG) console.log("DEBUG quizname= ", this.quizname);
4953
}
5054

5155
//generates the HTML that the user interacts with
@@ -90,7 +94,7 @@ export default class Khanex extends RunestoneBase {
9094
try {
9195
var khanex = new Khanex({ orig: this });
9296
khanexList[this.id] = khanex;
93-
setupCallback(khanex);
97+
setupCallback(khanex,khanex.quizname);
9498
} catch (err) {
9599
console.log(`Error rendering Khanex Exercise ${this.id}
96100
Details: ${err}`);
@@ -101,14 +105,11 @@ export default class Khanex extends RunestoneBase {
101105

102106
// Sets up a call back function on the window containing the khanex component
103107
// We need to pass a reference to this khanex object so that it can be use during callback.
104-
function setupCallback(khanex) {
108+
function setupCallback(khanex,quizname) {
105109
if (typeof window.component_factory === "undefined") {
106110
window.component_factory = {};
107111
}
108-
window.component_factory.khanex = function(result) {
109-
if (DEBUG) console.log("DEBUG: Khanex component factory = " + JSON.stringify(window.component_factory));
110-
if (DEBUG) console.log("DEBUG: Khanex component factory khanex " + JSON.stringify(result));
111-
khanex.submitKhanex(result);
112-
}
112+
var fn_name = "khanex_" + quizname; // Unique function name
113+
window.component_factory[fn_name] = function(result) { khanex.submitKhanex(result); }
113114
}
114115

0 commit comments

Comments
 (0)