Skip to content

Instantly share code, notes, and snippets.

@MartinBspheroid
Created September 2, 2020 12:02
Show Gist options
  • Save MartinBspheroid/f50ba761b491244fedbda6d2e6af19e6 to your computer and use it in GitHub Desktop.
Save MartinBspheroid/f50ba761b491244fedbda6d2e6af19e6 to your computer and use it in GitHub Desktop.
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])
}
}
@MartinBspheroid
Copy link
Author

simple and dirty way how to compose webpages

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment