|
@@ -229,6 +229,17 @@ class Main {
|
|
|
this.fpsLabel = document.getElementById("fpsLabel");
|
|
|
this.scripts;
|
|
|
this.previousHash = "";
|
|
|
+
|
|
|
+ // Restore BJS version if needed
|
|
|
+ var restoreVersionResult = true;
|
|
|
+ if (this.parent.settingsPG.restoreVersion() == false) {
|
|
|
+ // Check if there a hash in the URL
|
|
|
+ this.checkHash();
|
|
|
+ restoreVersionResult = false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // Load scripts list
|
|
|
+ this.loadScriptsList(restoreVersionResult);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -266,17 +277,6 @@ class Main {
|
|
|
}.bind(this)
|
|
|
);
|
|
|
|
|
|
- // Restore BJS version if needed
|
|
|
- var restoreVersionResult = true;
|
|
|
- if (this.parent.settingsPG.restoreVersion() == false) {
|
|
|
- // Check if there a hash in the URL
|
|
|
- this.checkHash();
|
|
|
- restoreVersionResult = false;
|
|
|
- }
|
|
|
-
|
|
|
- // Load scripts list
|
|
|
- this.loadScriptsList(restoreVersionResult);
|
|
|
-
|
|
|
// -------------------- UI --------------------
|
|
|
var handleRun = () => compileAndRun(this.parent, this.fpsLabel);
|
|
|
var handleSave = () => this.askForSave();
|
|
@@ -336,53 +336,56 @@ class Main {
|
|
|
}
|
|
|
}
|
|
|
// Language (JS / TS)
|
|
|
- this.parent.utils.setToMultipleID("toTSbutton", "click", function () {
|
|
|
- if (location.hash != null && location.hash != "") {
|
|
|
- this.parent.settingsPG.ScriptLanguage = "TS";
|
|
|
- window.location = "./";
|
|
|
- } else {
|
|
|
- if (this.parent.settingsPG.ScriptLanguage == "JS") {
|
|
|
- //revert in case the reload is cancel due to safe mode
|
|
|
- if (document.getElementById("safemodeToggle" + this.parent.utils.getCurrentSize()).classList.contains('checked')) {
|
|
|
- // Message before unload
|
|
|
- var languageTSswapper = function () {
|
|
|
+ if (this.parent.settingsPG.ScriptLanguage === "JS") {
|
|
|
+ this.parent.utils.setToMultipleID("toTSbutton", "click", function () {
|
|
|
+ if (location.hash != null && location.hash != "") {
|
|
|
+ this.parent.settingsPG.ScriptLanguage = "TS";
|
|
|
+ window.location = "./";
|
|
|
+ } else {
|
|
|
+ if (this.parent.settingsPG.ScriptLanguage == "JS") {
|
|
|
+ //revert in case the reload is cancel due to safe mode
|
|
|
+ if (document.getElementById("safemodeToggle" + this.parent.utils.getCurrentSize()).classList.contains('checked')) {
|
|
|
+ // Message before unload
|
|
|
+ var languageTSswapper = function () {
|
|
|
+ this.parent.settingsPG.ScriptLanguage = "TS";
|
|
|
+ window.removeEventListener('unload', languageTSswapper.bind(this));
|
|
|
+ };
|
|
|
+ window.addEventListener('unload', languageTSswapper.bind(this));
|
|
|
+
|
|
|
+ location.reload();
|
|
|
+ } else {
|
|
|
this.parent.settingsPG.ScriptLanguage = "TS";
|
|
|
- window.removeEventListener('unload', languageTSswapper.bind(this));
|
|
|
- };
|
|
|
- window.addEventListener('unload', languageTSswapper.bind(this));
|
|
|
-
|
|
|
- location.reload();
|
|
|
- } else {
|
|
|
- this.parent.settingsPG.ScriptLanguage = "TS";
|
|
|
- location.reload();
|
|
|
+ location.reload();
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- }.bind(this));
|
|
|
- this.parent.utils.setToMultipleID("toJSbutton", "click", function () {
|
|
|
- if (location.hash != null && location.hash != "") {
|
|
|
- this.parent.settingsPG.ScriptLanguage = "JS";
|
|
|
- window.location = "./";
|
|
|
- } else {
|
|
|
- if (this.parent.settingsPG.ScriptLanguage == "TS") {
|
|
|
- //revert in case the reload is cancel due to safe mode
|
|
|
- if (document.getElementById("safemodeToggle" + this.parent.utils.getCurrentSize()).classList.contains('checked')) {
|
|
|
- // Message before unload
|
|
|
- var LanguageJSswapper = function () {
|
|
|
+ }.bind(this));
|
|
|
+ } else {
|
|
|
+ this.parent.utils.setToMultipleID("toJSbutton", "click", function () {
|
|
|
+ if (location.hash != null && location.hash != "") {
|
|
|
+ this.parent.settingsPG.ScriptLanguage = "JS";
|
|
|
+ window.location = "./";
|
|
|
+ } else {
|
|
|
+ if (this.parent.settingsPG.ScriptLanguage == "TS") {
|
|
|
+ //revert in case the reload is cancel due to safe mode
|
|
|
+ if (document.getElementById("safemodeToggle" + this.parent.utils.getCurrentSize()).classList.contains('checked')) {
|
|
|
+ // Message before unload
|
|
|
+ var LanguageJSswapper = function () {
|
|
|
+ this.parent.settingsPG.ScriptLanguage = "JS";
|
|
|
+ window.removeEventListener('unload', LanguageJSswapper.bind(this));
|
|
|
+ };
|
|
|
+ window.addEventListener('unload', LanguageJSswapper.bind(this));
|
|
|
+
|
|
|
+ location.reload();
|
|
|
+ } else {
|
|
|
this.parent.settingsPG.ScriptLanguage = "JS";
|
|
|
- window.removeEventListener('unload', LanguageJSswapper.bind(this));
|
|
|
- };
|
|
|
- window.addEventListener('unload', LanguageJSswapper.bind(this));
|
|
|
-
|
|
|
- location.reload();
|
|
|
- } else {
|
|
|
- this.parent.settingsPG.ScriptLanguage = "JS";
|
|
|
- location.reload();
|
|
|
+ location.reload();
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
- }.bind(this));
|
|
|
+ }.bind(this));
|
|
|
+ }
|
|
|
// Safe mode
|
|
|
this.parent.utils.setToMultipleID("safemodeToggle", 'click', function () {
|
|
|
document.getElementById("safemodeToggle1280").classList.toggle('checked');
|
|
@@ -497,14 +500,16 @@ class Main {
|
|
|
if (!this.checkTypescriptSupport(xhr)) return;
|
|
|
|
|
|
xhr.onreadystatechange = null;
|
|
|
- this.parent.monacoCreator.BlockEditorChange = true;
|
|
|
- this.parent.monacoCreator.JsEditor.setValue(xhr.responseText);
|
|
|
- this.parent.monacoCreator.JsEditor.setPosition({
|
|
|
- lineNumber: 0,
|
|
|
- column: 0
|
|
|
- });
|
|
|
- this.parent.monacoCreator.BlockEditorChange = false;
|
|
|
- compileAndRun(this.parent, this.fpsLabel);
|
|
|
+ this.parent.monacoCreator.addOnMoncaoLoadedCallback(function () {
|
|
|
+ this.parent.monacoCreator.BlockEditorChange = true;
|
|
|
+ this.parent.monacoCreator.JsEditor.setValue(xhr.responseText);
|
|
|
+ this.parent.monacoCreator.JsEditor.setPosition({
|
|
|
+ lineNumber: 0,
|
|
|
+ column: 0
|
|
|
+ });
|
|
|
+ this.parent.monacoCreator.BlockEditorChange = false;
|
|
|
+ compileAndRun(this.parent, this.fpsLabel);
|
|
|
+ }, this);
|
|
|
|
|
|
this.currentSnippetToken = null;
|
|
|
}
|
|
@@ -1074,8 +1079,8 @@ class Main {
|
|
|
}
|
|
|
if (pgHash) {
|
|
|
var match = pgHash.match(/^(#[A-Za-z\d]*)(%23)([\d]+)$/);
|
|
|
- if (match){
|
|
|
- pgHash = match[1]+'#'+match[3];
|
|
|
+ if (match) {
|
|
|
+ pgHash = match[1] + '#' + match[3];
|
|
|
parent.location.hash = pgHash;
|
|
|
}
|
|
|
this.previousHash = pgHash;
|
|
@@ -1096,9 +1101,6 @@ class Main {
|
|
|
|
|
|
var snippet = JSON.parse(xmlHttp.responseText);
|
|
|
|
|
|
- this.parent.monacoCreator.BlockEditorChange = true;
|
|
|
- this.parent.monacoCreator.JsEditor.setValue(JSON.parse(snippet.jsonPayload).code.toString());
|
|
|
-
|
|
|
// Check if title / descr / tags are already set
|
|
|
if (snippet.name != null && snippet.name != "") {
|
|
|
this.currentSnippetTitle = snippet.name;
|
|
@@ -1127,12 +1129,18 @@ class Main {
|
|
|
|
|
|
this.updateMetadata();
|
|
|
|
|
|
- this.parent.monacoCreator.JsEditor.setPosition({
|
|
|
- lineNumber: 0,
|
|
|
- column: 0
|
|
|
- });
|
|
|
- this.parent.monacoCreator.BlockEditorChange = false;
|
|
|
- compileAndRun(this.parent, this.fpsLabel);
|
|
|
+ this.parent.monacoCreator.addOnMoncaoLoadedCallback(function () {
|
|
|
+ this.parent.monacoCreator.BlockEditorChange = true;
|
|
|
+ this.parent.monacoCreator.JsEditor.setValue(JSON.parse(snippet.jsonPayload).code.toString());
|
|
|
+
|
|
|
+ this.parent.monacoCreator.JsEditor.setPosition({
|
|
|
+ lineNumber: 0,
|
|
|
+ column: 0
|
|
|
+ });
|
|
|
+ this.parent.monacoCreator.BlockEditorChange = false;
|
|
|
+ compileAndRun(this.parent, this.fpsLabel);
|
|
|
+ }, this);
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
}.bind(this);
|
|
@@ -1151,21 +1159,21 @@ class Main {
|
|
|
|
|
|
if (this.currentSnippetTitle) {
|
|
|
selection = document.querySelector('title');
|
|
|
- if(selection){
|
|
|
+ if (selection) {
|
|
|
selection.innerText = (this.currentSnippetTitle + " | Babylon.js Playground");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (this.currentSnippetDescription) {
|
|
|
selection = document.querySelector('meta[name="description"]');
|
|
|
- if(selection){
|
|
|
+ if (selection) {
|
|
|
selection.setAttribute("content", this.currentSnippetDescription + " - Babylon.js Playground");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (this.currentSnippetTags) {
|
|
|
selection = document.querySelector('meta[name="keywords"]');
|
|
|
- if(selection){
|
|
|
+ if (selection) {
|
|
|
selection.setAttribute("content", "babylon.js, game engine, webgl, 3d," + this.currentSnippetTags);
|
|
|
}
|
|
|
}
|