Skip to content

Commit 5bfba28

Browse files
committed
Comments: Started inline comment display windows
1 parent 18ede9b commit 5bfba28

File tree

5 files changed

+132
-4
lines changed

5 files changed

+132
-4
lines changed

lang/en/entities.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,7 @@
402402
'comment_deleted_success' => 'Comment deleted',
403403
'comment_created_success' => 'Comment added',
404404
'comment_updated_success' => 'Comment updated',
405+
'comment_view' => 'View comment',
405406
'comment_delete_confirm' => 'Are you sure you want to delete this comment?',
406407
'comment_in_reply_to' => 'In reply to :commentId',
407408
'comment_editor_explain' => 'Here are the comments that have been left on this page. Comments can be added & managed when viewing the saved page.',

resources/js/components/page-comment.ts

Lines changed: 62 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@ import {findTargetNodeAndOffset, getLoading, hashElement, htmlToDom} from '../se
33
import {buildForInput} from '../wysiwyg-tinymce/config';
44
import {el} from "../wysiwyg/utils/dom";
55

6+
import commentIcon from "@icons/comment.svg"
7+
68
export class PageComment extends Component {
79

810
protected commentId: string;
911
protected commentLocalId: string;
1012
protected commentContentRef: string;
1113
protected deletedText: string;
1214
protected updatedText: string;
15+
protected viewCommentText: string;
1316

1417
protected wysiwygEditor: any = null;
1518
protected wysiwygLanguage: string;
@@ -31,6 +34,7 @@ export class PageComment extends Component {
3134
this.commentContentRef = this.$opts.commentContentRef;
3235
this.deletedText = this.$opts.deletedText;
3336
this.updatedText = this.$opts.updatedText;
37+
this.viewCommentText = this.$opts.viewCommentText;
3438

3539
// Editor reference and text options
3640
this.wysiwygLanguage = this.$opts.wysiwygLanguage;
@@ -171,13 +175,67 @@ export class PageComment extends Component {
171175

172176
const relLeft = bounds.left - refElBounds.left;
173177
const relTop = bounds.top - refElBounds.top;
174-
// TODO - Extract to class, Use theme color
175-
const marker = el('div', {
178+
179+
const marker = el('button', {
180+
type: 'button',
181+
class: 'content-comment-marker',
182+
title: this.viewCommentText,
183+
});
184+
marker.innerHTML = <string>commentIcon;
185+
marker.addEventListener('click', event => {
186+
this.showCommentAtMarker(marker);
187+
});
188+
189+
const markerWrap = el('div', {
176190
class: 'content-comment-highlight',
177191
style: `left: ${relLeft}px; top: ${relTop}px; width: ${bounds.width}px; height: ${bounds.height}px;`
178-
}, ['']);
192+
}, [marker]);
179193

180194
refEl.style.position = 'relative';
181-
refEl.append(marker);
195+
refEl.append(markerWrap);
196+
}
197+
198+
protected showCommentAtMarker(marker: HTMLElement): void {
199+
200+
marker.hidden = true;
201+
const readClone = this.container.closest('.comment-branch').cloneNode(true) as HTMLElement;
202+
const toRemove = readClone.querySelectorAll('.actions, form');
203+
for (const el of toRemove) {
204+
el.remove();
205+
}
206+
207+
const close = el('button', {type: 'button'}, ['x']);
208+
const jump = el('button', {type: 'button'}, ['Jump to thread']);
209+
210+
const commentWindow = el('div', {
211+
class: 'content-comment-window'
212+
}, [
213+
el('div', {
214+
class: 'content-comment-window-actions',
215+
}, [jump, close]),
216+
el('div', {
217+
class: 'content-comment-window-content',
218+
}, [readClone]),
219+
]);
220+
221+
marker.parentElement.append(commentWindow);
222+
223+
const closeAction = () => {
224+
commentWindow.remove();
225+
marker.hidden = false;
226+
};
227+
228+
close.addEventListener('click', closeAction.bind(this));
229+
230+
jump.addEventListener('click', () => {
231+
closeAction();
232+
this.container.scrollIntoView({behavior: 'smooth'});
233+
const highlightTarget = this.container.querySelector('.header') as HTMLElement;
234+
highlightTarget.classList.add('anim-highlight');
235+
highlightTarget.addEventListener('animationend', () => highlightTarget.classList.remove('anim-highlight'))
236+
});
237+
238+
// TODO - Position wrapper sensibly
239+
// TODO - Movement control?
182240
}
183241
}

resources/sass/_animations.scss

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,26 @@
6767
animation-duration: 180ms;
6868
animation-delay: 0s;
6969
animation-timing-function: cubic-bezier(.62, .28, .23, .99);
70+
}
71+
72+
@keyframes highlight {
73+
0% {
74+
background-color: var(--color-primary-light);
75+
}
76+
33% {
77+
background-color: transparent;
78+
}
79+
66% {
80+
background-color: var(--color-primary-light);
81+
}
82+
100% {
83+
background-color: transparent;
84+
}
85+
}
86+
87+
.anim-highlight {
88+
animation-name: highlight;
89+
animation-duration: 2s;
90+
animation-delay: 0s;
91+
animation-timing-function: linear;
7092
}

resources/sass/_pages.scss

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,52 @@ body.tox-fullscreen, body.markdown-fullscreen {
239239
opacity: 0.25;
240240
}
241241
}
242+
.content-comment-window {
243+
font-size: vars.$fs-m;
244+
line-height: 1.4;
245+
position: relative;
246+
z-index: 90;
247+
pointer-events: all;
248+
min-width: min(340px, 80vw);
249+
background-color: #FFF;
250+
//border: 1px solid var(--color-primary);
251+
box-shadow: vars.$bs-hover;
252+
border-radius: 4px;
253+
overflow: hidden;
254+
}
255+
.content-comment-window-actions {
256+
background-color: var(--color-primary);
257+
color: #FFF;
258+
display: flex;
259+
align-items: center;
260+
justify-content: end;
261+
}
262+
.content-comment-window-content {
263+
padding: vars.$xs;
264+
max-height: 200px;
265+
overflow-y: scroll;
266+
}
267+
.content-comment-marker {
268+
position: absolute;
269+
right: -16px;
270+
top: -16px;
271+
pointer-events: all;
272+
width: min(1.5em, 32px);
273+
height: min(1.5em, 32px);
274+
border-radius: min(calc(1.5em / 2), 32px);
275+
display: flex;
276+
align-items: center;
277+
justify-content: center;
278+
background-color: var(--color-primary);
279+
box-shadow: vars.$bs-hover;
280+
color: #FFF;
281+
cursor: pointer;
282+
z-index: 90;
283+
svg {
284+
fill: #FFF;
285+
width: 80%;
286+
}
287+
}
242288

243289
// Page editor sidebar toolbox
244290
.floating-toolbox {

resources/views/comments/comment.blade.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
option:page-comment:comment-content-ref="{{ $comment->content_ref }}"
88
option:page-comment:updated-text="{{ trans('entities.comment_updated_success') }}"
99
option:page-comment:deleted-text="{{ trans('entities.comment_deleted_success') }}"
10+
option:page-comment:view-comment-text="{{ trans('entities.comment_view') }}"
1011
option:page-comment:wysiwyg-language="{{ $locale->htmlLang() }}"
1112
option:page-comment:wysiwyg-text-direction="{{ $locale->htmlDirection() }}"
1213
id="comment{{$comment->local_id}}"

0 commit comments

Comments
 (0)