diff options
author | HombreLaser <sebastian-440@live.com> | 2024-02-27 11:18:43 -0600 |
---|---|---|
committer | HombreLaser <sebastian-440@live.com> | 2024-02-27 11:18:43 -0600 |
commit | 8690226ec041c28a21cb5267b69632ecc280a089 (patch) | |
tree | 53bcc1297efb6f0f6f48c7143b9ee5315f68824c /static/js/controllers/base_controller.js | |
parent | 1a306a0a6c714242c97e0db45adb0c8af0dada4a (diff) |
Improve coments pagination
Diffstat (limited to 'static/js/controllers/base_controller.js')
-rw-r--r-- | static/js/controllers/base_controller.js | 40 |
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; } - } + } } |