Skip to content

Commit ecda4e1

Browse files
committed
Comments: Added reference marker to comments
1 parent f656a82 commit ecda4e1

File tree

6 files changed

+63
-4
lines changed

6 files changed

+63
-4
lines changed

resources/icons/bookmark.svg

Lines changed: 1 addition & 0 deletions
Loading

resources/js/components/page-comment.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {el} from "../wysiwyg/utils/dom";
55

66
import commentIcon from "@icons/comment.svg"
77
import closeIcon from "@icons/close.svg"
8+
import {PageDisplay} from "./page-display";
89

910
/**
1011
* Track the close function for the current open marker so it can be closed
@@ -35,6 +36,7 @@ export class PageComment extends Component {
3536
protected deleteButton: HTMLElement;
3637
protected replyButton: HTMLElement;
3738
protected input: HTMLInputElement;
39+
protected contentRefLink: HTMLLinkElement|null;
3840

3941
setup() {
4042
// Options
@@ -60,6 +62,7 @@ export class PageComment extends Component {
6062
this.deleteButton = this.$refs.deleteButton;
6163
this.replyButton = this.$refs.replyButton;
6264
this.input = this.$refs.input as HTMLInputElement;
65+
this.contentRefLink = (this.$refs.contentRef || null) as HTMLLinkElement|null;
6366

6467
this.setupListeners();
6568
this.positionForReference();
@@ -153,21 +156,20 @@ export class PageComment extends Component {
153156
}
154157

155158
protected positionForReference() {
156-
if (!this.commentContentRef) {
159+
if (!this.commentContentRef || !this.contentRefLink) {
157160
return;
158161
}
159162

160163
const [refId, refHash, refRange] = this.commentContentRef.split(':');
161164
const refEl = document.getElementById(refId);
162165
if (!refEl) {
163-
// TODO - Show outdated marker for comment
166+
this.contentRefLink.classList.add('outdated', 'missing');
164167
return;
165168
}
166169

167170
const actualHash = hashElement(refEl);
168171
if (actualHash !== refHash) {
169-
// TODO - Show outdated marker for comment
170-
return;
172+
this.contentRefLink.classList.add('outdated');
171173
}
172174

173175
const refElBounds = refEl.getBoundingClientRect();
@@ -204,6 +206,13 @@ export class PageComment extends Component {
204206

205207
refEl.style.position = 'relative';
206208
refEl.append(markerWrap);
209+
210+
this.contentRefLink.href = `#${refEl.id}`;
211+
this.contentRefLink.addEventListener('click', (event: MouseEvent) => {
212+
const pageDisplayComponent = window.$components.get('page-display')[0] as PageDisplay;
213+
event.preventDefault();
214+
pageDisplayComponent.goToText(refId);
215+
});
207216
}
208217

209218
protected showCommentAtMarker(marker: HTMLElement): void {

resources/js/components/page-display.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ export class PageDisplay extends Component {
5757
}
5858
}
5959

60+
/**
61+
* @public
62+
*/
6063
goToText(text) {
6164
const idElem = document.getElementById(text);
6265

resources/sass/_components.scss

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -746,6 +746,44 @@ body.flexbox-support #entity-selector-wrap .popup-body .form-group {
746746
height: calc(100% - vars.$m);
747747
}
748748

749+
.comment-reference-indicator-wrap a {
750+
float: left;
751+
margin-top: vars.$xs;
752+
font-size: 12px;
753+
display: inline-block;
754+
font-weight: bold;
755+
position: relative;
756+
border-radius: 4px;
757+
overflow: hidden;
758+
padding: 2px 6px 2px 0;
759+
margin-inline-end: vars.$xs;
760+
color: var(--color-link);
761+
span {
762+
display: none;
763+
}
764+
&.outdated span {
765+
display: inline;
766+
}
767+
&.outdated.missing {
768+
color: var(--color-warning);
769+
pointer-events: none;
770+
}
771+
svg {
772+
width: 24px;
773+
margin-inline-end: 0;
774+
}
775+
&:after {
776+
background-color: currentColor;
777+
content: '';
778+
width: 100%;
779+
height: 100%;
780+
position: absolute;
781+
left: 0;
782+
top: 0;
783+
opacity: 0.15;
784+
}
785+
}
786+
749787
.comment-branch .comment-box {
750788
margin-bottom: vars.$m;
751789
}

resources/sass/_pages.scss

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,9 @@ body.tox-fullscreen, body.markdown-fullscreen {
280280
max-height: 200px;
281281
overflow-y: scroll;
282282
}
283+
.content-comment-window-content .comment-reference-indicator-wrap {
284+
display: none;
285+
}
283286
.content-comment-marker {
284287
position: absolute;
285288
right: -16px;

resources/views/comments/comment.blade.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ class="comment-box">
7777
<a class="text-muted text-small" href="#comment{{ $comment->parent_id }}">@icon('reply'){{ trans('entities.comment_in_reply_to', ['commentId' => '#' . $comment->parent_id]) }}</a>
7878
</p>
7979
@endif
80+
@if($comment->content_ref)
81+
<div class="comment-reference-indicator-wrap">
82+
<a href="#" refs="page-comment@content-ref">@icon('bookmark')Reference <span>- Outdated</span></a>
83+
</div>
84+
@endif
8085
{!! $commentHtml !!}
8186
</div>
8287

0 commit comments

Comments
 (0)