aboutsummaryrefslogtreecommitdiff
path: root/app/javascript/controllers/comment_controller.js
diff options
context:
space:
mode:
authorMiquel Sabaté Solà <msabate@suse.com>2024-03-13 18:03:43 +0100
committerMiquel Sabaté Solà <msabate@suse.com>2024-03-13 18:03:43 +0100
commita7791635aa98f012d35f97c3c5288494bbb28e38 (patch)
treebad987e6b4d10ad2f7cd02e40658d464907595ee /app/javascript/controllers/comment_controller.js
downloadoperum-a7791635aa98f012d35f97c3c5288494bbb28e38.tar.gz
operum-a7791635aa98f012d35f97c3c5288494bbb28e38.zip
Initial commit
Signed-off-by: Miquel Sabaté Solà <msabate@suse.com>
Diffstat (limited to 'app/javascript/controllers/comment_controller.js')
-rw-r--r--app/javascript/controllers/comment_controller.js36
1 files changed, 36 insertions, 0 deletions
diff --git a/app/javascript/controllers/comment_controller.js b/app/javascript/controllers/comment_controller.js
new file mode 100644
index 0000000..22167c8
--- /dev/null
+++ b/app/javascript/controllers/comment_controller.js
@@ -0,0 +1,36 @@
+import { Controller } from "@hotwired/stimulus"
+
+// Controller that handles actions for adding some dynamism like showing/hiding
+// comments.
+export default class extends Controller {
+ // Cancel the current operation for comments.
+ toggle(event) {
+ event.preventDefault();
+
+ const parent = event.target.closest('.comment');
+ const regl_body = parent.getElementsByClassName('comment-body');
+ const edit_body = parent.getElementsByClassName('comment-edit-body');
+ if (regl_body.length !== 1 || edit_body.length !== 1) {
+ return;
+ }
+
+ regl_body[0].classList.toggle('hidden');
+ edit_body[0].classList.toggle('hidden');
+ }
+
+ // Hide/show the "New comment" button & form properly, while also focusing on
+ // the text area when shown.
+ toggleNewComment(event) {
+ event.preventDefault();
+
+ document.getElementById("comment-new-button").classList.toggle('hidden');
+
+ let body = document.getElementById("comment-new-body");
+ body.classList.toggle('hidden');
+
+ // BUG (minor): this is not working! (bug in Trix?)
+ if (!body.classList.contains("hidden")) {
+ document.getElementById("comment_content").focus();
+ }
+ }
+}