From 8741e1d7f69bf3959a57fc5c57cce56a237eeb97 Mon Sep 17 00:00:00 2001 From: fatchan Date: Sun, 20 Oct 2019 05:43:17 +0000 Subject: [PATCH] post quoting changes and improvements for JS users --- gulp/res/css/style.css | 1 + gulp/res/js/post.js | 8 ++++---- gulp/res/js/quote.js | 21 ++++++++++++++++++++- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/gulp/res/css/style.css b/gulp/res/css/style.css index 6290947b..b372202c 100644 --- a/gulp/res/css/style.css +++ b/gulp/res/css/style.css @@ -92,6 +92,7 @@ pre { background: var(--darken); padding: 2px; font-family: monospace; + max-width: max-content; } .text-center { text-align: center; diff --git a/gulp/res/js/post.js b/gulp/res/js/post.js index 151f8668..129eba93 100644 --- a/gulp/res/js/post.js +++ b/gulp/res/js/post.js @@ -11,9 +11,9 @@ pug_html = pug_html + "\u003Cdiv class=\"reports post-container\"\u003E\u003Cinp }; pug_mixins["post"] = pug_interp = function(post, truncate, manage=false, globalmanage=false, ban=false){ var block = (this && this.block), attributes = (this && this.attributes) || {}; -pug_html = pug_html + "\u003Cdiv" + (" class=\"anchor\""+pug_attr("id", post.postId, true, false)) + "\u003E\u003C\u002Fdiv\u003E\u003Carticle" + (pug_attr("class", pug_classes([`post-container ${post.thread || ban === true ? '' : 'op'}`], [true]), false, false)) + "\u003E"; +pug_html = pug_html + "\u003Cdiv" + (" class=\"anchor\""+pug_attr("id", post.postId, true, false)) + "\u003E\u003C\u002Fdiv\u003E\u003Cdiv" + (pug_attr("class", pug_classes([`post-container ${post.thread || ban === true ? '' : 'op'}`], [true]), false, false)) + "\u003E"; const postURL = `/${post.board}/thread/${post.thread || post.postId}.html`; -pug_html = pug_html + "\u003Cheader class=\"post-info\"\u003E\u003Clabel\u003E"; +pug_html = pug_html + "\u003Cdiv class=\"post-info\"\u003E\u003Clabel\u003E"; if (globalmanage) { pug_html = pug_html + "\u003Cinput" + (" class=\"post-check\""+" type=\"checkbox\" name=\"globalcheckedposts\""+pug_attr("value", post._id, true, false)) + "\u002F\u003E"; } @@ -64,7 +64,7 @@ pug_html = pug_html + "\u003C\u002Flabel\u003E\u003Cspan class=\"post-links\"\u0 if (!post.thread) { pug_html = pug_html + " \u003Cspan\u003E\u003Ca" + (pug_attr("href", `${postURL}#postform`, true, false)) + "\u003E[Reply]\u003C\u002Fa\u003E\u003C\u002Fspan\u003E"; } -pug_html = pug_html + "\u003C\u002Fspan\u003E\u003C\u002Fspan\u003E\u003C\u002Fheader\u003E\u003Cdiv class=\"post-data\"\u003E"; +pug_html = pug_html + "\u003C\u002Fspan\u003E\u003C\u002Fspan\u003E\u003C\u002Fdiv\u003E\u003Cdiv class=\"post-data\"\u003E"; if (post.files.length > 0) { pug_html = pug_html + "\u003Cdiv class=\"post-files\"\u003E"; // iterate post.files @@ -199,7 +199,7 @@ pug_html = pug_html + "\u003Ca" + (" class=\"quote\""+pug_attr("href", `/${post. pug_html = pug_html + "\u003C\u002Fdiv\u003E"; } -pug_html = pug_html + "\u003C\u002Fdiv\u003E\u003C\u002Farticle\u003E"; +pug_html = pug_html + "\u003C\u002Fdiv\u003E\u003C\u002Fdiv\u003E"; if (manage === true) { // iterate post.reports ;(function(){ diff --git a/gulp/res/js/quote.js b/gulp/res/js/quote.js index 7971ce73..2e180e1a 100644 --- a/gulp/res/js/quote.js +++ b/gulp/res/js/quote.js @@ -1,18 +1,37 @@ window.addEventListener('DOMContentLoaded', (event) => { + const isThread = /\/\w+\/thread\/\d+.html/.test(window.location.pathname); const links = document.getElementsByClassName('post-quoters'); const messageBox = document.getElementById('message'); const addQuote = function(number) { + window.location.hash = 'postform'; //open postform messageBox.value += `>>${number}\n`; messageBox.scrollTop = messageBox.scrollHeight; + messageBox.focus(); + messageBox.setSelectionRange(messageBox.value.length, messageBox.value.length); } const quote = function(e) { + e.preventDefault(); const quoteNum = this.textContent.replace('[Reply]', '').split(' ')[0].trim(); - addQuote(quoteNum); + if (isThread) { + addQuote(quoteNum); + } else { + localStorage.setItem('clickedQuote', quoteNum); + window.location = this.firstChild.href.replace(/#postform$/, '#'+quoteNum); + } }; + //on loading page after clicking quote + if (isThread) { + const quoteNum = localStorage.getItem('clickedQuote'); + if (quoteNum != null) { + addQuote(quoteNum); + } + localStorage.removeItem('clickedQuote'); + } + for (let i = 0; i < links.length; i++) { links[i].addEventListener('click', quote, false); }