Skip to content

Commit

Permalink
fix votes
Browse files Browse the repository at this point in the history
Yes, I also patched HTMX. Had to modify how the `document.evaluate` function was called.
  • Loading branch information
marnym committed Apr 24, 2024
1 parent f41c497 commit fbc2bbb
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
3 changes: 1 addition & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ WORKDIR /src
COPY .swcrc .
COPY scripts ./scripts

RUN apk add swc && \
swc compile --config-file .swcrc --ignore scripts/htmx.min.js --out-dir . scripts
RUN apk add swc && swc compile --config-file .swcrc --out-dir . scripts

FROM denoland/deno:alpine-1.41.0
EXPOSE 8000
Expand Down
2 changes: 1 addition & 1 deletion scripts/htmx.min.js

Large diffs are not rendered by default.

11 changes: 8 additions & 3 deletions scripts/votes.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const votes = document.getElementById("votes");
let votes = document.getElementById("votes");
const INITIAL_VOTE_MAIN_WIDTH = 32;
const VOTE_COL_WIDTH = 20;

Expand All @@ -12,14 +12,19 @@ const votesRegex = /((?:width|left): ?\d{1,3})(?!px)(;|")/g;
* by setting the correct width the element will be centered correctly.
*/
function centerVotes() {
votes.innerHTML = votes.innerHTML.replaceAll(votesRegex, "$1px$2");
if (!votes) {
votes = document.getElementById("votes");
}
votes.innerHTML = votes.innerHTML.replace(votesRegex, "$1px$2");
const voteMain = votes.querySelector("#voteMain");
voteMain.style.width = votesWidth(voteMain) + "px";
}

function votesWidth(voteMain) {
let width = INITIAL_VOTE_MAIN_WIDTH;
for (const c of voteMain.children) {
const children = voteMain.children;
for (let i = 0; i < children.length; i++) {
const c = children[i];
const w = parseInt(c.style.left.replace("px", ""));
if (w > width) {
width = w;
Expand Down

0 comments on commit fbc2bbb

Please sign in to comment.