Skip to content

Commit

Permalink
Add styling to polls
Browse files Browse the repository at this point in the history
  • Loading branch information
syeopite committed Feb 6, 2024
1 parent 6bffe64 commit 59646de
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 12 deletions.
57 changes: 56 additions & 1 deletion assets/css/post-layout.css
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,59 @@ a.inline-link, a.inline-mention {
a.toggle-poll-results {
color: unset;
text-decoration: underline;
}
}

.poll-block {
gap: 15px;
border: unset;

padding: 0 10px;
margin: 10px 0;
}

.poll-block > header > h3 {
font-weight: normal;
margin: 0;
font-size: 24px;
}

.poll-choice {
border: 0;
border-radius: 10px;
background: #edeeee;
padding: 8px 18px;
overflow: hidden;
}

.poll-choice > .answer {
font-weight: 550;
}

.vote-proportion {
background: #dcdcdc;
border-radius: 10px 0px 0px 10px;
}

.poll-winner >.vote-proportion {
background: #BABABA;
}

.poll-block footer {
font-size: 15px;
margin-top: 0;
color: #6b7280;
}

.toggle-poll-results {
display: block;
margin-top: 10px;
margin-bottom: 20px;
}

.toggle-poll-results:hover {
font-weight: 700;
}

.separator {
font-size: 12px;
}
21 changes: 13 additions & 8 deletions assets/js/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,21 @@ function fill_poll_results(poll_element, results) {
choiceElement.appendChild(voteCountElement);
}

const totalVotesElement = document.createElement("p")
const pollMetadataElement = poll_element.getElementsByClassName("poll-metadata")[0]

if (poll_element.classList.contains("expired")) {
totalVotesElement.innerHTML = `Final result from ${total_votes} votes`
} else {
totalVotesElement.innerHTML = `${total_votes} votes`
}
const totalVotesElement = document.createElement("span")
totalVotesElement.innerHTML = `${total_votes} votes`

const separatorElement = document.createElement("span")
separatorElement.innerHTML = '•'
separatorElement.classList.add("separator")

const pollTimestamp = pollMetadataElement.children[0]

const newMetadataContents = document.createDocumentFragment()
newMetadataContents.append(totalVotesElement, separatorElement, pollTimestamp.cloneNode(true))

const pollFooter = poll_element.getElementsByTagName("footer")
pollFooter[0].insertBefore(totalVotesElement, pollFooter[0].firstChild)
pollTimestamp.replaceWith(newMetadataContents)

poll_element.classList.add("populated")
}
Expand Down
6 changes: 3 additions & 3 deletions src/helpers/ext_npf_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,15 @@ def _format_poll(self, block):

if (self.blog_name and self.post_id) and not block.votes:
poll_footer = poll_html[2]
poll_footer.add(
dominate.tags.noscript(
no_script_fallback = dominate.tags.noscript(
dominate.tags.a(
"See Results",
href=f"/{self.blog_name}/{self.post_id}?fetch_polls=true",
cls="toggle-poll-results"
)
)
)

poll_footer.children.insert(0, no_script_fallback)

return poll_html

Expand Down

0 comments on commit 59646de

Please sign in to comment.