@@ -12,6 +12,15 @@ function getPrefix(url) {
1212 return prefix ;
1313}
1414
15+ const lessonHelperScriptRE = / < s c r i p t s r c = " [ ^ " ] + l e s s o n s - h e l p e r \. j s " > < \/ s c r i p t > / ;
16+ const webglDebugHelperScriptRE = / < s c r i p t s r c = " [ ^ " ] + w e b g l - d e b u g - h e l p e r \. j s " > < \/ s c r i p t > / ;
17+
18+ function fixHTMLForCodeSite ( html ) {
19+ html = html . replace ( lessonHelperScriptRE , '' ) ;
20+ html = html . replace ( webglDebugHelperScriptRE , '' ) ;
21+ return html ;
22+ }
23+
1524/**
1625 * Fix any local URLs into fully qualified urls.
1726 *
@@ -141,14 +150,36 @@ function requestCORSIfNotSameOrigin(img, url) {
141150 return js ;
142151}
143152
153+ function prepHTML ( source , prefix ) {
154+ source = source . replace ( '<head>' , `<head>
155+ <link rel="stylesheet" href="${ prefix } /resources/lesson-helper.css" type="text/css">
156+ <script match="false">self.lessonSettings = ${ JSON . stringify ( lessonSettings ) } </script>` ) ;
157+
158+ source = source . replace ( '</head>' , `<script src="${ prefix } /resources/webgl-debug-helper.js"></script>
159+ <script src="${ prefix } /resources/lessons-helper.js"></script>
160+ </head>` ) ;
161+ return source ;
162+ }
163+
164+ function getWorkerPreamble ( scriptInfo ) {
165+ return `self.lessonSettings = ${ JSON . stringify ( lessonSettings ) } ;
166+ import '${ dirname ( scriptInfo . fqURL ) } /resources/webgl-debug-helper.js';
167+ import '${ dirname ( scriptInfo . fqURL ) } /resources/lessons-worker-helper.js';` ;
168+ }
169+
170+ const lessonSettings = {
171+ glDebug : true ,
172+ } ;
173+
144174window . lessonEditorSettings = {
145175 extraHTMLParsing,
146176 fixSourceLinks,
147177 fixJSForCodeSite,
178+ fixHTMLForCodeSite,
148179 runOnResize : true ,
149- lessonSettings : {
150- glDebug : true ,
151- } ,
180+ lessonSettings,
181+ prepHTML ,
182+ getWorkerPreamble ,
152183 tags : [ 'webgl' , 'webglfundamentals.org' ] ,
153184 name : 'WebGLFundamentals' ,
154185 icon : '/webgl/lessons/resources/webglfundamentals-icon-256.png' ,
0 commit comments