@@ -114,10 +114,29 @@ export function runestone_auto_import() {
114114$ ( document ) . ready ( runestone_auto_import ) ;
115115
116116// Provide a function to import one specific Runestone component.
117- export function runestone_import ( component_name ) {
117+ // the import function inside module_map is async -- runestone_import
118+ // should be awaited when necessary to ensure the import completes
119+ export async function runestone_import ( component_name ) {
118120 return module_map [ component_name ] ( ) ;
119121}
120122
123+ async function popupScratchAC ( ) {
124+ // load the activecode bundle
125+ await runestone_import ( "activecode" ) ;
126+ // scratchDiv will be defined if we have already created a scratch
127+ // activecode. If its not defined then we need to get it ready to toggle
128+ if ( ! eBookConfig . scratchDiv ) {
129+ window . ACFactory . createScratchActivecode ( ) ;
130+ let divid = eBookConfig . scratchDiv
131+ window . edList [ divid ] = ACFactory . createActiveCode ( $ ( `#${ divid } ` ) [ 0 ] ,
132+ eBookConfig . acDefaultLanguage ) ;
133+ if ( eBookConfig . isLoggedIn ) {
134+ window . edList [ divid ] . enableSaveLoad ( ) ;
135+ }
136+ }
137+ window . ACFactory . toggleScratchActivecode ( ) ;
138+ }
139+
121140// Set the directory containing this script as the `path <https://webpack.js.org/guides/public-path/#on-the-fly>`_ for all webpacked scripts.
122141const script_src = document . currentScript . src ;
123142__webpack_public_path__ = script_src . substring ( 0 , script_src . lastIndexOf ( '/' ) + 1 ) ;
@@ -131,4 +150,5 @@ rc.runestone_import = runestone_import;
131150rc . runestone_auto_import = runestone_auto_import ;
132151rc . getSwitch = getSwitch ;
133152rc . switchTheme = switchTheme ;
153+ rc . popupScratchAC = popupScratchAC ;
134154window . runestoneComponents = rc ;
0 commit comments