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