summaryrefslogtreecommitdiff
path: root/static/js/controllers/base_controller.js
diff options
context:
space:
mode:
Diffstat (limited to 'static/js/controllers/base_controller.js')
-rw-r--r--static/js/controllers/base_controller.js40
1 files changed, 20 insertions, 20 deletions
diff --git a/static/js/controllers/base_controller.js b/static/js/controllers/base_controller.js
index 2ef359c..40a16ca 100644
--- a/static/js/controllers/base_controller.js
+++ b/static/js/controllers/base_controller.js
@@ -1,5 +1,5 @@
export class BaseController {
- constructor() {
+ constructor() {
this.comments_server_url = document.getElementById('comments-client').src;
this.origin = window.location.origin;
this.protocol = this.getProtocol();
@@ -7,39 +7,39 @@ export class BaseController {
this.post = window.location.pathname;
this.comments_server_host = `${this.protocol}//${this.domain}`;
this.parser = new DOMParser();
- }
+ }
- async submit(event, route, form = new FormData(event.target)) {
+ async submit(event, route, form = new FormData(event.target)) {
event.preventDefault();
try {
- const response = await fetch(route, { method: "POST", body: form });
+ const response = await fetch(route, { method: "POST", body: form });
- response.text().then((response_document) => {
+ response.text().then((response_document) => {
this.renderSubmitResponse(response_document);
- });
- } catch(error) {}
- }
+ });
+ } catch (error) { }
+ }
- getDomain() {
+ getDomain() {
return this.comments_server_url.split('/')[2];
- }
+ }
- getProtocol() {
+ getProtocol() {
return this.comments_server_url.split('/')[0];
- }
+ }
- htmlFromResponse(body) {
+ htmlFromResponse(body) {
return this.parser.parseFromString(body, "text/html");
- }
+ }
- async get(route) {
+ async get(route) {
try {
- const response = await fetch(`${this.comments_server_host}${route}`);
+ const response = await fetch(`${this.comments_server_host}${route}`);
- return response.text().then(this.htmlFromResponse.bind(this));
- } catch(error) {
- return null;
+ return response.text().then(this.htmlFromResponse.bind(this));
+ } catch (error) {
+ return null;
}
- }
+ }
}