Browse Source

remove threejs-lesson-helper from samples

editor.js will inject it since it's only needed on the website
Gregg (Greggman/GMan) Tavares 7 years ago
parent
commit
5c0ba3b840

+ 48 - 11
threejs/resources/editor.js

@@ -48,14 +48,18 @@ function getHTML(url, callback) {
   req.send('');
 }
 
+function getPrefix(url) {
+  const u = new URL(window.location.origin + url);
+  const prefix = u.origin + dirname(u.pathname);
+  return prefix;
+}
+
 function fixSourceLinks(url, source) {
   const srcRE = /(src=)"(.*?)"/g;
   const linkRE = /(href=)"(.*?")/g;
   const imageSrcRE = /((?:image|img)\.src = )"(.*?)"/g;
   const loaderLoadRE = /(loader\.load)\(('|")(.*?)('|")/g;
-
-  const u = new URL(window.location.origin + url);
-  const prefix = u.origin + dirname(u.pathname);
+  const prefix = getPrefix(url);
 
   function addPrefix(url) {
     return url.indexOf('://') < 0 ? (prefix + url) : url;
@@ -202,18 +206,20 @@ function main() {
 
 
 let blobUrl;
-function getSourceBlob(options) {
+function getSourceBlob(htmlParts, options) {
   options = options || {};
   if (blobUrl) {
     URL.revokeObjectURL(blobUrl);
   }
+  const prefix = dirname(g.url);
   let source = g.html;
   source = source.replace('${hackedParams}', JSON.stringify(g.query));
-  source = source.replace('${html}', htmlParts.html.editor.getValue());
-  source = source.replace('${css}', htmlParts.css.editor.getValue());
-  source = source.replace('${js}', htmlParts.js.editor.getValue());
+  source = source.replace('${html}', htmlParts.html);
+  source = source.replace('${css}', htmlParts.css);
+  source = source.replace('${js}', htmlParts.js);
   source = source.replace('<head>', '<head>\n<script match="false">threejsLessonSettings = ' + JSON.stringify(options) + ';</script>');
 
+  source = source.replace('</head>', '<script src="' + prefix + '/resources/threejs-lessons-helper.js"></script>\n</head>');
   const scriptNdx = source.indexOf('<script>');
   g.numLinesBeforeScript = (source.substring(0, scriptNdx).match(/\n/g) || []).length;
 
@@ -222,6 +228,22 @@ function getSourceBlob(options) {
   return blobUrl;
 }
 
+function getSourceBlobFromEditor(options) {
+  return getSourceBlob({
+    html: htmlParts.html.editor.getValue(),
+    css: htmlParts.css.editor.getValue(),
+    js: htmlParts.js.editor.getValue(),
+  }, options);
+}
+
+function getSourceBlobFromOrig(options) {
+  return getSourceBlob({
+    html: htmlParts.html.source,
+    css: htmlParts.css.source,
+    js: htmlParts.js.source,
+  }, options);
+}
+
 function dirname(path) {
   const ndx = path.lastIndexOf('/');
   return path.substring(0, ndx + 1);
@@ -359,7 +381,7 @@ function toggleFullscreen() {
 
 function run(options) {
   g.setPosition = false;
-  const url = getSourceBlob(options);
+  const url = getSourceBlobFromEditor(options);
   g.iframe.src = url;
 }
 
@@ -479,19 +501,34 @@ function runEditor(parent, source, language) {
   });
 }
 
-function start() {
+function runAsBlob() {
   const query = getQuery();
+  g.url = getFQUrl(query.url);
+  g.query = getSearch(g.url);
+  getHTML(query.url, function(err, html) {
+    if (err) {
+      console.log(err);  // eslint-disable-line
+      return;
+    }
+    parseHTML(query.url, html);
+    window.location.href = getSourceBlobFromOrig();
+  });
+}
+
+function start() {
   const parentQuery = getQuery(window.parent.location.search);
   const isSmallish = window.navigator.userAgent.match(/Android|iPhone|iPod|Windows Phone/i);
   const isEdge = window.navigator.userAgent.match(/Edge/i);
   if (isEdge || isSmallish || parentQuery.editor === 'false') {
-    const url = query.url;
-    window.location.href = url;
+    runAsBlob();
+    // var url = query.url;
+    // window.location.href = url;
   } else {
     require.config({ paths: { 'vs': '/monaco-editor/min/vs' }});
     require(['vs/editor/editor.main'], main);
   }
 }
+
 start();
 }());
 

+ 0 - 1
threejs/threejs-fundamentals-3-cubes.html

@@ -10,7 +10,6 @@
     <canvas id="c"></canvas>
   </body>
 <script src="resources/threejs/r93/three.min.js"></script>
-<script src="resources/threejs-lessons-helper.js"></script> <!-- you can and should delete this script. it is only used on the site to help with errors -->
 <script>
 'use strict';
 

+ 0 - 1
threejs/threejs-fundamentals-with-animation.html

@@ -10,7 +10,6 @@
     <canvas id="c"></canvas>
   </body>
 <script src="resources/threejs/r93/three.min.js"></script>
-<script src="resources/threejs-lessons-helper.js"></script> <!-- you can and should delete this script. it is only used on the site to help with errors -->
 <script>
 'use strict';
 

+ 0 - 1
threejs/threejs-fundamentals-with-light.html

@@ -10,7 +10,6 @@
     <canvas id="c"></canvas>
   </body>
 <script src="resources/threejs/r93/three.min.js"></script>
-<script src="resources/threejs-lessons-helper.js"></script> <!-- you can and should delete this script. it is only used on the site to help with errors -->
 <script>
 'use strict';
 

+ 0 - 1
threejs/threejs-fundamentals.html

@@ -10,7 +10,6 @@
     <canvas id="c"></canvas>
   </body>
 <script src="resources/threejs/r93/three.min.js"></script>
-<script src="resources/threejs-lessons-helper.js"></script> <!-- you can and should delete this script. it is only used on the site to help with errors -->
 <script>
 'use strict';
 

+ 0 - 1
threejs/threejs-primitives-text.html

@@ -20,7 +20,6 @@
     <canvas id="c"></canvas>
   </body>
 <script src="resources/threejs/r93/three.min.js"></script>
-<script src="resources/threejs-lessons-helper.js"></script> <!-- you can and should delete this script. it is only used on the site to help with errors -->
 <script>
 'use strict';
 

+ 0 - 1
threejs/threejs-primitives.html

@@ -20,7 +20,6 @@
     <canvas id="c"></canvas>
   </body>
 <script src="resources/threejs/r93/three.min.js"></script>
-<script src="resources/threejs-lessons-helper.js"></script> <!-- you can and should delete this script. it is only used on the site to help with errors -->
 <script>
 'use strict';
 

+ 0 - 1
threejs/threejs-responsive-editor.html

@@ -48,7 +48,6 @@
     </div>
   </body>
 <script src="resources/threejs/r93/three.min.js"></script>
-<script src="resources/threejs-lessons-helper.js"></script> <!-- you can and should delete this script. it is only used on the site to help with errors -->
 <script src="threejs-responsive.js"></script>
 <script src="../3rdparty/split.min.js"></script>
 <script>

+ 0 - 1
threejs/threejs-responsive-hd-dpi.html

@@ -21,7 +21,6 @@
     <canvas id="c"></canvas>
   </body>
 <script src="resources/threejs/r93/three.min.js"></script>
-<script src="resources/threejs-lessons-helper.js"></script> <!-- you can and should delete this script. it is only used on the site to help with errors -->
 <script>
 'use strict';
 

+ 0 - 1
threejs/threejs-responsive-no-resize.html

@@ -21,7 +21,6 @@
     <canvas id="c"></canvas>
   </body>
 <script src="resources/threejs/r93/three.min.js"></script>
-<script src="resources/threejs-lessons-helper.js"></script> <!-- you can and should delete this script. it is only used on the site to help with errors -->
 <script>
 'use strict';
 

+ 0 - 1
threejs/threejs-responsive-paragraph.html

@@ -30,7 +30,6 @@ ut, auctor eget massa.
 </p>
   </body>
 <script src="resources/threejs/r93/three.min.js"></script>
-<script src="resources/threejs-lessons-helper.js"></script> <!-- you can and should delete this script. it is only used on the site to help with errors -->
 <script src="threejs-responsive.js"></script>
 </html>
 

+ 0 - 1
threejs/threejs-responsive-update-camera.html

@@ -21,7 +21,6 @@
     <canvas id="c"></canvas>
   </body>
 <script src="resources/threejs/r93/three.min.js"></script>
-<script src="resources/threejs-lessons-helper.js"></script> <!-- you can and should delete this script. it is only used on the site to help with errors -->
 <script>
 'use strict';
 

+ 0 - 1
threejs/threejs-responsive.html

@@ -20,7 +20,6 @@
     <canvas id="c"></canvas>
   </body>
 <script src="resources/threejs/r93/three.min.js"></script>
-<script src="resources/threejs-lessons-helper.js"></script> <!-- you can and should delete this script. it is only used on the site to help with errors -->
 <script>
 'use strict';