Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create standalone Sandcastle mode #7097

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 10 additions & 19 deletions Apps/Sandcastle/CesiumSandcastle.js
Original file line number Diff line number Diff line change
@@ -931,7 +931,7 @@ require({
return location.protocol + '//' + location.host + location.pathname;
}

registry.byId('buttonShareDrop').on('click', function() {
function makeCompressedBase64String() {
var code = jsEditor.getValue();
var html = htmlEditor.getValue();

@@ -943,6 +943,12 @@ require({
var base64String = btoa(pako.deflate(jsonString, { raw: true, to: 'string', level: 9 }));
base64String = base64String.replace(/\=+$/, ''); // remove padding

return base64String;
}

registry.byId('buttonShareDrop').on('click', function() {
var base64String = makeCompressedBase64String();

var shareUrlBox = document.getElementById('shareUrl');
shareUrlBox.value = getBaseUrl() + '#c=' + base64String;
shareUrlBox.select();
@@ -1022,25 +1028,10 @@ require({
});

registry.byId('buttonNewWindow').on('click', function() {
var baseHref = window.location.href;
var data = makeCompressedBase64String();
var url = '/Apps/Sandcastle/Standalone/?c=' + data;

//Handle case where demo is in a sub-directory.
var searchLen = window.location.search.length;
if (searchLen > 0) {
baseHref = baseHref.substring(0, baseHref.length - searchLen);
}

var pos = baseHref.lastIndexOf('/');
baseHref = baseHref.substring(0, pos) + '/gallery/';

var html = getDemoHtml();
html = html.replace('<head>', '<head>\n <base href="' + baseHref + '">');
var htmlBlob = new Blob([html], {
'type' : 'text/html;charset=utf-8',
'endings' : 'native'
});
var htmlBlobURL = URL.createObjectURL(htmlBlob);
window.open(htmlBlobURL, '_blank');
window.open(url, '_blank');
window.focus();
});

41 changes: 41 additions & 0 deletions Apps/Sandcastle/views/SandcastleStandalone.liquid
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
<meta name="description" content="Create 3D models using glTF.">
<meta name="cesium-sandcastle-labels" content="Tutorials,Showcases">
<title>Cesium Demo</title>
<script type="text/javascript" src="../Sandcastle-header.js"></script>
<script type="text/javascript" src="../../../ThirdParty/requirejs-2.1.20/require.js"></script>
<script type="text/javascript">
if(typeof require === 'function') {
require.config({
baseUrl : '../../../Source',
waitSeconds : 120
});
}
</script>
</head>
<body class="sandcastle-loading" data-sandcastle-bucket="bucket-requirejs.html">
<style>
@import url(../templates/bucket.css);
</style>
{{html}}
<script id="cesium_sandcastle_script">
function startup(Cesium) {
'use strict';
//Sandcastle_Begin
{{code}}
//Sandcastle_End
Sandcastle.finishedLoading();
}
if (typeof Cesium !== 'undefined') {
startup(Cesium);
} else if (typeof require === 'function') {
require(['Cesium'], startup);
}
</script>
</body>
</html>
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -30,6 +30,9 @@
"email": "cesium-dev@googlegroups.com"
},
"dependencies": {
"atob": "^2.1.2",
"liquidjs": "^6.0.0",
"pako": "^1.0.6",
"requirejs": "^2.3.2"
},
"devDependencies": {
27 changes: 27 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
@@ -6,6 +6,9 @@
var fs = require('fs');
var url = require('url');
var request = require('request');
var Liquid = require('liquidjs');
var atob = require('atob');
var pako = require('pako');

var gzipHeader = Buffer.from('1F8B08', 'hex');

@@ -81,6 +84,30 @@

app.use(express.static(__dirname));

// register liquid engine
var templateEngine = Liquid(); // eslint-disable-line new-cap
app.engine('liquid', templateEngine.express());
app.set('views', './Apps/Sandcastle/views');
app.set('view engine', 'liquid');

app.get('/Apps/Sandcastle/Standalone', function(req, res) {
var base64String = req.url.substr(req.url.indexOf('?c=')+3);

// restore padding
while (base64String.length % 4 !== 0) {
base64String += '=';
}

var jsonString = pako.inflate(atob(base64String), { raw: true, to: 'string' });
jsonString = '["' + jsonString + '"]';
var json = JSON.parse(jsonString);

var code = json[0];
var html = json[1];

res.render('SandcastleStandalone', { code : code, html: html });
});

function getRemoteUrlFromParam(req) {
var remoteUrl = req.params[0];
if (remoteUrl) {