Created
September 2, 2020 12:02
-
-
Save MartinBspheroid/f50ba761b491244fedbda6d2e6af19e6 to your computer and use it in GitHub Desktop.
This file contains 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 characters
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]) | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
simple and dirty way how to compose webpages