88"use strict" ;
99
1010import RunestoneBase from "../../common/js/runestonebase.js" ;
11- import AudioTour from "./audiotour" ;
12- import "./activecode-i18n.en" ;
13- import "./activecode-i18n.pt-br" ;
11+ import AudioTour from "./audiotour.js" ;
12+ import "./activecode-i18n.en.js" ;
13+ import "./activecode-i18n.pt-br.js" ;
14+ import "./activecode-i18n.sr-Cyrl.js" ;
1415import CodeMirror from "codemirror" ;
1516import "codemirror/mode/python/python.js" ;
1617import "codemirror/mode/css/css.js" ;
@@ -20,7 +21,6 @@ import "codemirror/mode/javascript/javascript.js";
2021import "codemirror/mode/sql/sql.js" ;
2122import "codemirror/mode/clike/clike.js" ;
2223import "codemirror/mode/octave/octave.js" ;
23- import "./activecode-i18n.en.js" ;
2424import "./../css/activecode.css" ;
2525import "codemirror/lib/codemirror.css" ;
2626
@@ -43,6 +43,7 @@ export class ActiveCode extends RunestoneBase {
4343 super ( opts ) ;
4444 var suffStart ;
4545 var orig = $ ( opts . orig ) . find ( "textarea" ) [ 0 ] ;
46+ this . containerDiv = opts . orig ;
4647 this . useRunestoneServices = opts . useRunestoneServices ;
4748 this . python3 = opts . python3 ;
4849 this . alignVertical = opts . vertical ;
@@ -124,28 +125,28 @@ export class ActiveCode extends RunestoneBase {
124125 1000
125126 ) ;
126127 if ( this . autorun ) {
127- $ ( document ) . ready ( this . runProg . bind ( this ) ) ;
128+ // Simulate pressing the run button, since this will also prevent the user from clicking it until the initial run is complete, and also help the user understand why they're waiting.
129+ $ ( document ) . ready ( this . runButtonHandler . bind ( this ) ) ;
128130 }
131+ this . indicate_component_ready ( ) ;
129132 }
130133
131134 createEditor ( index ) {
132- this . containerDiv = document . createElement ( "div" ) ;
135+ this . outerDiv = document . createElement ( "div" ) ;
133136 var linkdiv = document . createElement ( "div" ) ;
134137 linkdiv . id = this . divid . replace ( / _ / g, "-" ) . toLowerCase ( ) ; // :ref: changes _ to - so add this as a target
135- $ ( this . containerDiv ) . addClass ( "ac_section alert alert-warning" ) ;
138+ $ ( this . outerDiv ) . addClass ( "ac_section alert alert-warning" ) ;
136139 var codeDiv = document . createElement ( "div" ) ;
137140 $ ( codeDiv ) . addClass ( "ac_code_div col-md-12" ) ;
138141 this . codeDiv = codeDiv ;
139- this . containerDiv . id = this . divid ;
140- this . containerDiv . lang = this . language ;
141- this . outerDiv = this . containerDiv ;
142- $ ( this . origElem ) . replaceWith ( this . containerDiv ) ;
142+ this . outerDiv . lang = this . language ;
143+ $ ( this . origElem ) . replaceWith ( this . outerDiv ) ;
143144 if ( linkdiv . id !== this . divid ) {
144145 // Don't want the 'extra' target if they match.
145- this . containerDiv . appendChild ( linkdiv ) ;
146+ this . outerDiv . appendChild ( linkdiv ) ;
146147 }
147- this . containerDiv . appendChild ( codeDiv ) ;
148- var edmode = this . containerDiv . lang ;
148+ this . outerDiv . appendChild ( codeDiv ) ;
149+ var edmode = this . outerDiv . lang ;
149150 if ( edmode === "sql" ) {
150151 edmode = "text/x-sql" ;
151152 } else if ( edmode === "java" ) {
@@ -233,7 +234,9 @@ export class ActiveCode extends RunestoneBase {
233234 }
234235 }
235236
236- async runButtonHander ( ) {
237+ async runButtonHandler ( ) {
238+ // Disable the run button until the run is finished.
239+ this . runButton . disabled = true ;
237240 try {
238241 await this . runProg ( ) ;
239242 } catch ( e ) {
@@ -243,6 +246,8 @@ export class ActiveCode extends RunestoneBase {
243246 this . logCurrentAnswer ( ) ;
244247 }
245248 this . renderFeedback ( ) ;
249+ // The run is finished; re-enable the button.
250+ this . runButton . disabled = false ;
246251 }
247252
248253 createControls ( ) {
@@ -257,7 +262,7 @@ export class ActiveCode extends RunestoneBase {
257262 ctrlDiv . appendChild ( butt ) ;
258263 this . runButton = butt ;
259264 console . log ( "adding click function for run" ) ;
260- this . runButton . onclick = this . runButtonHander . bind ( this ) ;
265+ this . runButton . onclick = this . runButtonHandler . bind ( this ) ;
261266 $ ( butt ) . attr ( "type" , "button" ) ;
262267
263268 if ( this . enabledownload || eBookConfig . downloadsEnabled ) {
@@ -1207,22 +1212,21 @@ Yet another is that there is an internal error. The internal error message is:
12071212 let urDivid = `${ this . divid } _offscreen_unit_results` ;
12081213 let unitFeedback = document . getElementById ( urDivid ) ;
12091214 let tmp = document . body . removeChild ( unitFeedback ) ;
1210- if ( $ ( this . containerDiv ) . find ( `#${ urDivid } ` ) . length > 0 ) {
1211- tmp = $ ( this . containerDiv ) . find ( `#${ urDivid } ` ) [ 0 ] ;
1215+ if ( $ ( this . outerDiv ) . find ( `#${ urDivid } ` ) . length > 0 ) {
1216+ tmp = $ ( this . outerDiv ) . find ( `#${ urDivid } ` ) [ 0 ] ;
12121217 } else {
1213- this . containerDiv . appendChild ( tmp ) ;
1218+ this . outerDiv . appendChild ( tmp ) ;
12141219 }
12151220 $ ( tmp ) . show ( ) ;
12161221 } else {
12171222 let urDivid = this . divid + "_unit_results" ;
12181223 if (
1219- $ ( this . containerDiv ) . find ( `#${ urDivid } ` ) . length == 0 &&
1220- $ ( this . containerDiv ) . find (
1221- `#${ urDivid } _offscreen_unit_results`
1222- ) . length == 0
1224+ $ ( this . outerDiv ) . find ( `#${ urDivid } ` ) . length == 0 &&
1225+ $ ( this . outerDiv ) . find ( `#${ urDivid } _offscreen_unit_results` )
1226+ . length == 0
12231227 ) {
12241228 let urResults = document . getElementById ( urDivid ) ;
1225- this . containerDiv . appendChild ( urResults ) ;
1229+ this . outerDiv . appendChild ( urResults ) ;
12261230 }
12271231 }
12281232 }
@@ -1274,8 +1278,8 @@ Yet another is that there is an internal error. The internal error message is:
12741278 } ) ;
12751279 Sk . divid = this . divid ;
12761280 Sk . logResults = logResults ;
1277- if ( this . graderactive && this . containerDiv . closest ( ".loading" ) ) {
1278- Sk . gradeContainer = this . containerDiv . closest ( ".loading" ) . id ;
1281+ if ( this . graderactive && this . outerDiv . closest ( ".loading" ) ) {
1282+ Sk . gradeContainer = this . outerDiv . closest ( ".loading" ) . id ;
12791283 } else {
12801284 Sk . gradeContainer = this . divid ;
12811285 }
0 commit comments