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

Commit 22a3996

Browse files
committed
Fix: enable scratchAC even on pages with no activecode
1 parent 3c01ace commit 22a3996

3 files changed

Lines changed: 27 additions & 4 deletions

File tree

runestone/common/js/renderComponent.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ export async function renderRunestoneComponent(componentSrc, whereDiv, moreOpts)
66
* The tedious part is calling the right functions to turn the
77
* source into the actual component.
88
*/
9+
if (!componentSrc) {
10+
jQuery(`#${whereDiv}`).html(`<p>Sorry, no source is available for preview.</p>`);
11+
return;
12+
}
913
let patt = /..\/_images/g;
1014
componentSrc = componentSrc.replace(
1115
patt,
@@ -38,7 +42,7 @@ export async function renderRunestoneComponent(componentSrc, whereDiv, moreOpts)
3842

3943
if (typeof component_factory === "undefined") {
4044
alert(
41-
"Error: Missing the component factory! Clear you browser cache."
45+
"Error: Missing the component factory!"
4246
);
4347
} else {
4448
if (

runestone/common/project_template/_templates/plugin_layouts/sphinx_bootstrap/layout.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@
173173
<!-- <li id="scratch_ac_link"><a href="javascript:ACFactory.toggleScratchActivecode()">Scratch ActiveCode</a></li> -->
174174

175175
<!-- <li class="dropdown"> -->
176-
<li id="scratch_ac_link" class="dropdown"><a href="javascript:ACFactory.toggleScratchActivecode()">
176+
<li id="scratch_ac_link" class="dropdown"><a href="javascript:runestoneComponents.popupScratchAC()">
177177
<i class="glyphicon glyphicon-pencil" style="opacity:0.9;"><span aria-label="Scratch Activecode" class="visuallyhidden">Scratch Activecode</span></i></a></li>
178178
<!-- </li> -->
179179

@@ -274,7 +274,6 @@
274274
eBookConfig.proxyuri_files = '{{proxy_uri_files}}';
275275
eBookConfig.enable_chatcodes = {{enable_chatcodes}} ? {{ enable_chatcodes }} : false;
276276

277-
278277
</script>
279278

280279
<!-- Ad Serving Headers Only serve ads to Anonymous Users -->

webpack.index.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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.
122141
const 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;
131150
rc.runestone_auto_import = runestone_auto_import;
132151
rc.getSwitch = getSwitch;
133152
rc.switchTheme = switchTheme;
153+
rc.popupScratchAC = popupScratchAC;
134154
window.runestoneComponents = rc;

0 commit comments

Comments
 (0)