-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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 Sandcastle Standalone Mode #7250
Merged
Merged
Changes from 6 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
887da68
Create static standalone sandcastle mode
cdd3350
Use standalone mode for open in new window
73534fe
Simplify and refactor standalone sandcastle
7db0785
Eslint fix
3e710ed
Fix path
OmarShehata a678381
Wait for CSS to load
OmarShehata 0914c4f
Make sure open in new window works for development examples
1871b93
Adjust relative paths
emackey 880ad06
Merge pull request #2 from emackey/standalone-patch-1
OmarShehata ca39c8d
Fix standalone with built version
9711de3
Make sure standalone works in built/ie11
e034277
Eslint
9ed3838
Resolve conflict
f90f1c7
Compile bucket.css for Sandcastle
d73a373
Revert mutation observer fix
405ae66
Use requirejs in Sandcastle-helpers
25d82eb
No need to wait for CSS to load anymore
bbc7df6
Make it work for built Sandcastle
d89ffbe
lint
7f5398b
Clean generated bucket css
388d463
Make sure standalone mode works when served from subdirectory
e7685da
Merge branch 'master' into standlone-sandcastle
3a4a4a9
Update changes
ec62839
Merge branch 'master' into standlone-sandcastle
emackey File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/*global pako*/ | ||
(function() { | ||
'use strict'; | ||
|
||
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]; | ||
|
||
return { | ||
code : code, | ||
html : 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
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,88 @@ | ||
<!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="ThirdParty/pako.min.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 : '../../', | ||
waitSeconds : 120 | ||
}); | ||
} | ||
</script> | ||
</head> | ||
<body class="sandcastle-loading" data-sandcastle-bucket="bucket-requirejs.html"> | ||
<script type="text/javascript" src="Sandcastle-client.js"></script> | ||
<script type="text/javascript" src="Sandcastle-helpers.js"></script> | ||
<script type="text/javascript"> | ||
/*global pako,decodeBase64Data,embedInSandcastleTemplate */ | ||
if (typeof require === 'function') { | ||
require([ | ||
'Source/Cesium' | ||
], function( | ||
Cesium) { | ||
'use strict'; | ||
window.Cesium = Cesium; | ||
loadDemoFromUrl(); | ||
}); | ||
} else { | ||
loadDemoFromUrl(); | ||
} | ||
|
||
function loadDemoFromUrl() { | ||
'use strict'; | ||
// The helper functions script needs this. | ||
window.pako = pako; | ||
var defined = Cesium.defined; | ||
var loaderElement; | ||
var frameDelay = 30; | ||
var code; | ||
|
||
function update() { | ||
var width = getComputedStyle(loaderElement).getPropertyValue('width'); | ||
var done = false; | ||
if (width === '12px') { | ||
frameDelay --; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. spacing |
||
if (frameDelay <= 0) { | ||
done = true; | ||
var scriptElement = document.createElement('script'); | ||
var isFirefox = navigator.userAgent.indexOf('Firefox/') >= 0; | ||
document.head.appendChild(scriptElement); | ||
scriptElement.innerHTML = embedInSandcastleTemplate(code, isFirefox); | ||
} | ||
} | ||
|
||
if (!done) { | ||
requestAnimationFrame(update); | ||
} | ||
} | ||
|
||
if (window.location.hash.indexOf('#c=') === 0) { | ||
var base64String = window.location.hash.substr(3); | ||
var data = decodeBase64Data(base64String); | ||
var html = data.html; | ||
code = data.code; | ||
// Replace CSS URL since standalone is one level up from the usual bucket.html | ||
html = html.replace('../templates', 'templates'); | ||
html += '<div id="loader"></div>'; | ||
html += '<style>#loader { width : 12px }</style>'; | ||
|
||
// Add the HTML content | ||
var htmlElement = document.createElement('div'); | ||
htmlElement.innerHTML = html; | ||
document.body.appendChild(htmlElement); | ||
// Add the JavaScript only when CSS has loaded | ||
loaderElement = document.querySelector("#loader"); | ||
emackey marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
requestAnimationFrame(update); | ||
} | ||
} | ||
</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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why doesn't sandcastle-helpers use AMD syntax and include pako itself?