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