|
@@ -1,7 +1,77 @@
|
|
var jsEditor;
|
|
var jsEditor;
|
|
|
|
+
|
|
var defaultScene = "scripts/basic scene.js";
|
|
var defaultScene = "scripts/basic scene.js";
|
|
var monacoMode = "javascript";
|
|
var monacoMode = "javascript";
|
|
|
|
|
|
|
|
+var scriptLanguage = localStorage.getItem("bjs-playground-scriptLanguage") || 'JS';
|
|
|
|
+if (scriptLanguage == "JS") {
|
|
|
|
+ defaultScene = "scripts/basic scene.js";
|
|
|
|
+ monacoMode = "javascript";
|
|
|
|
+}
|
|
|
|
+else if (scriptLanguage == "TS") {
|
|
|
|
+ defaultScene = "scripts/basic scene.txt";
|
|
|
|
+ monacoMode = "typescript";
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ var compilerTriggerTimeoutID;
|
|
|
|
+ function triggerCompile(d, func) {
|
|
|
|
+ if (compilerTriggerTimeoutID !== null) {
|
|
|
|
+ window.clearTimeout(compilerTriggerTimeoutID);
|
|
|
|
+ }
|
|
|
|
+ compilerTriggerTimeoutID = window.setTimeout(function () {
|
|
|
|
+ try {
|
|
|
|
+
|
|
|
|
+ var output = transpileModule(d, {
|
|
|
|
+ module: ts.ModuleKind.AMD,
|
|
|
|
+ target: ts.ScriptTarget.ES5,
|
|
|
|
+ noLib: true,
|
|
|
|
+ noResolve: true,
|
|
|
|
+ suppressOutputPathCheck: true
|
|
|
|
+ });
|
|
|
|
+ if (typeof output === "string") {
|
|
|
|
+ func(output);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ catch (e) {
|
|
|
|
+ showError(e.message, e);
|
|
|
|
+ }
|
|
|
|
+ }, 100);
|
|
|
|
+ }
|
|
|
|
+ function transpileModule(input, options) {
|
|
|
|
+ var inputFileName = options.jsx ? "module.tsx" : "module.ts";
|
|
|
|
+ var sourceFile = ts.createSourceFile(inputFileName, input, options.target || ts.ScriptTarget.ES5);
|
|
|
|
+ // Output
|
|
|
|
+ var outputText;
|
|
|
|
+ var program = ts.createProgram([inputFileName], options, {
|
|
|
|
+ getSourceFile: function (fileName) { return fileName.indexOf("module") === 0 ? sourceFile : undefined; },
|
|
|
|
+ writeFile: function (_name, text) { outputText = text; },
|
|
|
|
+ getDefaultLibFileName: function () { return "lib.d.ts"; },
|
|
|
|
+ useCaseSensitiveFileNames: function () { return false; },
|
|
|
|
+ getCanonicalFileName: function (fileName) { return fileName; },
|
|
|
|
+ getCurrentDirectory: function () { return ""; },
|
|
|
|
+ getNewLine: function () { return "\r\n"; },
|
|
|
|
+ fileExists: function (fileName) { return fileName === inputFileName; },
|
|
|
|
+ readFile: function () { return ""; },
|
|
|
|
+ directoryExists: function () { return true; },
|
|
|
|
+ getDirectories: function () { return []; }
|
|
|
|
+ });
|
|
|
|
+ // Emit
|
|
|
|
+ program.emit();
|
|
|
|
+ if (outputText === undefined) {
|
|
|
|
+ throw new Error("Output generation failed");
|
|
|
|
+ }
|
|
|
|
+ return outputText;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ function getRunCode(jsEditor, callBack) {
|
|
|
|
+ triggerCompile(jsEditor.getValue(), function (result) {
|
|
|
|
+ callBack(result + "var createScene = function() { return Playground.CreateScene(engine, engine.getRenderingCanvas()); }")
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
function getRunCode(jsEditor, callBack) {
|
|
function getRunCode(jsEditor, callBack) {
|
|
var code = jsEditor.getValue();
|
|
var code = jsEditor.getValue();
|
|
callBack(code);
|
|
callBack(code);
|
|
@@ -30,22 +100,27 @@ function showError(errorMessage, errorEvent) {
|
|
document.getElementById("errorZone").innerHTML = errorContent;
|
|
document.getElementById("errorZone").innerHTML = errorContent;
|
|
|
|
|
|
// Close button error
|
|
// Close button error
|
|
- document.getElementById("errorZone").querySelector('.close').addEventListener('click', function() {
|
|
|
|
|
|
+ document.getElementById("errorZone").querySelector('.close').addEventListener('click', function () {
|
|
document.getElementById("errorZone").style.display = 'none';
|
|
document.getElementById("errorZone").style.display = 'none';
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
-(function() {
|
|
|
|
-
|
|
|
|
- var multipleSize = [1600, 1475, 1030, 750];
|
|
|
|
- var setToMultipleID = function(id, thingToDo, param) {
|
|
|
|
- multipleSize.forEach(function(size) {
|
|
|
|
|
|
+(function () {
|
|
|
|
|
|
|
|
+ var multipleSize = [1280, 920, 710, 550];
|
|
|
|
+ var setToMultipleID = function (id, thingToDo, param) {
|
|
|
|
+ multipleSize.forEach(function (size) {
|
|
if (thingToDo == "innerHTML") {
|
|
if (thingToDo == "innerHTML") {
|
|
document.getElementById(id + size).innerHTML = param
|
|
document.getElementById(id + size).innerHTML = param
|
|
}
|
|
}
|
|
else if (thingToDo == "click") {
|
|
else if (thingToDo == "click") {
|
|
- document.getElementById(id + size).addEventListener("click", param);
|
|
|
|
|
|
+ if (param.length > 1) {
|
|
|
|
+ for (var i = 0; i < param.length; i++) {
|
|
|
|
+ document.getElementById(id + size).addEventListener("click", param[i]);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ document.getElementById(id + size).addEventListener("click", param);
|
|
}
|
|
}
|
|
else if (thingToDo == "addClass") {
|
|
else if (thingToDo == "addClass") {
|
|
document.getElementById(id + size).classList.add(param);
|
|
document.getElementById(id + size).classList.add(param);
|
|
@@ -65,18 +140,21 @@ function showError(errorMessage, errorEvent) {
|
|
|
|
|
|
var splitInstance = Split(['#jsEditor', '#canvasZone']);
|
|
var splitInstance = Split(['#jsEditor', '#canvasZone']);
|
|
|
|
|
|
|
|
+ var elementForscriptLanguage = [
|
|
|
|
+ '#exampleList #exampleBanner',
|
|
|
|
+ '.navbar',
|
|
|
|
+ '.navbar .category',
|
|
|
|
+ '.navbar .select .toDisplay',
|
|
|
|
+ '.navbar .select .toDisplay .subSelect .toDisplaySub',
|
|
|
|
+ '#fpsLabel',
|
|
|
|
+ '.save-form'
|
|
|
|
+ ];
|
|
var elementToTheme = [
|
|
var elementToTheme = [
|
|
- '.wrapper .gutter',
|
|
|
|
'.wrapper #jsEditor',
|
|
'.wrapper #jsEditor',
|
|
- '.navbar',
|
|
|
|
- '.navbar .select .toDisplay .option',
|
|
|
|
- '.navbar .select .toDisplayBig',
|
|
|
|
- '.navbar .select .toDisplayBig a',
|
|
|
|
- '.navbar .select .toDisplayBig ul li',
|
|
|
|
- '.navbarBottom',
|
|
|
|
- '.navbarBottom .links .link'];
|
|
|
|
|
|
+ '.wrapper .gutter'
|
|
|
|
+ ];
|
|
|
|
|
|
- var run = function() {
|
|
|
|
|
|
+ var run = function () {
|
|
|
|
|
|
// #region - Examples playgrounds
|
|
// #region - Examples playgrounds
|
|
var examplesButton = document.getElementsByClassName("examplesButton");
|
|
var examplesButton = document.getElementsByClassName("examplesButton");
|
|
@@ -84,13 +162,15 @@ function showError(errorMessage, errorEvent) {
|
|
if (examplesButton && examplesButton.length > 0) {
|
|
if (examplesButton && examplesButton.length > 0) {
|
|
var isExamplesDisplayed = false;
|
|
var isExamplesDisplayed = false;
|
|
for (var i = 0; i < examplesButton.length; i++) {
|
|
for (var i = 0; i < examplesButton.length; i++) {
|
|
- examplesButton[i].parentElement.onclick = function() {
|
|
|
|
|
|
+ examplesButton[i].parentElement.onclick = function () {
|
|
isExamplesDisplayed = !isExamplesDisplayed;
|
|
isExamplesDisplayed = !isExamplesDisplayed;
|
|
if (isExamplesDisplayed) {
|
|
if (isExamplesDisplayed) {
|
|
|
|
+ document.getElementById("fpsLabel").style.display = "none";
|
|
document.getElementById("exampleList").style.display = "block";
|
|
document.getElementById("exampleList").style.display = "block";
|
|
document.getElementsByClassName("wrapper")[0].style.width = "calc(100% - 400px)";
|
|
document.getElementsByClassName("wrapper")[0].style.width = "calc(100% - 400px)";
|
|
}
|
|
}
|
|
else {
|
|
else {
|
|
|
|
+ document.getElementById("fpsLabel").style.display = "block";
|
|
document.getElementById("exampleList").style.display = "none";
|
|
document.getElementById("exampleList").style.display = "none";
|
|
document.getElementsByClassName("wrapper")[0].style.width = "100%";
|
|
document.getElementsByClassName("wrapper")[0].style.width = "100%";
|
|
}
|
|
}
|
|
@@ -102,7 +182,7 @@ function showError(errorMessage, errorEvent) {
|
|
var filterBar = document.getElementById("filterBar");
|
|
var filterBar = document.getElementById("filterBar");
|
|
if (filterBar) {
|
|
if (filterBar) {
|
|
var filterBarClear = document.getElementById("filterBarClear");
|
|
var filterBarClear = document.getElementById("filterBarClear");
|
|
- var filter = function() {
|
|
|
|
|
|
+ var filter = function () {
|
|
var filterText = filterBar.value.toLowerCase();
|
|
var filterText = filterBar.value.toLowerCase();
|
|
if (filterText == "") filterBarClear.style.display = "none";
|
|
if (filterText == "") filterBarClear.style.display = "none";
|
|
else filterBarClear.style.display = "inline-block";
|
|
else filterBarClear.style.display = "inline-block";
|
|
@@ -132,10 +212,10 @@ function showError(errorMessage, errorEvent) {
|
|
if (displayCount == 0) document.getElementById("noResultsContainer").style.display = "block";
|
|
if (displayCount == 0) document.getElementById("noResultsContainer").style.display = "block";
|
|
else document.getElementById("noResultsContainer").style.display = "none";
|
|
else document.getElementById("noResultsContainer").style.display = "none";
|
|
}
|
|
}
|
|
- filterBar.oninput = function() {
|
|
|
|
|
|
+ filterBar.oninput = function () {
|
|
filter();
|
|
filter();
|
|
}
|
|
}
|
|
- filterBarClear.onclick = function() {
|
|
|
|
|
|
+ filterBarClear.onclick = function () {
|
|
filterBar.value = "";
|
|
filterBar.value = "";
|
|
filter();
|
|
filter();
|
|
}
|
|
}
|
|
@@ -144,7 +224,7 @@ function showError(errorMessage, errorEvent) {
|
|
|
|
|
|
var blockEditorChange = false;
|
|
var blockEditorChange = false;
|
|
|
|
|
|
- var markDirty = function() {
|
|
|
|
|
|
+ var markDirty = function () {
|
|
if (blockEditorChange) {
|
|
if (blockEditorChange) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
@@ -155,7 +235,7 @@ function showError(errorMessage, errorEvent) {
|
|
setToMultipleID('safemodeToggle', 'innerHTML', 'Safe mode <i class="fa fa-check-square" aria-hidden="true"></i>');
|
|
setToMultipleID('safemodeToggle', 'innerHTML', 'Safe mode <i class="fa fa-check-square" aria-hidden="true"></i>');
|
|
}
|
|
}
|
|
|
|
|
|
- jsEditor.onKeyUp(function(evt) {
|
|
|
|
|
|
+ jsEditor.onKeyUp(function (evt) {
|
|
markDirty();
|
|
markDirty();
|
|
});
|
|
});
|
|
|
|
|
|
@@ -170,26 +250,27 @@ function showError(errorMessage, errorEvent) {
|
|
var zipCode;
|
|
var zipCode;
|
|
BABYLON.Engine.ShadersRepository = "/src/Shaders/";
|
|
BABYLON.Engine.ShadersRepository = "/src/Shaders/";
|
|
|
|
|
|
|
|
+ // TO DO : Rewrite this with unpkg.com
|
|
if (location.href.indexOf("indexStable") !== -1) {
|
|
if (location.href.indexOf("indexStable") !== -1) {
|
|
- setToMultipleID("currentVersion", "innerHTML", "Version: Stable");
|
|
|
|
|
|
+ setToMultipleID("currentVersion", "innerHTML", "v.3.0");
|
|
} else {
|
|
} else {
|
|
- setToMultipleID("currentVersion", "innerHTML", "Version: Latest");
|
|
|
|
|
|
+ setToMultipleID("currentVersion", "innerHTML", "v.4.0");
|
|
}
|
|
}
|
|
|
|
|
|
- var checkTypescriptSupport = function(xhr) {
|
|
|
|
- var filename = location.pathname.substring(location.pathname.lastIndexOf('/') + 1);
|
|
|
|
- if (xhr.responseText.indexOf("class Playground") !== -1) {// Typescript content
|
|
|
|
- if (!filename) {
|
|
|
|
- window.location.href = location.protocol + "//" + location.host + "/ts.html" + window.location.hash;
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
- else if (filename !== "ts.html") {
|
|
|
|
- window.location.href = location.protocol + "//" + location.host + location.pathname.replace(filename, "ts.html") + window.location.hash;
|
|
|
|
|
|
+ var checkTypescriptSupport = function (xhr) {
|
|
|
|
+ // If we're loading TS content and it's JS page
|
|
|
|
+ if (xhr.responseText.indexOf("class Playground") !== -1) {
|
|
|
|
+ if (scriptLanguage == "JS") {
|
|
|
|
+ localStorage.setItem("bjs-playground-scriptLanguage", "TS");
|
|
|
|
+ if (confirm("You need to reload the page to switch to Typescript. Do you want to reload now ?"))
|
|
|
|
+ location.reload();
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
- } else { // Javscript content
|
|
|
|
- if (filename === "ts.html") {
|
|
|
|
- window.location.href = location.protocol + "//" + location.host + location.pathname.replace(filename, "index.html") + window.location.hash;
|
|
|
|
|
|
+ } else { // If we're loading JS content and it's TS page
|
|
|
|
+ if (scriptLanguage == "TS") {
|
|
|
|
+ localStorage.setItem("bjs-playground-scriptLanguage", "JS");
|
|
|
|
+ if (confirm("You need to reload the page to switch to Javascript. Do you want to reload now ?"))
|
|
|
|
+ location.reload();
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -197,12 +278,12 @@ function showError(errorMessage, errorEvent) {
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
|
|
- var loadScript = function(scriptURL, title) {
|
|
|
|
|
|
+ var loadScript = function (scriptURL, title) {
|
|
var xhr = new XMLHttpRequest();
|
|
var xhr = new XMLHttpRequest();
|
|
|
|
|
|
xhr.open('GET', scriptURL, true);
|
|
xhr.open('GET', scriptURL, true);
|
|
|
|
|
|
- xhr.onreadystatechange = function() {
|
|
|
|
|
|
+ xhr.onreadystatechange = function () {
|
|
if (xhr.readyState === 4) {
|
|
if (xhr.readyState === 4) {
|
|
if (xhr.status === 200) {
|
|
if (xhr.status === 200) {
|
|
|
|
|
|
@@ -227,7 +308,7 @@ function showError(errorMessage, errorEvent) {
|
|
xhr.send(null);
|
|
xhr.send(null);
|
|
};
|
|
};
|
|
|
|
|
|
- var loadScriptsList = function() {
|
|
|
|
|
|
+ var loadScriptsList = function () {
|
|
|
|
|
|
var exampleList = document.getElementById("exampleList");
|
|
var exampleList = document.getElementById("exampleList");
|
|
|
|
|
|
@@ -240,7 +321,7 @@ function showError(errorMessage, errorEvent) {
|
|
xhr.open('GET', 'https://raw.githubusercontent.com/BabylonJS/Documentation/master/examples/list_ts.json', true);
|
|
xhr.open('GET', 'https://raw.githubusercontent.com/BabylonJS/Documentation/master/examples/list_ts.json', true);
|
|
}
|
|
}
|
|
|
|
|
|
- xhr.onreadystatechange = function() {
|
|
|
|
|
|
+ xhr.onreadystatechange = function () {
|
|
if (xhr.readyState === 4) {
|
|
if (xhr.readyState === 4) {
|
|
if (xhr.status === 200) {
|
|
if (xhr.status === 200) {
|
|
scripts = JSON.parse(xhr.response)["examples"];
|
|
scripts = JSON.parse(xhr.response)["examples"];
|
|
@@ -383,9 +464,12 @@ function showError(errorMessage, errorEvent) {
|
|
// Restore theme
|
|
// Restore theme
|
|
var theme = localStorage.getItem("bjs-playground-theme") || 'light';
|
|
var theme = localStorage.getItem("bjs-playground-theme") || 'light';
|
|
toggleTheme(theme);
|
|
toggleTheme(theme);
|
|
|
|
+ // Restore language
|
|
|
|
+ scriptLanguage = localStorage.getItem("bjs-playground-scriptLanguage") || 'JS';
|
|
|
|
+ togglescriptLanguage(scriptLanguage);
|
|
|
|
|
|
// Remove editor if window size is less than 850px
|
|
// Remove editor if window size is less than 850px
|
|
- var removeEditorForSmallScreen = function() {
|
|
|
|
|
|
+ var removeEditorForSmallScreen = function () {
|
|
if (mq.matches) {
|
|
if (mq.matches) {
|
|
splitInstance.collapse(0);
|
|
splitInstance.collapse(0);
|
|
} else {
|
|
} else {
|
|
@@ -401,7 +485,7 @@ function showError(errorMessage, errorEvent) {
|
|
xhr.send(null);
|
|
xhr.send(null);
|
|
}
|
|
}
|
|
|
|
|
|
- var createNewScript = function() {
|
|
|
|
|
|
+ var createNewScript = function () {
|
|
// check if checked is on
|
|
// check if checked is on
|
|
let iCanClear = checkSafeMode("Are you sure you want to create a new playground?");
|
|
let iCanClear = checkSafeMode("Are you sure you want to create a new playground?");
|
|
if (!iCanClear) return;
|
|
if (!iCanClear) return;
|
|
@@ -421,7 +505,7 @@ function showError(errorMessage, errorEvent) {
|
|
compileAndRun();
|
|
compileAndRun();
|
|
}
|
|
}
|
|
|
|
|
|
- var clear = function() {
|
|
|
|
|
|
+ var clear = function () {
|
|
// check if checked is on
|
|
// check if checked is on
|
|
let iCanClear = checkSafeMode("Are you sure you want to clear the playground?");
|
|
let iCanClear = checkSafeMode("Are you sure you want to clear the playground?");
|
|
if (!iCanClear) return;
|
|
if (!iCanClear) return;
|
|
@@ -432,14 +516,14 @@ function showError(errorMessage, errorEvent) {
|
|
jsEditor.focus();
|
|
jsEditor.focus();
|
|
}
|
|
}
|
|
|
|
|
|
- var checkSafeMode = function(message) {
|
|
|
|
- var safeToggle = document.getElementById("safemodeToggle1600");
|
|
|
|
|
|
+ var checkSafeMode = function (message) {
|
|
|
|
+ var safeToggle = document.getElementById("safemodeToggle1280");
|
|
if (safeToggle.classList.contains('checked')) {
|
|
if (safeToggle.classList.contains('checked')) {
|
|
let confirm = window.confirm(message);
|
|
let confirm = window.confirm(message);
|
|
if (!confirm) {
|
|
if (!confirm) {
|
|
return false;
|
|
return false;
|
|
} else {
|
|
} else {
|
|
- document.getElementById("safemodeToggle1600").classList.toggle('checked');
|
|
|
|
|
|
+ document.getElementById("safemodeToggle1280").classList.toggle('checked');
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
@@ -447,7 +531,7 @@ function showError(errorMessage, errorEvent) {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- var showNoMetadata = function() {
|
|
|
|
|
|
+ var showNoMetadata = function () {
|
|
if (currentSnippetTitle) {
|
|
if (currentSnippetTitle) {
|
|
document.getElementById("saveFormTitle").value = currentSnippetTitle;
|
|
document.getElementById("saveFormTitle").value = currentSnippetTitle;
|
|
document.getElementById("saveFormTitle").readOnly = true;
|
|
document.getElementById("saveFormTitle").readOnly = true;
|
|
@@ -477,7 +561,7 @@ function showError(errorMessage, errorEvent) {
|
|
};
|
|
};
|
|
showNoMetadata();
|
|
showNoMetadata();
|
|
|
|
|
|
- var hideNoMetadata = function() {
|
|
|
|
|
|
+ var hideNoMetadata = function () {
|
|
document.getElementById("saveFormTitle").readOnly = true;
|
|
document.getElementById("saveFormTitle").readOnly = true;
|
|
document.getElementById("saveFormDescription").readOnly = true;
|
|
document.getElementById("saveFormDescription").readOnly = true;
|
|
document.getElementById("saveFormTags").readOnly = true;
|
|
document.getElementById("saveFormTags").readOnly = true;
|
|
@@ -485,7 +569,7 @@ function showError(errorMessage, errorEvent) {
|
|
setToMultipleID("metadataButton", "display", "inline-block");
|
|
setToMultipleID("metadataButton", "display", "inline-block");
|
|
};
|
|
};
|
|
|
|
|
|
- compileAndRun = function() {
|
|
|
|
|
|
+ compileAndRun = function () {
|
|
try {
|
|
try {
|
|
var waitRing = document.getElementById("waitDiv");
|
|
var waitRing = document.getElementById("waitDiv");
|
|
if (waitRing) {
|
|
if (waitRing) {
|
|
@@ -520,8 +604,8 @@ function showError(errorMessage, errorEvent) {
|
|
var createEngineFunction = "createDefaultEngine";
|
|
var createEngineFunction = "createDefaultEngine";
|
|
var createSceneFunction;
|
|
var createSceneFunction;
|
|
|
|
|
|
- getRunCode(jsEditor, function(code) {
|
|
|
|
- var createDefaultEngine = function() {
|
|
|
|
|
|
+ getRunCode(jsEditor, function (code) {
|
|
|
|
+ var createDefaultEngine = function () {
|
|
return new BABYLON.Engine(canvas, true, { preserveDrawingBuffer: true, stencil: true });
|
|
return new BABYLON.Engine(canvas, true, { preserveDrawingBuffer: true, stencil: true });
|
|
}
|
|
}
|
|
|
|
|
|
@@ -586,7 +670,7 @@ function showError(errorMessage, errorEvent) {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- engine.runRenderLoop(function() {
|
|
|
|
|
|
+ engine.runRenderLoop(function () {
|
|
if (engine.scenes.length === 0) {
|
|
if (engine.scenes.length === 0) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
@@ -601,7 +685,6 @@ function showError(errorMessage, errorEvent) {
|
|
scene.render();
|
|
scene.render();
|
|
}
|
|
}
|
|
|
|
|
|
- fpsLabel.style.right = document.body.clientWidth - (jsEditor.domElement.clientWidth + canvas.clientWidth) + "px";
|
|
|
|
fpsLabel.innerHTML = engine.getFps().toFixed() + " fps";
|
|
fpsLabel.innerHTML = engine.getFps().toFixed() + " fps";
|
|
});
|
|
});
|
|
|
|
|
|
@@ -615,11 +698,11 @@ function showError(errorMessage, errorEvent) {
|
|
showError("You must at least create a camera.", null);
|
|
showError("You must at least create a camera.", null);
|
|
return;
|
|
return;
|
|
} else if (scene.then) {
|
|
} else if (scene.then) {
|
|
- scene.then(function() {
|
|
|
|
|
|
+ scene.then(function () {
|
|
document.getElementById("statusBar").innerHTML = "";
|
|
document.getElementById("statusBar").innerHTML = "";
|
|
});
|
|
});
|
|
} else {
|
|
} else {
|
|
- engine.scenes[0].executeWhenReady(function() {
|
|
|
|
|
|
+ engine.scenes[0].executeWhenReady(function () {
|
|
document.getElementById("statusBar").innerHTML = "";
|
|
document.getElementById("statusBar").innerHTML = "";
|
|
});
|
|
});
|
|
}
|
|
}
|
|
@@ -628,7 +711,7 @@ function showError(errorMessage, errorEvent) {
|
|
if (showInspector) {
|
|
if (showInspector) {
|
|
if (scene.then) {
|
|
if (scene.then) {
|
|
// Handle if scene is a promise
|
|
// Handle if scene is a promise
|
|
- scene.then(function(s) {
|
|
|
|
|
|
+ scene.then(function (s) {
|
|
if (!s.debugLayer.isVisible()) {
|
|
if (!s.debugLayer.isVisible()) {
|
|
s.debugLayer.show({ embedMode: true });
|
|
s.debugLayer.show({ embedMode: true });
|
|
}
|
|
}
|
|
@@ -649,7 +732,7 @@ function showError(errorMessage, errorEvent) {
|
|
}
|
|
}
|
|
};
|
|
};
|
|
window.addEventListener("resize",
|
|
window.addEventListener("resize",
|
|
- function() {
|
|
|
|
|
|
+ function () {
|
|
if (engine) {
|
|
if (engine) {
|
|
engine.resize();
|
|
engine.resize();
|
|
}
|
|
}
|
|
@@ -659,7 +742,7 @@ function showError(errorMessage, errorEvent) {
|
|
loadScriptsList();
|
|
loadScriptsList();
|
|
|
|
|
|
// Zip
|
|
// Zip
|
|
- var addContentToZip = function(zip, name, url, replace, buffer, then) {
|
|
|
|
|
|
+ var addContentToZip = function (zip, name, url, replace, buffer, then) {
|
|
if (url.substring(0, 5) == "data:" || url.substring(0, 5) == "http:" || url.substring(0, 5) == "blob:" || url.substring(0, 6) == "https:") {
|
|
if (url.substring(0, 5) == "data:" || url.substring(0, 5) == "http:" || url.substring(0, 5) == "blob:" || url.substring(0, 6) == "https:") {
|
|
then();
|
|
then();
|
|
return;
|
|
return;
|
|
@@ -673,7 +756,7 @@ function showError(errorMessage, errorEvent) {
|
|
xhr.responseType = "arraybuffer";
|
|
xhr.responseType = "arraybuffer";
|
|
}
|
|
}
|
|
|
|
|
|
- xhr.onreadystatechange = function() {
|
|
|
|
|
|
+ xhr.onreadystatechange = function () {
|
|
if (xhr.readyState === 4) {
|
|
if (xhr.readyState === 4) {
|
|
if (xhr.status === 200) {
|
|
if (xhr.status === 200) {
|
|
var text;
|
|
var text;
|
|
@@ -701,7 +784,7 @@ function showError(errorMessage, errorEvent) {
|
|
xhr.send(null);
|
|
xhr.send(null);
|
|
}
|
|
}
|
|
|
|
|
|
- var addTexturesToZip = function(zip, index, textures, folder, then) {
|
|
|
|
|
|
+ var addTexturesToZip = function (zip, index, textures, folder, then) {
|
|
|
|
|
|
if (index === textures.length || !textures[index].name) {
|
|
if (index === textures.length || !textures[index].name) {
|
|
then();
|
|
then();
|
|
@@ -754,7 +837,7 @@ function showError(errorMessage, errorEvent) {
|
|
url,
|
|
url,
|
|
null,
|
|
null,
|
|
true,
|
|
true,
|
|
- function() {
|
|
|
|
|
|
+ function () {
|
|
addTexturesToZip(zip, index + 1, textures, folder, then);
|
|
addTexturesToZip(zip, index + 1, textures, folder, then);
|
|
});
|
|
});
|
|
}
|
|
}
|
|
@@ -763,7 +846,7 @@ function showError(errorMessage, errorEvent) {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- var addImportedFilesToZip = function(zip, index, importedFiles, folder, then) {
|
|
|
|
|
|
+ var addImportedFilesToZip = function (zip, index, importedFiles, folder, then) {
|
|
if (index === importedFiles.length) {
|
|
if (index === importedFiles.length) {
|
|
then();
|
|
then();
|
|
return;
|
|
return;
|
|
@@ -781,12 +864,12 @@ function showError(errorMessage, errorEvent) {
|
|
url,
|
|
url,
|
|
null,
|
|
null,
|
|
true,
|
|
true,
|
|
- function() {
|
|
|
|
|
|
+ function () {
|
|
addImportedFilesToZip(zip, index + 1, importedFiles, folder, then);
|
|
addImportedFilesToZip(zip, index + 1, importedFiles, folder, then);
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
- var getZip = function() {
|
|
|
|
|
|
+ var getZip = function () {
|
|
if (engine.scenes.length === 0) {
|
|
if (engine.scenes.length === 0) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
@@ -810,17 +893,17 @@ function showError(errorMessage, errorEvent) {
|
|
"zipContent/index.html",
|
|
"zipContent/index.html",
|
|
zipCode,
|
|
zipCode,
|
|
false,
|
|
false,
|
|
- function() {
|
|
|
|
|
|
+ function () {
|
|
addTexturesToZip(zip,
|
|
addTexturesToZip(zip,
|
|
0,
|
|
0,
|
|
textures,
|
|
textures,
|
|
null,
|
|
null,
|
|
- function() {
|
|
|
|
|
|
+ function () {
|
|
addImportedFilesToZip(zip,
|
|
addImportedFilesToZip(zip,
|
|
0,
|
|
0,
|
|
importedFiles,
|
|
importedFiles,
|
|
null,
|
|
null,
|
|
- function() {
|
|
|
|
|
|
+ function () {
|
|
var blob = zip.generate({ type: "blob" });
|
|
var blob = zip.generate({ type: "blob" });
|
|
saveAs(blob, "sample.zip");
|
|
saveAs(blob, "sample.zip");
|
|
document.getElementById("statusBar").innerHTML = "";
|
|
document.getElementById("statusBar").innerHTML = "";
|
|
@@ -830,7 +913,7 @@ function showError(errorMessage, errorEvent) {
|
|
}
|
|
}
|
|
|
|
|
|
// Versions
|
|
// Versions
|
|
- setVersion = function(version) {
|
|
|
|
|
|
+ setVersion = function (version) {
|
|
switch (version) {
|
|
switch (version) {
|
|
case "stable":
|
|
case "stable":
|
|
location.href = "indexStable.html" + location.hash;
|
|
location.href = "indexStable.html" + location.hash;
|
|
@@ -842,42 +925,50 @@ function showError(errorMessage, errorEvent) {
|
|
}
|
|
}
|
|
|
|
|
|
// Fonts
|
|
// Fonts
|
|
- setFontSize = function(size) {
|
|
|
|
|
|
+ setFontSize = function (size) {
|
|
fontSize = size;
|
|
fontSize = size;
|
|
jsEditor.updateOptions({ fontSize: size });
|
|
jsEditor.updateOptions({ fontSize: size });
|
|
- setToMultipleID("currentFontSize", "innerHTML", "Font: " + size);
|
|
|
|
|
|
+
|
|
|
|
+ var array = document.getElementsByClassName("displayFontSize");
|
|
|
|
+ for (var i = 0; i < array.length; i++) {
|
|
|
|
+ var subArray = array[i].children;
|
|
|
|
+ for (var j = 0; j < subArray.length; j++) {
|
|
|
|
+ subArray[j].classList.remove("selected");
|
|
|
|
+ if (subArray[j].innerText == size) subArray[j].classList.add("selected");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
};
|
|
};
|
|
|
|
|
|
- showQRCode = function() {
|
|
|
|
|
|
+ showQRCode = function () {
|
|
$("#qrCodeImage").empty();
|
|
$("#qrCodeImage").empty();
|
|
var playgroundCode = window.location.href.split("#");
|
|
var playgroundCode = window.location.href.split("#");
|
|
playgroundCode.shift();
|
|
playgroundCode.shift();
|
|
- $("#qrCodeImage").qrcode({text: "https://playground.babylonjs.com/frame.html#"+(playgroundCode.join("#"))});
|
|
|
|
|
|
+ $("#qrCodeImage").qrcode({ text: "https://playground.babylonjs.com/frame.html#" + (playgroundCode.join("#")) });
|
|
};
|
|
};
|
|
|
|
|
|
// Fullscreen
|
|
// Fullscreen
|
|
- document.getElementById("renderCanvas").addEventListener("webkitfullscreenchange", function() {
|
|
|
|
|
|
+ document.getElementById("renderCanvas").addEventListener("webkitfullscreenchange", function () {
|
|
if (document.webkitIsFullScreen) goFullPage();
|
|
if (document.webkitIsFullScreen) goFullPage();
|
|
else exitFullPage();
|
|
else exitFullPage();
|
|
}, false);
|
|
}, false);
|
|
|
|
|
|
- var goFullPage = function() {
|
|
|
|
|
|
+ var goFullPage = function () {
|
|
var canvasElement = document.getElementById("renderCanvas");
|
|
var canvasElement = document.getElementById("renderCanvas");
|
|
canvasElement.style.position = "absolute";
|
|
canvasElement.style.position = "absolute";
|
|
canvasElement.style.top = 0;
|
|
canvasElement.style.top = 0;
|
|
canvasElement.style.left = 0;
|
|
canvasElement.style.left = 0;
|
|
canvasElement.style.zIndex = 100;
|
|
canvasElement.style.zIndex = 100;
|
|
}
|
|
}
|
|
- var exitFullPage = function() {
|
|
|
|
|
|
+ var exitFullPage = function () {
|
|
document.getElementById("renderCanvas").style.position = "relative";
|
|
document.getElementById("renderCanvas").style.position = "relative";
|
|
document.getElementById("renderCanvas").style.zIndex = 0;
|
|
document.getElementById("renderCanvas").style.zIndex = 0;
|
|
}
|
|
}
|
|
- var goFullscreen = function() {
|
|
|
|
|
|
+ var goFullscreen = function () {
|
|
if (engine) {
|
|
if (engine) {
|
|
engine.switchFullscreen(true);
|
|
engine.switchFullscreen(true);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- var editorGoFullscreen = function() {
|
|
|
|
|
|
+ var editorGoFullscreen = function () {
|
|
var editorDiv = document.getElementById("jsEditor");
|
|
var editorDiv = document.getElementById("jsEditor");
|
|
if (editorDiv.requestFullscreen) {
|
|
if (editorDiv.requestFullscreen) {
|
|
editorDiv.requestFullscreen();
|
|
editorDiv.requestFullscreen();
|
|
@@ -889,15 +980,15 @@ function showError(errorMessage, errorEvent) {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- var toggleEditor = function() {
|
|
|
|
- var editorButton = document.getElementById("editorButton1600");
|
|
|
|
|
|
+ var toggleEditor = function () {
|
|
|
|
+ var editorButton = document.getElementById("editorButton1280");
|
|
var scene = engine.scenes[0];
|
|
var scene = engine.scenes[0];
|
|
|
|
|
|
// If the editor is present
|
|
// If the editor is present
|
|
if (editorButton.classList.contains('checked')) {
|
|
if (editorButton.classList.contains('checked')) {
|
|
setToMultipleID("editorButton", "removeClass", 'checked');
|
|
setToMultipleID("editorButton", "removeClass", 'checked');
|
|
splitInstance.collapse(0);
|
|
splitInstance.collapse(0);
|
|
- setToMultipleID("editorButton", "innerHTML", 'Editor <i class="far fa-square" aria-hidden="true"></i>');
|
|
|
|
|
|
+ setToMultipleID("editorButton", "innerHTML", 'Editor <i class="fa fa-square" aria-hidden="true"></i>');
|
|
} else {
|
|
} else {
|
|
setToMultipleID("editorButton", "addClass", 'checked');
|
|
setToMultipleID("editorButton", "addClass", 'checked');
|
|
splitInstance.setSizes([50, 50]); // Reset
|
|
splitInstance.setSizes([50, 50]); // Reset
|
|
@@ -911,15 +1002,20 @@ function showError(errorMessage, errorEvent) {
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * Toggle the dark theme
|
|
|
|
|
|
+ * Set the theme (dark / light)
|
|
*/
|
|
*/
|
|
- var toggleTheme = function(theme) {
|
|
|
|
|
|
+ var toggleTheme = function (theme) {
|
|
|
|
+ setToMultipleID("darkTheme", "removeClass", "selected");
|
|
|
|
+ setToMultipleID("lightTheme", "removeClass", "selected");
|
|
|
|
+
|
|
// Monaco
|
|
// Monaco
|
|
var vsTheme;
|
|
var vsTheme;
|
|
if (theme == 'dark') {
|
|
if (theme == 'dark') {
|
|
vsTheme = 'vs-dark'
|
|
vsTheme = 'vs-dark'
|
|
|
|
+ setToMultipleID("darkTheme", "addClass", "selected");
|
|
} else {
|
|
} else {
|
|
vsTheme = 'vs'
|
|
vsTheme = 'vs'
|
|
|
|
+ setToMultipleID("lightTheme", "addClass", "selected");
|
|
}
|
|
}
|
|
|
|
|
|
var oldCode = jsEditor.getValue();
|
|
var oldCode = jsEditor.getValue();
|
|
@@ -943,12 +1039,12 @@ function showError(errorMessage, errorEvent) {
|
|
enabled: true
|
|
enabled: true
|
|
}
|
|
}
|
|
};
|
|
};
|
|
- editorOptions.minimap.enabled = document.getElementById("minimapToggle1600").classList.contains('checked');
|
|
|
|
|
|
+ editorOptions.minimap.enabled = document.getElementById("minimapToggle1280").classList.contains('checked');
|
|
jsEditor = monaco.editor.create(document.getElementById('jsEditor'), editorOptions);
|
|
jsEditor = monaco.editor.create(document.getElementById('jsEditor'), editorOptions);
|
|
jsEditor.setValue(oldCode);
|
|
jsEditor.setValue(oldCode);
|
|
setFontSize(fontSize);
|
|
setFontSize(fontSize);
|
|
|
|
|
|
- jsEditor.onKeyUp(function(evt) {
|
|
|
|
|
|
+ jsEditor.onKeyUp(function (evt) {
|
|
markDirty();
|
|
markDirty();
|
|
});
|
|
});
|
|
|
|
|
|
@@ -965,8 +1061,32 @@ function showError(errorMessage, errorEvent) {
|
|
|
|
|
|
localStorage.setItem("bjs-playground-theme", theme);
|
|
localStorage.setItem("bjs-playground-theme", theme);
|
|
}
|
|
}
|
|
|
|
+ /**
|
|
|
|
+ * Toggle Typescript / Javascript language
|
|
|
|
+ */
|
|
|
|
+ var togglescriptLanguage = function (scriptLanguage) {
|
|
|
|
+ for (var index = 0; index < elementForscriptLanguage.length; index++) {
|
|
|
|
+ var obj = elementForscriptLanguage[index];
|
|
|
|
+ var domObjArr = document.querySelectorAll(obj);
|
|
|
|
+ for (var domObjIndex = 0; domObjIndex < domObjArr.length; domObjIndex++) {
|
|
|
|
+ var domObj = domObjArr[domObjIndex];
|
|
|
|
+ domObj.classList.remove('languageJS');
|
|
|
|
+ domObj.classList.remove('languageTS');
|
|
|
|
+ domObj.classList.add("language" + scriptLanguage);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (scriptLanguage == "JS") {
|
|
|
|
+ setToMultipleID("toJSbutton", "removeClass", "floatLeft");
|
|
|
|
+ }
|
|
|
|
+ else if (scriptLanguage == "TS") {
|
|
|
|
+ setToMultipleID("toJSbutton", "addClass", "floatLeft");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ localStorage.setItem("bjs-playground-scriptLanguage", scriptLanguage);
|
|
|
|
+ }
|
|
|
|
|
|
- var toggleDebug = function() {
|
|
|
|
|
|
+ var toggleDebug = function () {
|
|
// Always showing the debug layer, because you can close it by itself
|
|
// Always showing the debug layer, because you can close it by itself
|
|
var scene = engine.scenes[0];
|
|
var scene = engine.scenes[0];
|
|
if (scene.debugLayer.isVisible()) {
|
|
if (scene.debugLayer.isVisible()) {
|
|
@@ -977,20 +1097,20 @@ function showError(errorMessage, errorEvent) {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- var toggleMetadata = function() {
|
|
|
|
|
|
+ var toggleMetadata = function () {
|
|
var scene = engine.scenes[0];
|
|
var scene = engine.scenes[0];
|
|
document.getElementById("saveLayer").style.display = "block";
|
|
document.getElementById("saveLayer").style.display = "block";
|
|
}
|
|
}
|
|
|
|
|
|
- var formatCode = function() {
|
|
|
|
|
|
+ var formatCode = function () {
|
|
jsEditor.getAction('editor.action.formatDocument').run();
|
|
jsEditor.getAction('editor.action.formatDocument').run();
|
|
}
|
|
}
|
|
|
|
|
|
- var toggleMinimap = function() {
|
|
|
|
- var minimapToggle = document.getElementById("minimapToggle1600");
|
|
|
|
|
|
+ var toggleMinimap = function () {
|
|
|
|
+ var minimapToggle = document.getElementById("minimapToggle1280");
|
|
if (minimapToggle.classList.contains('checked')) {
|
|
if (minimapToggle.classList.contains('checked')) {
|
|
jsEditor.updateOptions({ minimap: { enabled: false } });
|
|
jsEditor.updateOptions({ minimap: { enabled: false } });
|
|
- setToMultipleID("minimapToggle", "innerHTML", 'Minimap <i class="far fa-square" aria-hidden="true"></i>');
|
|
|
|
|
|
+ setToMultipleID("minimapToggle", "innerHTML", 'Minimap <i class="fa fa-square" aria-hidden="true"></i>');
|
|
} else {
|
|
} else {
|
|
jsEditor.updateOptions({ minimap: { enabled: true } });
|
|
jsEditor.updateOptions({ minimap: { enabled: true } });
|
|
setToMultipleID("minimapToggle", "innerHTML", 'Minimap <i class="fa fa-check-square" aria-hidden="true"></i>');
|
|
setToMultipleID("minimapToggle", "innerHTML", 'Minimap <i class="fa fa-check-square" aria-hidden="true"></i>');
|
|
@@ -1000,8 +1120,8 @@ function showError(errorMessage, errorEvent) {
|
|
|
|
|
|
|
|
|
|
//Navigation Overwrites
|
|
//Navigation Overwrites
|
|
- var exitPrompt = function(e) {
|
|
|
|
- var safeToggle = document.getElementById("safemodeToggle1600");
|
|
|
|
|
|
+ var exitPrompt = function (e) {
|
|
|
|
+ var safeToggle = document.getElementById("safemodeToggle1280");
|
|
if (safeToggle.classList.contains('checked')) {
|
|
if (safeToggle.classList.contains('checked')) {
|
|
e = e || window.event;
|
|
e = e || window.event;
|
|
var message =
|
|
var message =
|
|
@@ -1016,7 +1136,7 @@ function showError(errorMessage, errorEvent) {
|
|
window.onbeforeunload = exitPrompt;
|
|
window.onbeforeunload = exitPrompt;
|
|
|
|
|
|
// Snippet
|
|
// Snippet
|
|
- var save = function() {
|
|
|
|
|
|
+ var save = function () {
|
|
|
|
|
|
// Retrieve title if necessary
|
|
// Retrieve title if necessary
|
|
if (document.getElementById("saveLayer")) {
|
|
if (document.getElementById("saveLayer")) {
|
|
@@ -1026,7 +1146,7 @@ function showError(errorMessage, errorEvent) {
|
|
}
|
|
}
|
|
|
|
|
|
var xmlHttp = new XMLHttpRequest();
|
|
var xmlHttp = new XMLHttpRequest();
|
|
- xmlHttp.onreadystatechange = function() {
|
|
|
|
|
|
+ xmlHttp.onreadystatechange = function () {
|
|
if (xmlHttp.readyState === 4) {
|
|
if (xmlHttp.readyState === 4) {
|
|
if (xmlHttp.status === 200) {
|
|
if (xmlHttp.status === 200) {
|
|
var baseUrl = location.href.replace(location.hash, "").replace(location.search, "");
|
|
var baseUrl = location.href.replace(location.hash, "").replace(location.search, "");
|
|
@@ -1061,7 +1181,7 @@ function showError(errorMessage, errorEvent) {
|
|
xmlHttp.send(JSON.stringify(dataToSend));
|
|
xmlHttp.send(JSON.stringify(dataToSend));
|
|
}
|
|
}
|
|
|
|
|
|
- var askForSave = function() {
|
|
|
|
|
|
+ var askForSave = function () {
|
|
if (currentSnippetTitle == null
|
|
if (currentSnippetTitle == null
|
|
|| currentSnippetDescription == null
|
|
|| currentSnippetDescription == null
|
|
|| currentSnippetTags == null) {
|
|
|| currentSnippetTags == null) {
|
|
@@ -1072,18 +1192,18 @@ function showError(errorMessage, errorEvent) {
|
|
save();
|
|
save();
|
|
}
|
|
}
|
|
};
|
|
};
|
|
- document.getElementById("saveFormButtonOk").addEventListener("click", function() {
|
|
|
|
|
|
+ document.getElementById("saveFormButtonOk").addEventListener("click", function () {
|
|
document.getElementById("saveLayer").style.display = "none";
|
|
document.getElementById("saveLayer").style.display = "none";
|
|
save();
|
|
save();
|
|
});
|
|
});
|
|
- document.getElementById("saveFormButtonCancel").addEventListener("click", function() {
|
|
|
|
|
|
+ document.getElementById("saveFormButtonCancel").addEventListener("click", function () {
|
|
document.getElementById("saveLayer").style.display = "none";
|
|
document.getElementById("saveLayer").style.display = "none";
|
|
});
|
|
});
|
|
- document.getElementById("mainTitle").innerHTML = "v" + BABYLON.Engine.Version;
|
|
|
|
|
|
+ setToMultipleID("mainTitle", "innerHTML", "v" + BABYLON.Engine.Version);
|
|
|
|
|
|
var previousHash = "";
|
|
var previousHash = "";
|
|
|
|
|
|
- var cleanHash = function() {
|
|
|
|
|
|
+ var cleanHash = function () {
|
|
var splits = decodeURIComponent(location.hash.substr(1)).split("#");
|
|
var splits = decodeURIComponent(location.hash.substr(1)).split("#");
|
|
|
|
|
|
if (splits.length > 2) {
|
|
if (splits.length > 2) {
|
|
@@ -1093,7 +1213,7 @@ function showError(errorMessage, errorEvent) {
|
|
location.hash = splits.join("#");
|
|
location.hash = splits.join("#");
|
|
}
|
|
}
|
|
|
|
|
|
- var checkHash = function(firstTime) {
|
|
|
|
|
|
+ var checkHash = function (firstTime) {
|
|
if (location.hash) {
|
|
if (location.hash) {
|
|
if (previousHash !== location.hash) {
|
|
if (previousHash !== location.hash) {
|
|
cleanHash();
|
|
cleanHash();
|
|
@@ -1102,7 +1222,7 @@ function showError(errorMessage, errorEvent) {
|
|
|
|
|
|
try {
|
|
try {
|
|
var xmlHttp = new XMLHttpRequest();
|
|
var xmlHttp = new XMLHttpRequest();
|
|
- xmlHttp.onreadystatechange = function() {
|
|
|
|
|
|
+ xmlHttp.onreadystatechange = function () {
|
|
if (xmlHttp.readyState === 4) {
|
|
if (xmlHttp.readyState === 4) {
|
|
if (xmlHttp.status === 200) {
|
|
if (xmlHttp.status === 200) {
|
|
|
|
|
|
@@ -1184,16 +1304,43 @@ function showError(errorMessage, errorEvent) {
|
|
setToMultipleID("saveButton", "click", askForSave);
|
|
setToMultipleID("saveButton", "click", askForSave);
|
|
// Zip
|
|
// Zip
|
|
setToMultipleID("zipButton", "click", getZip);
|
|
setToMultipleID("zipButton", "click", getZip);
|
|
- // Themes
|
|
|
|
- setToMultipleID("darkTheme", "click", toggleTheme.bind(this, 'dark'));
|
|
|
|
- setToMultipleID("lightTheme", "click", toggleTheme.bind(this, 'light'));
|
|
|
|
|
|
+ // // Themes
|
|
|
|
+ setToMultipleID("darkTheme", "click", [toggleTheme.bind(this, 'dark'), clickOptionSub]);
|
|
|
|
+ setToMultipleID("lightTheme", "click", [toggleTheme.bind(this, 'light'), clickOptionSub]);
|
|
|
|
+ // Size
|
|
|
|
+ var displayFontSize = document.getElementsByClassName('displayFontSize');
|
|
|
|
+ for (var i = 0; i < displayFontSize.length; i++) {
|
|
|
|
+ var options = displayFontSize[i].querySelectorAll('.option');
|
|
|
|
+ for (var j = 0; j < options.length; j++) {
|
|
|
|
+ options[j].addEventListener('click', clickOptionSub);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // Footer links
|
|
|
|
+ var displayFontSize = document.getElementsByClassName('displayFooterLinks');
|
|
|
|
+ for (var i = 0; i < displayFontSize.length; i++) {
|
|
|
|
+ var options = displayFontSize[i].querySelectorAll('.option');
|
|
|
|
+ for (var j = 0; j < options.length; j++) {
|
|
|
|
+ options[j].addEventListener('click', clickOptionSub);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // Language (JS / TS)
|
|
|
|
+ setToMultipleID("toTSbutton", "click", function () {
|
|
|
|
+ localStorage.setItem("bjs-playground-scriptLanguage", "TS");
|
|
|
|
+ if (confirm("You need to reload the page to switch to Typescript. Do you want to reload now ?"))
|
|
|
|
+ location.reload();
|
|
|
|
+ });
|
|
|
|
+ setToMultipleID("toJSbutton", "click", function () {
|
|
|
|
+ localStorage.setItem("bjs-playground-scriptLanguage", "JS");
|
|
|
|
+ if (confirm("You need to reload the page to switch to Javascript. Do you want to reload now ?"))
|
|
|
|
+ location.reload();
|
|
|
|
+ });
|
|
// Safe mode
|
|
// Safe mode
|
|
- setToMultipleID("safemodeToggle", 'click', function() {
|
|
|
|
- document.getElementById("safemodeToggle1600").classList.toggle('checked');
|
|
|
|
- if (document.getElementById("safemodeToggle1600").classList.contains('checked')) {
|
|
|
|
|
|
+ setToMultipleID("safemodeToggle", 'click', function () {
|
|
|
|
+ document.getElementById("safemodeToggle1280").classList.toggle('checked');
|
|
|
|
+ if (document.getElementById("safemodeToggle1280").classList.contains('checked')) {
|
|
setToMultipleID("safemodeToggle", "innerHTML", 'Safe mode <i class="fa fa-check-square" aria-hidden="true"></i>');
|
|
setToMultipleID("safemodeToggle", "innerHTML", 'Safe mode <i class="fa fa-check-square" aria-hidden="true"></i>');
|
|
} else {
|
|
} else {
|
|
- setToMultipleID("safemodeToggle", "innerHTML", 'Safe mode <i class="far fa-square" aria-hidden="true"></i>');
|
|
|
|
|
|
+ setToMultipleID("safemodeToggle", "innerHTML", 'Safe mode <i class="fa fa-square" aria-hidden="true"></i>');
|
|
}
|
|
}
|
|
});
|
|
});
|
|
// Editor
|
|
// Editor
|
|
@@ -1216,6 +1363,9 @@ function showError(errorMessage, errorEvent) {
|
|
var theme = localStorage.getItem("bjs-playground-theme") || 'light';
|
|
var theme = localStorage.getItem("bjs-playground-theme") || 'light';
|
|
toggleTheme(theme);
|
|
toggleTheme(theme);
|
|
toggleMinimap();
|
|
toggleMinimap();
|
|
|
|
+ // Restore language
|
|
|
|
+ scriptLanguage = localStorage.getItem("bjs-playground-scriptLanguage") || 'JS';
|
|
|
|
+ togglescriptLanguage(scriptLanguage);
|
|
}
|
|
}
|
|
|
|
|
|
// Monaco
|
|
// Monaco
|
|
@@ -1224,11 +1374,11 @@ function showError(errorMessage, errorEvent) {
|
|
|
|
|
|
xhr.open('GET', "babylon.d.txt", true);
|
|
xhr.open('GET', "babylon.d.txt", true);
|
|
|
|
|
|
- xhr.onreadystatechange = function() {
|
|
|
|
|
|
+ xhr.onreadystatechange = function () {
|
|
if (xhr.readyState === 4) {
|
|
if (xhr.readyState === 4) {
|
|
if (xhr.status === 200) {
|
|
if (xhr.status === 200) {
|
|
require.config({ paths: { 'vs': 'node_modules/monaco-editor/min/vs' } });
|
|
require.config({ paths: { 'vs': 'node_modules/monaco-editor/min/vs' } });
|
|
- require(['vs/editor/editor.main'], function() {
|
|
|
|
|
|
+ require(['vs/editor/editor.main'], function () {
|
|
if (monacoMode === "javascript") {
|
|
if (monacoMode === "javascript") {
|
|
monaco.languages.typescript.javascriptDefaults.addExtraLib(xhr.responseText, 'babylon.d.ts');
|
|
monaco.languages.typescript.javascriptDefaults.addExtraLib(xhr.responseText, 'babylon.d.ts');
|
|
} else {
|
|
} else {
|