42 lines
1.4 KiB
JavaScript
42 lines
1.4 KiB
JavaScript
// 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();
|
|
});
|
|
});
|
|
}); |