1- export function renderRunestoneComponent ( componentSrc , whereDiv , moreOpts ) {
1+ export async function renderRunestoneComponent ( componentSrc , whereDiv , moreOpts ) {
22 /**
33 * The easy part is adding the componentSrc to the existing div.
44 * The tedious part is calling the right functions to turn the
@@ -19,47 +19,46 @@ export function renderRunestoneComponent(componentSrc, whereDiv, moreOpts) {
1919 "component"
2020 ) ;
2121 // Import the JavaScript for this component before proceeding.
22- runestone_import ( componentKind ) . then ( ( ) => {
23- let opt = { } ;
24- opt . orig = jQuery ( `#${ whereDiv } [data-component]` ) [ 0 ] ;
25- if ( opt . orig ) {
26- opt . lang = $ ( opt . orig ) . data ( "lang" ) ;
27- opt . useRunestoneServices = true ;
28- opt . graderactive = false ;
29- opt . python3 = true ;
30- if ( typeof moreOpts !== "undefined" ) {
31- for ( let key in moreOpts ) {
32- opt [ key ] = moreOpts [ key ] ;
33- }
22+ await runestone_import ( componentKind ) ;
23+ let opt = { } ;
24+ opt . orig = jQuery ( `#${ whereDiv } [data-component]` ) [ 0 ] ;
25+ if ( opt . orig ) {
26+ opt . lang = $ ( opt . orig ) . data ( "lang" ) ;
27+ opt . useRunestoneServices = true ;
28+ opt . graderactive = false ;
29+ opt . python3 = true ;
30+ if ( typeof moreOpts !== "undefined" ) {
31+ for ( let key in moreOpts ) {
32+ opt [ key ] = moreOpts [ key ] ;
3433 }
3534 }
35+ }
3636
37- if ( typeof component_factory === "undefined" ) {
38- alert (
39- "Error: Missing the component factory! Clear you browser cache."
37+ if ( typeof component_factory === "undefined" ) {
38+ alert (
39+ "Error: Missing the component factory! Clear you browser cache."
40+ ) ;
41+ } else {
42+ if (
43+ ! window . component_factory [ componentKind ] &&
44+ ! jQuery ( `#${ whereDiv } ` ) . html ( )
45+ ) {
46+ jQuery ( `#${ whereDiv } ` ) . html (
47+ `<p>Preview not available for ${ componentKind } </p>`
4048 ) ;
4149 } else {
42- if (
43- ! window . component_factory [ componentKind ] &&
44- ! jQuery ( `#${ whereDiv } ` ) . html ( )
45- ) {
46- jQuery ( `#${ whereDiv } ` ) . html (
47- `<p>Preview not available for ${ componentKind } </p>`
48- ) ;
49- } else {
50- let res = window . component_factory [ componentKind ] ( opt ) ;
51- if ( componentKind === "activecode" ) {
52- if ( moreOpts . multiGrader ) {
53- window . edList [
54- `${ moreOpts . gradingContainer } ${ res . divid } `
55- ] = res ;
56- } else {
57- window . edList [ res . divid ] = res ;
58- }
50+ let res = window . component_factory [ componentKind ] ( opt ) ;
51+ if ( componentKind === "activecode" ) {
52+ if ( moreOpts . multiGrader ) {
53+ window . edList [
54+ `${ moreOpts . gradingContainer } ${ res . divid } `
55+ ] = res ;
56+ } else {
57+ window . edList [ res . divid ] = res ;
5958 }
6059 }
6160 }
62- } ) ;
61+ }
6362}
6463
6564export function createTimedComponent ( componentSrc , moreOpts ) {
0 commit comments