From 0e26143bf99a9c7a33aa55ffba7327176c03e74d Mon Sep 17 00:00:00 2001 From: Mhykol Date: Mon, 10 Jun 2024 04:38:00 -0400 Subject: Added loading screen --- assets/js/blog.js | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 assets/js/blog.js (limited to 'assets/js/blog.js') diff --git a/assets/js/blog.js b/assets/js/blog.js new file mode 100644 index 0000000..21d9e27 --- /dev/null +++ b/assets/js/blog.js @@ -0,0 +1,56 @@ +class Blog { + constructor() { + this.object = { + body: document.getElementsByTagName('body')[0], + section: document.getElementById('main'), + blogButtonList: document.getElementsByClassName('bloglistbutton') + } + } + + Init() {this.#EventListener()} + #EventListener() { + for (let i = 0; i < this.object.blogButtonList.length; i++) { + this.object.blogButtonList[i].addEventListener('click', () => { + new Loading().Start() + new Menu().HideIcon() + this.#GetBlog(this.object.blogButtonList[i].value) + }) + } + } + #GetUrl() { + if (window.location.href.endsWith('/')) { + return `${window.location.href}item` + } else { + return `${window.location.href}/item` + } + } + async #GetBlog(x) { + const object = { + url: this.#GetUrl(), + value: x + } + + await fetch(this.fetch, { + method: 'post', + body: JSON.stringify(object), + headers: new Headers({ + 'Content-Type': 'application/json' + }) + }) + .then(res => res.json()) + .then(output => { + const object = output.html + new Promise(res => { + const script = document.createElement('script') + script.src = `${window.location.origin}/js/blogitem.js` + this.object.body.appendChild(script) + script.onload = res + }).then(output => { + new BlogItem().Init(object) + }) + }) + } +} + +new Blog().Init() + -- cgit v1.2.3-70-g09d2