From 4adf03be48a46cf8dfb0eba7700533bdfdffe325 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Sat, 11 Dec 2021 00:49:39 +0200 Subject: [PATCH] fdsfsd --- .../assets/js/comments+submission_listing.js | 78 ++++++++++++++++++- files/assets/js/popover.js | 48 ------------ files/assets/js/viewmore.js | 13 +--- files/classes/user.py | 3 +- files/templates/comments.html | 61 +++++++-------- files/templates/submission.html | 50 +----------- files/templates/submission_listing.html | 35 ++++----- 7 files changed, 123 insertions(+), 165 deletions(-) delete mode 100644 files/assets/js/popover.js diff --git a/files/assets/js/comments+submission_listing.js b/files/assets/js/comments+submission_listing.js index 6cc96b1a1..53e71498f 100644 --- a/files/assets/js/comments+submission_listing.js +++ b/files/assets/js/comments+submission_listing.js @@ -13,4 +13,80 @@ function expandDesktopImage(image) { document.getElementById("desktop-expanded-image").src = image.replace("200w_d.webp", "giphy.webp"); document.getElementById("desktop-expanded-image-link").href = image; document.getElementById("desktop-expanded-image-wrap-link").href=image; -}; \ No newline at end of file +}; + + +function popovertrigger() { + const popoverTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="popover"]')); + const popoverList = popoverTriggerList.map(function(popoverTriggerEl) { + const popoverId = popoverTriggerEl.getAttribute('data-content-id'); + const contentEl = document.getElementById(popoverId); + if (contentEl) { + return new bootstrap.Popover(popoverTriggerEl, { + content: contentEl.innerHTML, + html: true, + }); + } + }) +} + +popovertrigger() + +function popoverEventListener(value){ + //get the id of the popover that will be created for this user + var content_id = value.getAttributeNode("data-content-id").value; + //add an event listener that will trigger the creation of a replacement popover when the username is clicked + value.addEventListener("click", function(){createNewPopover(content_id)}); + } + + function checkIfPopover(){ + //check if a replacement popover already exists and remove it if so + if (document.getElementById("popover-fix") != null){ + document.body.removeChild(document.getElementById("popover-fix")); + } + } + + function closePopover(e){ + //get the element that was clicked on + active = document.activeElement; + //if the element is not a username then check if a popover replacement already exists + if (active.attributes.getNamedItem("data-bs-toggle").nodeValue != "popover"){ + checkIfPopover(); + } + } + + function createNewPopover(value){ + //check for an existing replacement popover and then copy the original popover node + checkIfPopover(); + var popover_old = document.getElementsByClassName("popover")[0]; + var popover_new = document.createElement("DIV"); + + //copy the contents of the original popover + popover_new.innerHTML = popover_old.outerHTML; + popover_new.id = "popover-fix"; + + //append the replacement popover to the document and remove the original one + document.body.appendChild(popover_new); + document.body.removeChild(popover_old); + } + + window.addEventListener('load', (e) => { + //grab all of the usernames on the page and create event listeners for them + var usernames = document.querySelectorAll("a[data-bs-toggle=popover]"); + usernames.forEach(popoverEventListener); + + //create an event listener to check if a clicked element is a username + document.addEventListener("click", function(e){closePopover(e)}); + }); + + +function popclick(author) { + for (const x of document.getElementsByClassName('pop-banner')) {x.src = author["bannerurl"]} + for (const x of document.getElementsByClassName('pop-picture')) {x.src = author["profile_url"]} + for (const x of document.getElementsByClassName('pop-username')) {x.innerHTML = author["username"]} + for (const x of document.getElementsByClassName('pop-bio')) {x.innerHTML = author["bio_html"]} + for (const x of document.getElementsByClassName('pop-postcount')) {x.innerHTML = author["post_count"]} + for (const x of document.getElementsByClassName('pop-commentcount')) {x.innerHTML = author["comment_count"]} + for (const x of document.getElementsByClassName('pop-coins')) {x.innerHTML = author["coins"]} + for (const x of document.getElementsByClassName('pop-viewmore')) {x.href = author["url"]} +} \ No newline at end of file diff --git a/files/assets/js/popover.js b/files/assets/js/popover.js deleted file mode 100644 index 7631f75db..000000000 --- a/files/assets/js/popover.js +++ /dev/null @@ -1,48 +0,0 @@ - -const popoverTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="popover"]')); -const popoverList = popoverTriggerList.map(function(popoverTriggerEl) { - const popoverId = popoverTriggerEl.getAttribute('data-content-id'); - const contentEl = document.getElementById(popoverId); - if (contentEl) { - return new bootstrap.Popover(popoverTriggerEl, { - content: contentEl.innerHTML, - html: true, - }); - } -}) - -function eventasdf(value){ - var content_id = value.getAttributeNode("data-content-id").value; - value.addEventListener("click", function(){jhkj(content_id)}); -} - -function checkIfBussy(){ - if (document.getElementById("bussy") != null){ - document.body.removeChild(document.getElementById("bussy")); - } -} - -function dfgh(e){ - active = document.activeElement; - if (active.getAttributeNode("class") == null || active.getAttributeNode("class").nodeValue != "user-name text-decoration-none"){ - checkIfBussy(); - } -} - -function jhkj(value){ - checkIfBussy(); - var popover_shit = document.getElementsByClassName("popover")[0]; - var uiop = document.createElement("DIV"); - - uiop.innerHTML = popover_shit.outerHTML; - uiop.id = "bussy"; - - document.body.appendChild(uiop); - document.body.removeChild(popover_shit); -} - - -var usernames = document.querySelectorAll("a.user-name"); -usernames.forEach(eventasdf); - -document.addEventListener("click", function(e){dfgh(e)}); \ No newline at end of file diff --git a/files/assets/js/viewmore.js b/files/assets/js/viewmore.js index 75ed97b96..1146119cd 100644 --- a/files/assets/js/viewmore.js +++ b/files/assets/js/viewmore.js @@ -14,18 +14,7 @@ function viewmore(pid,sort,offset) { tooltipTriggerList.map(function(element){ return new bootstrap.Tooltip(element); }); - - const popoverTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="popover"]')); - const popoverList = popoverTriggerList.map(function(popoverTriggerEl) { - const popoverId = popoverTriggerEl.getAttribute('data-content-id'); - const contentEl = document.getElementById(popoverId); - if (contentEl) { - return new bootstrap.Popover(popoverTriggerEl, { - content: contentEl.innerHTML, - html: true, - }); - } - }) + popovertrigger() } } xhr.send(form) diff --git a/files/classes/user.py b/files/classes/user.py index c529257dd..321664cf3 100644 --- a/files/classes/user.py +++ b/files/classes/user.py @@ -267,6 +267,7 @@ class User(Base): @property @lazy def bio_html_eager(self): + if self.bio_html == None: return '' return self.bio_html.replace('data-src', 'src').replace('src="/assets/images/loading.webp"', '') @property @@ -434,7 +435,7 @@ class User(Base): 'profile_url': self.profile_url, 'bannerurl': self.bannerurl, 'bio': self.bio, - 'bio_html': self.bio_html, + 'bio_html': self.bio_html_eager, 'flair': self.customtitle } diff --git a/files/templates/comments.html b/files/templates/comments.html index 6b45ccf30..0cfd415e0 100644 --- a/files/templates/comments.html +++ b/files/templates/comments.html @@ -27,54 +27,46 @@ } - -{% macro single_comment(c, level=1) %} - -