@@ -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