Created
September 2, 2020 12:02
-
-
Save MartinBspheroid/f50ba761b491244fedbda6d2e6af19e6 to your computer and use it in GitHub Desktop.
Revisions
-
MartinBspheroid created this gist
Sep 2, 2020 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,43 @@ class Fetcher { constructor(scenesObj, startScene = 0) { this.scenes = scenesObj; this.currentScene = startScene this.init() } init() { this.target = document.createElement("div") this.target.id = "stage" document.body.appendChild(this.target) this.loadScene(this.scenes[this.currentScene].page, this.scenes[this.currentScene].script); } loadScene(path, jsPath, ) { fetch(path /*, options */) .then((response) => response.text()) .then((html) => { this.target.innerHTML = html; let newScript = document.createElement("script"); newScript.src = jsPath; this.target.appendChild(newScript); }) .catch((error) => { console.warn(error); }); } loadSceneNumber(num){ this.loadNextScene(this.scenes[num].page, this.scenes[num].script) } loadNextScene() { this.currentScene += 1 this.loadScene(this.scenes[this.currentScene].page, this.scenes[this.currentScene].script, this.scenes[this.currentScene]?.req); console.log(this.scenes[this.currentScene]) } }