From b13c85903826c0362b41e1c046a2891326411658 Mon Sep 17 00:00:00 2001 From: Helen Chong <119173961+helenclx@users.noreply.github.com> Date: Mon, 27 May 2024 13:00:11 +0800 Subject: [PATCH] Update guestbook control with new features --- src/assets/css/comments.css | 28 +++++++++++--- src/assets/js/comments.js | 73 +++++++++++++++++++++++++++++++------ 2 files changed, 84 insertions(+), 17 deletions(-) diff --git a/src/assets/css/comments.css b/src/assets/css/comments.css index c1d8b545..5a2a46f9 100644 --- a/src/assets/css/comments.css +++ b/src/assets/css/comments.css @@ -53,6 +53,7 @@ align-items: center; justify-content: center; gap: 0.5em; + background-color: var(--clr-quote-bg); } .form-footer { @@ -63,7 +64,8 @@ } .form-footer input, -.comment-article > button { +.comment-footer button, +.show-comment { cursor: pointer; border: none; background: var(--clr-link-btn-bg); @@ -72,6 +74,20 @@ border-radius: 0.2em; } +gw-comment-card:not(.collapsed) .show-comment { + display: none; +} +gw-comment-card.collapsed .comment-article > *:not(.comment-header) { + display: none !important; +} +gw-comment-card.collapsed .show-comment { + display: block; +} + +gw-comment-card.collapsed .comment-header-right time { + display: none; +} + .comments-container { display: flex; flex-direction: column; @@ -81,7 +97,7 @@ } .comment-article { - padding: 0.5em 0; + padding: 0.3em 0; display: flex; flex-direction: column; } @@ -109,14 +125,16 @@ padding-right: 0; } -.comment-id, .comment-timestamp { +.comment-id, .comment-header-right > time { font-size: 0.85em; font-style: italic; word-break: keep-all; } -.comment-timestamp { - text-align: end; +.comment-header-right { + display: flex; + flex-direction: row; + justify-content: flex-end; } .commenter-name { diff --git a/src/assets/js/comments.js b/src/assets/js/comments.js index df3381cf..da3bc927 100644 --- a/src/assets/js/comments.js +++ b/src/assets/js/comments.js @@ -1,10 +1,29 @@ /** - * Author: Vera Konigin - * Site: https://groundedwren.neocities.org - * Contact: vera@groundedwren.com - * - * File Description: Comments Control - */ +* Author: Vera Konigin +* Site: https://groundedwren.neocities.org +* Contact: vera@groundedwren.com +* +* File Description: Comments Control +*/ + +/** +* By default, any JavaScript code written is defined in the global namespace, which means it's accessible directly under the "window" element. +* If you have a lot of scripts, this can lead to clutter and naming collisions (what if two different scripts use a variable called "i"? They can inadvertently mess each other up). +* To get around this, we define the registerNamespace function in the global namespace, which just confines all the code in the function passed to it to a property under window. +* That property is represented as the "path" parameter. It is passed to the function for ease of access. +*/ +function registerNamespace(path, nsFunc) +{ + var ancestors = path.split("."); + + var ns = window; + for(var i = 0; i < ancestors.length; i++) + { + ns[ancestors[i]] = ns[ancestors[i]] || {}; + ns = ns[ancestors[i]]; + } + nsFunc(ns); +} registerNamespace("GW.Controls", function (ns) { @@ -312,6 +331,7 @@ registerNamespace("GW.Controls", function (ns)
-
+ ${commenterNameEl} - +
+ + +
${this.commentText}
- + `; //element properties this.articleEl = document.getElementById(`${this.idKey}-article`); + this.timestamp = document.getElementById(`${this.idKey}-timestamp`); this.replyBtn = document.getElementById(`${this.idKey}-reply`); + this.hideBtn = document.getElementById(`${this.idKey}-hide`); + this.showBtn = document.getElementById(`${this.idKey}-show`); } //#region Handlers registerHandlers() { this.replyBtn.onclick = this.onReply; + this.hideBtn.onclick = this.onHide; + this.showBtn.onclick = this.onShow; } onReply = () => @@ -468,6 +505,18 @@ registerNamespace("GW.Controls", function (ns) respToInpt.value = this.commentId; respToInpt.focus(); }; + + onHide = () => + { + this.classList.add("collapsed"); + this.showBtn.focus(); + }; + + onShow = () => + { + this.classList.remove("collapsed"); + this.timestamp.focus(); + }; //#endregion }; customElements.define("gw-comment-card", ns.CommentCard);