From a4dbf1cd8d0769b1ff1e0d99217f92b28b92e0d4 Mon Sep 17 00:00:00 2001 From: HombreLaser Date: Wed, 7 Feb 2024 12:39:56 -0600 Subject: Add javascript entrypoint --- static/js/comments/comment_form.js | 12 +++++++++--- static/js/main.js | 6 ++++++ 2 files changed, 15 insertions(+), 3 deletions(-) create mode 100644 static/js/main.js (limited to 'static/js') diff --git a/static/js/comments/comment_form.js b/static/js/comments/comment_form.js index dff0803..6edde9f 100644 --- a/static/js/comments/comment_form.js +++ b/static/js/comments/comment_form.js @@ -2,8 +2,9 @@ class CommentForm { constructor(domain, post) { this.domain = domain; this.post = post; + this.parser = new DOMParser(); this.form_element = document.getElementById("comment-form"); - this.form_element.addEventListener("submit", this.submit); + this.form_element.addEventListener("submit", this.submit.bind(this)); } async submit(event) { @@ -19,7 +20,12 @@ class CommentForm { }, body: form }); - const body = response.body; + const response_page = this.htmlFromResponse(response.body); } catch(error) {} } -} + + htmlFromResponse(body) { + return this.parser.parseFromString(body, "text/html"); + } + } + diff --git a/static/js/main.js b/static/js/main.js new file mode 100644 index 0000000..cfb02dc --- /dev/null +++ b/static/js/main.js @@ -0,0 +1,6 @@ +import CommentForm from "./comments/comment_form"; + + +const post = window.location.pathname; +const domain = window.location.hostname; +new CommentForm(domain, post); -- cgit v1.2.3