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

Support html and css in Github Gists #4548

Merged
merged 5 commits into from
Nov 2, 2016
Merged
Show file tree
Hide file tree
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
40 changes: 28 additions & 12 deletions Apps/Sandcastle/CesiumSandcastle.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,16 @@ require({
var currentTab = '';
var newDemo;
var demoHtml = '';
var demoJs = '';
var demoCode = '';
var previousCode = '';
var previousHtml = '';
var runGist = false;
var gistCode;
var gistHtml;
var sandcastleUrl = '';

var defaultHtml = '<style>\n@import url(../templates/bucket.css);\n</style>\n<div id=\"cesiumContainer\" class=\"fullSize\"></div>\n<div id=\"loadingOverlay\"><h1>Loading...</h1></div>\n<div id=\"toolbar\"></div>';

var galleryErrorMsg = document.createElement('span');
galleryErrorMsg.className = 'galleryError';
galleryErrorMsg.style.display = 'none';
Expand Down Expand Up @@ -504,7 +508,7 @@ require({
window.onbeforeunload = function (e) {
var htmlText = (htmlEditor.getValue()).replace(/\s/g, '');
var jsText = (jsEditor.getValue()).replace(/\s/g, '');
if (demoHtml !== htmlText || demoJs !== jsText) {
if (demoHtml !== htmlText || demoCode !== jsText) {
return 'Be sure to save a copy of any important edits before leaving this page.';
}
};
Expand Down Expand Up @@ -695,7 +699,7 @@ require({

if (demo.name === 'Gist Import') {
jsEditor.setValue(gistCode);
htmlEditor.setValue('<style>\n@import url(../templates/bucket.css);\n</style>\n<div id=\"cesiumContainer\" class=\"fullSize\"></div>\n<div id=\"loadingOverlay\"><h1>Loading...</h1></div>\n<div id=\"toolbar\"></div>');
htmlEditor.setValue(gistHtml);
document.title = 'Gist Import - Cesium Sandcastle';
CodeMirror.commands.runCesium(jsEditor);
return;
Expand All @@ -719,17 +723,23 @@ require({
}

var scriptCode = scriptMatch[1];
demoJs = scriptCode.replace(/\s/g, '');
demoCode = scriptCode.replace(/\s/g, '');

if (Cesium.defined(queryObject.gistId)) {
Cesium.loadJsonp('https://api.github.com/gists/' + queryObject.gistId + '?access_token=dd8f755c2e5d9bbb26806bb93eaa2291f2047c60')
.then(function(data) {
var files = data.data.files;
var code = files[Object.keys(files)[0]].content;
var code = files['Cesium-Sandcastle.js'].content;
var htmlFile = files['Cesium-Sandcastle.html'];
var html = Cesium.defined(htmlFile) ? htmlFile.content : defaultHtml; // Use the default html for old gists
jsEditor.setValue(code);
demoJs = code.replace(/\s/g, '');
htmlEditor.setValue(html);
demoCode = code.replace(/\s/g, '');
demoHtml = html.replace(/\s/g, '');
gistCode = code;
gistHtml = html;
previousCode = code;
previousHtml = html;
sandcastleUrl = Cesium.getBaseUri(window.location.href) + '?src=Hello%20World.html&label=Showcases&gist=' + gistId;
CodeMirror.commands.runCesium(jsEditor);
clearRun();
Expand Down Expand Up @@ -885,17 +895,22 @@ require({
var textArea = document.getElementById('link');
textArea.value = '\n\n';
var code = jsEditor.getValue();
if (code === previousCode) {
var html = htmlEditor.getValue();
if (code === previousCode && html === previousHtml) {
textArea.value = sandcastleUrl;
textArea.select();
return;
}
previousCode = code;
previousHtml = html;
var data = {
public : true,
files : {
'Cesium-Sandcastle.js' : {
content : code
},
'Cesium-Sandcastle.html' : {
content : html
}
}
};
Expand All @@ -915,9 +930,10 @@ require({

registry.byId('buttonImport').on('click', function() {
gistId = document.getElementById("gistId").value;
if (gistId.indexOf('/') !== -1) {
var index = gistId.lastIndexOf('/');
gistId = gistId.substring(index + 1);
var gistParameter = '&gist=';
var gistIndex = gistId.indexOf(gistParameter);
if (gistIndex !== -1) {
gistId = gistId.substring(gistIndex + gistParameter.length);
}
window.location.href = Cesium.getBaseUri(window.location.href) + '?src=Hello%20World.html&label=Showcases&gist=' + gistId;
});
Expand All @@ -926,7 +942,7 @@ require({
var htmlText = (htmlEditor.getValue()).replace(/\s/g, '');
var jsText = (jsEditor.getValue()).replace(/\s/g, '');
var confirmChange = true;
if (demoHtml !== htmlText || demoJs !== jsText) {
if (demoHtml !== htmlText || demoCode !== jsText) {
confirmChange = window.confirm('You have unsaved changes. Are you sure you want to navigate away from this demo?');
}
if (confirmChange) {
Expand Down Expand Up @@ -1169,7 +1185,7 @@ require({
var htmlText = (htmlEditor.getValue()).replace(/\s/g, '');
var jsText = (jsEditor.getValue()).replace(/\s/g, '');
var confirmChange = true;
if (demoHtml !== htmlText || demoJs !== jsText) {
if (demoHtml !== htmlText || demoCode !== jsText) {
confirmChange = window.confirm('You have unsaved changes. Are you sure you want to navigate away from this demo?');
}
if (confirmChange) {
Expand Down
7 changes: 7 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
Change Log
==========

### 1.28 - 2016-12-01
* Deprecated
*
* Breaking changes
*
* Added support for saving html and css in Github Gists [#4125](https://github.com/AnalyticalGraphicsInc/cesium/issues/4125)

### 1.27 - 2016-11-01
* Deprecated
* Individual heading, pitch, and roll options to `Transforms.headingPitchRollToFixedFrame` and `Transforms.headingPitchRollQuaternion` have been deprecated and will be removed in 1.30. Pass the new `HeadingPitchRoll` object instead. [#4498](https://github.com/AnalyticalGraphicsInc/cesium/pull/4498)
Expand Down