summaryrefslogtreecommitdiff
path: root/assets/js/blog.js
diff options
context:
space:
mode:
authorMhykol <mchaeldonald62@pm.me>2024-06-10 04:38:00 -0400
committerMhykol <mchaeldonald62@pm.me>2024-06-10 04:38:00 -0400
commit0e26143bf99a9c7a33aa55ffba7327176c03e74d (patch)
tree2bc9c480f89acdd06b3b666d1f64b66f692bf95a /assets/js/blog.js
parent71bf9554707d096dd367cd0227853106b2a5fad7 (diff)
Added loading screen
Diffstat (limited to 'assets/js/blog.js')
-rw-r--r--assets/js/blog.js56
1 files changed, 56 insertions, 0 deletions
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()
+