Add floating window for new threads

New threads get a floating window just like new replies have. This only
pops up on the board detail view.

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
2022-06-28 23:55:44 -07:00
parent 6ad2a72b86
commit 6c11d210e8
8 changed files with 151 additions and 58 deletions

View File

@@ -1,6 +1,7 @@
const OPEN = "open";
const CLOSED = "closed";
const replyWindowName = "reply-window";
const postWindowName = "post-window";
function documentClick(e) {
let sender = e.target;
@@ -59,7 +60,7 @@ function openReplyWindow(replyUrl) {
if (window.top.jsFrame.containsWindowName(replyWindowName)) {
// if there's already a new reply window, don't override it and just let
// it continue to exist.
return;
return getReplyWindow();
}
let replyWindow = window.top.jsFrame.create({
@@ -70,6 +71,7 @@ function openReplyWindow(replyUrl) {
url: replyUrl
});
replyWindow.show();
return replyWindow;
}
function getReplyWindow() {
@@ -77,18 +79,49 @@ function getReplyWindow() {
}
function replyTextbox() {
return $("iframe").contents().find("#id_text");
replyWindow = getReplyWindow();
if (!replyWindow) {
return null;
}
return replyWindow.$("#id_text")
}
function replyAppend(toAdd) {
let replyWindow = getReplyWindow();
let textbox = replyTextbox();
if (textbox.length === 0) {
if (!textbox) {
$(replyWindow.iframe, "#id_text").on("load", (e) => {
replyAppend(toAdd);
})
} else {
let caret = textbox.selectionStart;
textbox = $(textbox);
let text = textbox.val();
textbox.val(text.substring(0, caret) + toAdd + text.substring(caret));
textbox.focus();
}
}
////////////////////////////////////////////////////////////////////////////////
// Reply window
////////////////////////////////////////////////////////////////////////////////
function openPostWindow(postUrl) {
if (window.top.jsFrame.containsWindowName(postWindowName)) {
return;
}
let caret = textbox[0].selectionStart;
let text = textbox.val();
textbox.val(text.substring(0, caret) + toAdd + text.substring(caret));
textbox.focus();
let postWindow = window.top.jsFrame.create({
title: "New Thread",
name: postWindowName,
width: 385,
height: 350,
url: postUrl,
});
postWindow.show();
}
function getPostWindow() {
return window.top.jsFrame.getWindowByName(postWindowName);
}
////////////////////////////////////////////////////////////////////////////////