diff --git a/board/static/board/post.js b/board/static/board/post.js index 391ad5e..906a449 100644 --- a/board/static/board/post.js +++ b/board/static/board/post.js @@ -1,3 +1,4 @@ +const NAME_COOKIE = "posting_as"; const OPEN = "open"; const CLOSED = "closed"; const replyWindowName = "reply-window"; @@ -5,6 +6,35 @@ const postWindowName = "post-window"; const reportWindowName = "report-window" const WINDOW_INNER_PADDING = 25; + +//////////////////////////////////////////////////////////////////////////////// +// Cookie functions, stolen from W3Schools +//////////////////////////////////////////////////////////////////////////////// +function setCookie(cname, cvalue, expseconds) { + const d = new Date(); + d.setTime(d.getTime() + (expseconds * 1000)); + let expires = "expires=" + d.toUTCString(); + document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/"; +} + +function getCookie(cname) { + let name = cname + "="; + let ca = document.cookie.split(';'); + for (let i = 0; i < ca.length; i++) { + let c = ca[i]; + while (c.charAt(0) == ' ') { + c = c.substring(1); + } + if (c.indexOf(name) == 0) { + return c.substring(name.length, c.length); + } + } + return ""; +} + +//////////////////////////////////////////////////////////////////////////////// +// Document-specific functions +//////////////////////////////////////////////////////////////////////////////// function documentClick(e) { let sender = e.target; let id = sender.getAttribute("data-id"); @@ -82,7 +112,13 @@ function openReplyWindow(replyUrl) { }); $(replyWindow.iframe, "iframe").on("load", () => { fitWindowToContent(replyWindow); - replyWindow.$("#id_text").focus(); + // the iframe load event gets fired on the success page as well as the + // new post page. We just want to target the text area on the new post + // page. + let textarea = replyWindow.$("#id_text"); + if (textarea) { + textarea.focus(); + } }); replyWindow.show(); return replyWindow; diff --git a/board/templates/board/post_create_view.html b/board/templates/board/post_create_view.html index 953722b..76a3b9f 100644 --- a/board/templates/board/post_create_view.html +++ b/board/templates/board/post_create_view.html @@ -55,4 +55,15 @@ input[type=text] {