diff --git a/web/static/js/inline-replies.js b/web/static/js/inline-replies.js new file mode 100644 index 0000000..c2f4c74 --- /dev/null +++ b/web/static/js/inline-replies.js @@ -0,0 +1,42 @@ +// nonshy inline "Quote" and "Reply" buttons that activate the comment field +// on the current page. Common logic between forum threads and photo comments. + +document.addEventListener('DOMContentLoaded', function() { + const $message = document.querySelector("#message"); + + // Enhance the in-post Quote and Reply buttons to activate the reply field + // at the page header instead of going to the dedicated comment page. + (document.querySelectorAll(".nonshy-quote-button") || []).forEach(node => { + const message = node.dataset.quoteBody, + replyTo = node.dataset.replyTo; + + node.addEventListener("click", (e) => { + e.preventDefault(); + + if (replyTo) { + $message.value += "@" + replyTo + "\n\n"; + } + + // Prepare the quoted message. + var lines = []; + for (let line of message.split("\n")) { + lines.push("> " + line); + } + + $message.value += lines.join("\n") + "\n\n"; + $message.scrollIntoView(); + $message.focus(); + }); + }); + + (document.querySelectorAll(".nonshy-reply-button") || []).forEach(node => { + const replyTo = node.dataset.replyTo; + + node.addEventListener("click", (e) => { + e.preventDefault(); + $message.value += "@" + replyTo + "\n\n"; + $message.scrollIntoView(); + $message.focus(); + }); + }); +}); \ No newline at end of file diff --git a/web/templates/forum/thread.html b/web/templates/forum/thread.html index dae3f7c..2de118a 100644 --- a/web/templates/forum/thread.html +++ b/web/templates/forum/thread.html @@ -268,7 +268,7 @@ {{if not $Root.Thread.NoReply}}
+ class="has-text-dark nonshy-quote-button" data-quote-body="{{.Message}}" data-reply-to="{{.User.Username}}"> Quote @@ -425,42 +425,8 @@
{{end}} - + + {{if .Forum.PermitPhotos}} diff --git a/web/templates/photo/permalink.html b/web/templates/photo/permalink.html index 6abbd40..bc62d03 100644 --- a/web/templates/photo/permalink.html +++ b/web/templates/photo/permalink.html @@ -311,6 +311,21 @@ +
+ + + Quote + +
+
+ + + Reply + +
+ {{if or $Root.CurrentUser.IsAdmin (eq $Root.CurrentUser.ID .User.ID)}}
@@ -370,6 +385,9 @@
+ + + {{template "mark-explicit-modal" .}} {{end}}