Skip to content

Commit

Permalink
Split out initialization script in xhtml build, see #954
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisklus committed Aug 7, 2020
1 parent 8ed4cf2 commit 381be90
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
3 changes: 2 additions & 1 deletion js/grunt/buildRunnable.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,8 @@ module.exports = async function( repo, minifyOptions, instrument, allHTML, brand
brand: brand,
stringMap: stringMap,
htmlHeader: htmlHeader,
scripts: [ xhtmlInitializationScript, ...productionScripts ]
initializationScript: xhtmlInitializationScript,
scripts: productionScripts
} );

// dependencies.json
Expand Down
5 changes: 5 additions & 0 deletions js/grunt/packageXHTML.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ module.exports = function( xhtmlDir, config ) {
repo, // {string}
brand, // {string}
stringMap, // {Object}, map[ locale ][ stringKey ] => {string}
initializationScript, // {string}
scripts, // {Array.<string>}
htmlHeader // {string}
} = config;
Expand All @@ -41,14 +42,18 @@ module.exports = function( xhtmlDir, config ) {

const localizedTitle = stringMap[ ChipperConstants.FALLBACK_LOCALE ][ getTitleStringKey( repo ) ];

const initializationScriptFilename = `${repo}_initialization_${brand}.js`;

const script = scripts.join( '\n' );
const scriptFilename = `${repo}_${brand}.js`;

const xhtml = ChipperStringUtils.replacePlaceholders( grunt.file.read( '../chipper/templates/sim.xhtml' ), {
PHET_SIM_TITLE: encoder.htmlEncode( localizedTitle ),
PHET_HTML_HEADER: htmlHeader,
PHET_INITIALIZATION_SCRIPT: `<script type="text/javascript" src="${initializationScriptFilename}" charset="utf-8"></script>`,
PHET_SIM_SCRIPTS: `<script type="text/javascript" src="${scriptFilename}" charset="utf-8"></script>`
} );
grunt.file.write( `${xhtmlDir}/${repo}_all${brand === 'phet' ? '' : `_${brand}`}.xhtml`, xhtml );
grunt.file.write( `${xhtmlDir}/${initializationScriptFilename}`, initializationScript );
grunt.file.write( `${xhtmlDir}/${scriptFilename}`, script );
};
1 change: 1 addition & 0 deletions templates/sim.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
-->
<!-- body is only made black for the loading phase so that the splash screen is black -->
<body style="background-color:black;">
{{PHET_INITIALIZATION_SCRIPT}}
{{PHET_SIM_SCRIPTS}}
</body>
</html>

0 comments on commit 381be90

Please sign in to comment.