-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7250 from OmarShehata/standlone-sandcastle
Create Sandcastle Standalone Mode
- Loading branch information
Showing
8 changed files
with
185 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
(function() { | ||
'use strict'; | ||
var pako = window.pako; | ||
|
||
window.embedInSandcastleTemplate = function(code, addExtraLine) { | ||
return 'function startup(Cesium) {\n' + | ||
' \'use strict\';\n' + | ||
'//Sandcastle_Begin\n' + | ||
(addExtraLine ? '\n' : '') + | ||
code + | ||
'//Sandcastle_End\n' + | ||
' Sandcastle.finishedLoading();\n' + | ||
'}\n' + | ||
'if (typeof Cesium !== \'undefined\') {\n' + | ||
' startup(Cesium);\n' + | ||
'} else if (typeof require === \'function\') {\n' + | ||
' require([\'Cesium\'], startup);\n' + | ||
'}\n'; | ||
}; | ||
window.decodeBase64Data = function(base64String) { | ||
// data stored in the hash as: | ||
// Base64 encoded, raw DEFLATE compressed JSON array where index 0 is code, index 1 is html | ||
// restore padding | ||
while (base64String.length % 4 !== 0) { | ||
base64String += '='; | ||
} | ||
var jsonString = pako.inflate(atob(base64String), { raw: true, to: 'string' }); | ||
// we save a few bytes by omitting the leading [" and trailing "] since they are always the same | ||
jsonString = '["' + jsonString + '"]'; | ||
var json = JSON.parse(jsonString); | ||
// index 0 is code, index 1 is html | ||
var code = json[0]; | ||
var html = json[1]; | ||
var baseHref = json[2]; | ||
return { | ||
code : code, | ||
html : html, | ||
baseHref : baseHref | ||
}; | ||
}; | ||
}()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<!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"> | ||
<title>Cesium Demo</title> | ||
<script type="text/javascript" src="Sandcastle-header.js"></script> | ||
<script type="text/javascript" src="Sandcastle-client.js"></script> | ||
<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> | ||
</head> | ||
<body class="sandcastle-loading" data-sandcastle-bucket="bucket-requirejs.html"> | ||
<script type="text/javascript"> | ||
/*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; | ||
} | ||
|
||
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 = window.Cesium.defined; | ||
var code; | ||
|
||
if (defined(window.sandcastleData)) { | ||
var base64String = window.location.hash.substr(3); | ||
var data = window.sandcastleData; | ||
var html = data.html; | ||
code = data.code; | ||
var isIE11 = !!window.MSInputMethodContext && !!document.documentMode; | ||
if (isIE11) { | ||
html = html.replace('../templates', 'templates'); | ||
} | ||
|
||
// Add the HTML content | ||
var htmlElement = document.createElement('div'); | ||
htmlElement.innerHTML = html; | ||
document.body.appendChild(htmlElement); | ||
|
||
// Add the JavaScript | ||
var scriptElement = document.createElement('script'); | ||
var isFirefox = navigator.userAgent.indexOf('Firefox/') >= 0; | ||
document.head.appendChild(scriptElement); | ||
scriptElement.innerHTML = window.embedInSandcastleTemplate(code, isFirefox); | ||
} | ||
}); | ||
|
||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,4 +63,4 @@ body { | |
padding: 4px; | ||
border: 1px solid #444; | ||
border-radius: 4px; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.