Skip to content

Commit

Permalink
Make sure standalone mode works when served from subdirectory
Browse files Browse the repository at this point in the history
  • Loading branch information
Omar Shehata committed Jan 4, 2019
1 parent 7f5398b commit 388d463
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 30 deletions.
59 changes: 30 additions & 29 deletions Apps/Sandcastle/standalone.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,52 +10,52 @@
<script type="text/javascript" src="ThirdParty/pako.min.js"></script>
<script type="text/javascript" src="../../ThirdParty/requirejs-2.1.20/require.js"></script>
<script type="text/javascript" src="Sandcastle-helpers.js"></script>
<script type="text/javascript">
if(typeof require === 'function') {
require.config({
baseUrl : '../../../',
waitSeconds : 120
});
}
</script>
</head>
<body class="sandcastle-loading" data-sandcastle-bucket="bucket-requirejs.html">
<script type="text/javascript">
/*global pako */
if (typeof require === 'function') {
require([
'Source/Cesium'
], function(
Cesium) {
'use strict';
window.Cesium = Cesium;
loadDemoFromUrl();
});
} else {
loadDemoFromUrl();
/*global pako */
if (window.location.hash.indexOf('#c=') === 0) {
var base64String = window.location.hash.substr(3);
var data = window.decodeBase64Data(base64String);
//Handle case where demo is in a sub-directory by modifying
//the HTML to add a base href.
document.head.innerHTML = document.head.innerHTML + '<base href="' + data.baseHref + '" />';
window.sandcastleData = data;
}

function loadDemoFromUrl() {
'use strict';
require({
baseUrl : '../../../',
waitSeconds : 120,
packages: [{
name: 'CesiumUnminified',
location: '../Build/CesiumUnminified',
main: 'Cesium'
}]
},[
'Source/Cesium'
], function(
Cesium) {
'use strict';
if (window.Cesium === undefined) {
window.Cesium = Cesium;
}

// The helper functions script needs this.
window.pako = pako;

var defined = Cesium.defined;
var defined = window.Cesium.defined;
var code;

if (window.location.hash.indexOf('#c=') === 0) {
if (defined(window.sandcastleData)) {
var base64String = window.location.hash.substr(3);
var data = window.decodeBase64Data(base64String);
var data = window.sandcastleData;
var html = data.html;
code = data.code;
var isIE11 = !!window.MSInputMethodContext && !!document.documentMode;
if (isIE11) {
html = html.replace('../templates', 'templates');
}

//Handle case where demo is in a sub-directory by modifying
//the HTML to add a base href.
document.head.innerHTML = document.head.innerHTML + '<base href="' + data.baseHref + '" />';
// Add the HTML content
var htmlElement = document.createElement('div');
htmlElement.innerHTML = html;
Expand All @@ -67,7 +67,8 @@
document.head.appendChild(scriptElement);
scriptElement.innerHTML = window.embedInSandcastleTemplate(code, isFirefox);
}
}
});

</script>
</body>
</html>
3 changes: 2 additions & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -1251,7 +1251,8 @@ function buildSandcastle() {
var standaloneStream = gulp.src([
'Apps/Sandcastle/standalone.html'
])
.pipe(gulpReplace('../../ThirdParty/requirejs-2.1.20/require.js', '/Build/CesiumUnminified/Cesium.js'))
.pipe(gulpReplace('../../ThirdParty/requirejs-2.1.20/require.js', '../../../ThirdParty/requirejs-2.1.20/require.js'))
.pipe(gulpReplace('Source/Cesium', 'CesiumUnminified'))
.pipe(gulp.dest('Build/Apps/Sandcastle'));

return streamToPromise(mergeStream(appStream, imageStream, standaloneStream));
Expand Down

0 comments on commit 388d463

Please sign in to comment.