From 887da68d42fe17682b2e2ea1ec9c2b7f8d66610f Mon Sep 17 00:00:00 2001 From: Omar Shehata Date: Thu, 8 Nov 2018 12:11:26 -0500 Subject: [PATCH 01/20] Create static standalone sandcastle mode --- Apps/Sandcastle/standalone.html | 174 ++++++++++++++++++++++++++++++++ 1 file changed, 174 insertions(+) create mode 100644 Apps/Sandcastle/standalone.html diff --git a/Apps/Sandcastle/standalone.html b/Apps/Sandcastle/standalone.html new file mode 100644 index 00000000000..51091afa153 --- /dev/null +++ b/Apps/Sandcastle/standalone.html @@ -0,0 +1,174 @@ + + + + + + + Cesium Sandcastle + + + + + + + + + + + + + + + + + + + + + + + +
Loading...
+
+
+
+
+ New +
+ +
+ Run (F8) +
+ +
+ Suggest (Ctrl-Space) +
+ +
+ Info + +
+ +
+ Save As + +
+ +
+ Share + +
+ +
+ Import Gist + +
+ + +
+ Open in New Window +
+ +
+ View as Thumbnail +
+ + +
+
+ +
+ +
+
+ +
+
+
+
+ +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+ + From cdd3350c170402e264717f6ebc9d962ea34b32c5 Mon Sep 17 00:00:00 2001 From: Omar Shehata Date: Thu, 8 Nov 2018 12:48:22 -0500 Subject: [PATCH 02/20] Use standalone mode for open in new window --- Apps/Sandcastle/CesiumSandcastle.js | 32 +++++++++++++---------------- 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/Apps/Sandcastle/CesiumSandcastle.js b/Apps/Sandcastle/CesiumSandcastle.js index 030689d76fb..37a7413ba14 100644 --- a/Apps/Sandcastle/CesiumSandcastle.js +++ b/Apps/Sandcastle/CesiumSandcastle.js @@ -953,7 +953,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(); @@ -965,6 +965,15 @@ 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 code = jsEditor.getValue(); + var html = htmlEditor.getValue(); + + var base64String = makeCompressedBase64String(); + var shareUrlBox = document.getElementById('shareUrl'); shareUrlBox.value = getBaseUrl() + '#c=' + base64String; shareUrlBox.select(); @@ -1045,24 +1054,11 @@ require({ registry.byId('buttonNewWindow').on('click', function() { var baseHref = window.location.href; + var data = makeCompressedBase64String(); + var url = getBaseUrl(); + url = url.replace('index.html','') + 'standalone.html#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('', '\n '); - 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(); }); From 73534fe01507e546d8b1beee24213cc356e893d1 Mon Sep 17 00:00:00 2001 From: Omar Shehata Date: Wed, 14 Nov 2018 13:42:17 -0500 Subject: [PATCH 03/20] Simplify and refactor standalone sandcastle --- Apps/Sandcastle/CesiumSandcastle.js | 43 ++---- Apps/Sandcastle/Sandcastle-helpers.js | 40 +++++ Apps/Sandcastle/index.html | 1 + Apps/Sandcastle/standalone.html | 214 +++++++------------------- gulpfile.js | 9 +- 5 files changed, 113 insertions(+), 194 deletions(-) create mode 100644 Apps/Sandcastle/Sandcastle-helpers.js diff --git a/Apps/Sandcastle/CesiumSandcastle.js b/Apps/Sandcastle/CesiumSandcastle.js index 37a7413ba14..84a4bc4d742 100644 --- a/Apps/Sandcastle/CesiumSandcastle.js +++ b/Apps/Sandcastle/CesiumSandcastle.js @@ -1,4 +1,5 @@ -/*global require,Blob,JSHINT*/ +/*global require,Blob,JSHINT */ +/*global decodeBase64Data, embedInSandcastleTemplate */ /*global gallery_demos, has_new_gallery_demos, hello_world_index*/// defined in gallery/gallery-index.js, created by build /*global sandcastleJsHintOptions*/// defined by jsHintOptions.js, created by build require({ @@ -110,6 +111,8 @@ require({ if (!defined(window.Cesium)) { window.Cesium = Cesium; } + // Used by Sandcastle-helpers.js + window.pako = pako; parser.parse(); @@ -383,7 +386,7 @@ require({ // make a copy of the options, JSHint modifies the object it's given var options = JSON.parse(JSON.stringify(sandcastleJsHintOptions)); /*eslint-disable new-cap*/ - if (!JSHINT(getScriptFromEditor(false), options)) { + if (!JSHINT(embedInSandcastleTemplate(jsEditor.getValue(), false), options)) { var hints = JSHINT.errors; for (i = 0, len = hints.length; i < len; ++i) { var hint = hints[i]; @@ -540,22 +543,6 @@ require({ } }); - function getScriptFromEditor(addExtraLine) { - return 'function startup(Cesium) {\n' + - ' \'use strict\';\n' + - '//Sandcastle_Begin\n' + - (addExtraLine ? '\n' : '') + - jsEditor.getValue() + - '//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'; - } - var scriptCodeRegex = /\/\/Sandcastle_Begin\s*([\s\S]*)\/\/Sandcastle_End/; function activateBucketScripts(bucketDoc) { @@ -620,7 +607,7 @@ require({ // Firefox line numbers are zero-based, not one-based. var isFirefox = navigator.userAgent.indexOf('Firefox/') >= 0; - element.textContent = getScriptFromEditor(isFirefox); + element.textContent = embedInSandcastleTemplate(jsEditor.getValue(), isFirefox); bucketDoc.body.appendChild(element); } }; @@ -775,20 +762,10 @@ require({ applyLoadedDemo(code, html); } else if (window.location.hash.indexOf('#c=') === 0) { - // data stored in the hash as: - // Base64 encoded, raw DEFLATE compressed JSON array where index 0 is code, index 1 is html var base64String = window.location.hash.substr(3); - // 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 + '"]'; - json = JSON.parse(jsonString); - // index 0 is code, index 1 is html - code = json[0]; - html = json[1]; + var data = decodeBase64Data(base64String); + code = data.code; + html = data.html; applyLoadedDemo(code, html); } else { @@ -1028,7 +1005,7 @@ require({ return local.headers + '\n' + htmlEditor.getValue() + '\n' + '\n' + '\n'; diff --git a/Apps/Sandcastle/Sandcastle-helpers.js b/Apps/Sandcastle/Sandcastle-helpers.js new file mode 100644 index 00000000000..60fa2172647 --- /dev/null +++ b/Apps/Sandcastle/Sandcastle-helpers.js @@ -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 + }; + }; + }()); diff --git a/Apps/Sandcastle/index.html b/Apps/Sandcastle/index.html index 0dcaac49fc9..9ddfe6faf13 100644 --- a/Apps/Sandcastle/index.html +++ b/Apps/Sandcastle/index.html @@ -20,6 +20,7 @@ + diff --git a/Apps/Sandcastle/standalone.html b/Apps/Sandcastle/standalone.html index 51091afa153..7335294350f 100644 --- a/Apps/Sandcastle/standalone.html +++ b/Apps/Sandcastle/standalone.html @@ -4,171 +4,65 @@ - Cesium Sandcastle - - - - - +function loadDemoFromUrl() { + // The helper functions script needs this. + window.pako = pako; + var defined = Cesium.defined; - + if (window.location.hash.indexOf('#c=') === 0) { + var base64String = window.location.hash.substr(3); + var data = decodeBase64Data(base64String); + var html = data.html; + var code = data.code; + // Replace CSS URL since standalone is one level up from the usual bucket.html + html = html.replace('../templates', 'templates'); - - - - - - - - - - - - - - - -
Loading...
-
-
-
-
- New -
- -
- Run (F8) -
- -
- Suggest (Ctrl-Space) -
- -
- Info - -
- -
- Save As - -
- -
- Share - -
- -
- Import Gist - -
- - -
- Open in New Window -
- -
- View as Thumbnail -
- - -
-
- -
- -
-
- -
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+ // Add the HTML content + var htmlElement = document.createElement('div'); + htmlElement.innerHTML = html; + document.body.appendChild(htmlElement); + + // Wait for that to load, then add the script + // the window load event will re-fire since we've altered the DOM. + window.addEventListener("load", function(event) { + var scriptElement = document.createElement('script'); + var isFirefox = navigator.userAgent.indexOf('Firefox/') >= 0; + document.head.appendChild(scriptElement); + scriptElement.innerHTML = embedInSandcastleTemplate(code, isFirefox); + }); + } +} -
-
-
-
+ diff --git a/gulpfile.js b/gulpfile.js index b203550ea93..abe37b49c10 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1204,6 +1204,7 @@ var sandcastleJsHintOptions = ' + JSON.stringify(primary, null, 4) + ';\n'; function buildSandcastle() { var appStream = gulp.src([ 'Apps/Sandcastle/**', + '!Apps/Sandcastle/standalone.html', '!Apps/Sandcastle/images/**', '!Apps/Sandcastle/gallery/**.jpg' ]) @@ -1227,7 +1228,13 @@ function buildSandcastle() { }) .pipe(gulp.dest('Build/Apps/Sandcastle')); - return streamToPromise(eventStream.merge(appStream, imageStream)); + var standaloneStream = gulp.src([ + 'Apps/Sandcastle/standalone.html' + ]) + .pipe(gulpReplace('../../../ThirdParty/requirejs-2.1.20/require.js', '../../CesiumUnminified/Cesium.js')) + .pipe(gulp.dest('Build/Apps/Sandcastle')); + + return streamToPromise(eventStream.merge(appStream, imageStream, standaloneStream)); } function buildCesiumViewer() { From 7db0785ac38d53ca6d696c6363bfa63a08284766 Mon Sep 17 00:00:00 2001 From: Omar Shehata Date: Thu, 15 Nov 2018 10:34:11 -0500 Subject: [PATCH 04/20] Eslint fix --- Apps/Sandcastle/standalone.html | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/Apps/Sandcastle/standalone.html b/Apps/Sandcastle/standalone.html index 7335294350f..98903971de2 100644 --- a/Apps/Sandcastle/standalone.html +++ b/Apps/Sandcastle/standalone.html @@ -21,12 +21,13 @@ From 3e710ed9a05e2e604f02f2d1bd24213a4a5558b1 Mon Sep 17 00:00:00 2001 From: Omar Shehata Date: Fri, 16 Nov 2018 17:02:21 -0500 Subject: [PATCH 05/20] Fix path --- Apps/Sandcastle/standalone.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Apps/Sandcastle/standalone.html b/Apps/Sandcastle/standalone.html index 98903971de2..146dca12b04 100644 --- a/Apps/Sandcastle/standalone.html +++ b/Apps/Sandcastle/standalone.html @@ -7,7 +7,7 @@ Cesium Demo - + From 0914c4f84c9fe11815eec3783591f5d5120ae1d4 Mon Sep 17 00:00:00 2001 From: Omar Shehata Date: Mon, 19 Nov 2018 14:14:07 -0500 Subject: [PATCH 07/20] Make sure open in new window works for development examples --- Apps/Sandcastle/CesiumSandcastle.js | 20 +++++++++++++------- Apps/Sandcastle/standalone.html | 17 ++++++++++++++--- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/Apps/Sandcastle/CesiumSandcastle.js b/Apps/Sandcastle/CesiumSandcastle.js index 84a4bc4d742..69a4e3f8fda 100644 --- a/Apps/Sandcastle/CesiumSandcastle.js +++ b/Apps/Sandcastle/CesiumSandcastle.js @@ -930,10 +930,7 @@ require({ return location.protocol + '//' + location.host + location.pathname; } - function makeCompressedBase64String() { - var code = jsEditor.getValue(); - var html = htmlEditor.getValue(); - + function makeCompressedBase64String(html, code) { // data stored in the hash as: // Base64 encoded, raw DEFLATE compressed JSON array where index 0 is code, index 1 is html var jsonString = JSON.stringify([code, html]); @@ -949,7 +946,7 @@ require({ var code = jsEditor.getValue(); var html = htmlEditor.getValue(); - var base64String = makeCompressedBase64String(); + var base64String = makeCompressedBase64String(html, code); var shareUrlBox = document.getElementById('shareUrl'); shareUrlBox.value = getBaseUrl() + '#c=' + base64String; @@ -1030,10 +1027,19 @@ require({ }); registry.byId('buttonNewWindow').on('click', function() { + //Handle case where demo is in a sub-directory by modifying + //the demo's HTML to add a base href. var baseHref = window.location.href; - var data = makeCompressedBase64String(); + 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 data = makeCompressedBase64String(htmlEditor.getValue(), jsEditor.getValue()); var url = getBaseUrl(); - url = url.replace('index.html','') + 'standalone.html#c=' + data; + url = url.replace('index.html','') + 'standalone.html' + '?gallery=' + baseHref + '#c=' + data; window.open(url, '_blank'); window.focus(); diff --git a/Apps/Sandcastle/standalone.html b/Apps/Sandcastle/standalone.html index c965d6cf4d4..67ab11b1c39 100644 --- a/Apps/Sandcastle/standalone.html +++ b/Apps/Sandcastle/standalone.html @@ -10,8 +10,9 @@ + + - - - - + From bbc7df6eb08d6f586067762aebfc68481b70bd87 Mon Sep 17 00:00:00 2001 From: Omar Shehata Date: Fri, 14 Dec 2018 15:29:46 -0500 Subject: [PATCH 16/20] Make it work for built Sandcastle --- Apps/Sandcastle/CesiumSandcastle.js | 2 ++ Apps/Sandcastle/Sandcastle-helpers.js | 14 +++----------- Apps/Sandcastle/standalone.html | 3 +++ Apps/Sandcastle/templates/bucketRaw.css | 1 - 4 files changed, 8 insertions(+), 12 deletions(-) diff --git a/Apps/Sandcastle/CesiumSandcastle.js b/Apps/Sandcastle/CesiumSandcastle.js index bd85e0d2f01..f59aa4943fb 100644 --- a/Apps/Sandcastle/CesiumSandcastle.js +++ b/Apps/Sandcastle/CesiumSandcastle.js @@ -104,6 +104,8 @@ require({ pako) { 'use strict'; + window.pako = pako; // For Sandcastle-helpers. + // attach clipboard handling to our Copy button var clipboardjs = new ClipboardJS('.copyButton'); diff --git a/Apps/Sandcastle/Sandcastle-helpers.js b/Apps/Sandcastle/Sandcastle-helpers.js index 8c597e70913..bcea19a2bb5 100644 --- a/Apps/Sandcastle/Sandcastle-helpers.js +++ b/Apps/Sandcastle/Sandcastle-helpers.js @@ -1,14 +1,6 @@ -require({ - baseUrl: '../../Source', - packages: [{ - name: 'ThirdParty', - location: '../Apps/Sandcastle/ThirdParty' - }] - }, [ - 'ThirdParty/pako.min' - ], function( - pako) { +(function() { 'use strict'; + var pako = window.pako; window.embedInSandcastleTemplate = function(code, addExtraLine) { return 'function startup(Cesium) {\n' + @@ -46,4 +38,4 @@ require({ baseHref : baseHref }; }; - }); +}()); diff --git a/Apps/Sandcastle/standalone.html b/Apps/Sandcastle/standalone.html index 80c80c9ae2a..e3708eb93e6 100644 --- a/Apps/Sandcastle/standalone.html +++ b/Apps/Sandcastle/standalone.html @@ -7,6 +7,7 @@ Cesium Demo + - diff --git a/gulpfile.js b/gulpfile.js index d794ff8b891..40797ad6802 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -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)); From 3a4a4a9069ec7c3f637e7b184b7d6891e398a582 Mon Sep 17 00:00:00 2001 From: Omar Shehata Date: Fri, 4 Jan 2019 15:35:18 -0500 Subject: [PATCH 20/20] Update changes --- CHANGES.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index e4eabc4cdd4..f8128c54934 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -20,7 +20,8 @@ Change Log * Fixed an issue where classification primitives with the `CESIUM_3D_TILE` classification type would render on terrain. [#7422](https://github.com/AnalyticalGraphicsInc/cesium/pull/7422) * Fixed an issue where 3D Tiles would show through the globe. [#7422](https://github.com/AnalyticalGraphicsInc/cesium/pull/7422) * Fixed crash when entity geometry show value is an interval that only covered part of the entity availability range [#7458](https://github.com/AnalyticalGraphicsInc/cesium/pull/7458) -* Fixed image size issue when using multiple particle systems [#7412](https://github.com/AnalyticalGraphicsInc/cesium/pull/7412) +* Fixed image size issue when using multiple particle systems. [#7412](https://github.com/AnalyticalGraphicsInc/cesium/pull/7412) +* Fixed Sandcastle's "Open in New Window" button not displaying imagery due to blob URI limitations. [#7250](https://github.com/AnalyticalGraphicsInc/cesium/pull/7250) ### 1.53 - 2019-01-02