Skip to content

Commit 802aa6d

Browse files
jaqrazeripath
jaqra
authored andcommitted
Add comment highlight when target from url (#9047)
* Add comment highlight css * Add js to remove highlight on click outside * Improve refresh page on click outside * Use location.hash property to remove target * Handle click ONLY clicked outside of 'targetted comment' (not other comment) * Remove unnecessary checks and simply code * Combine hash and setState to remove target path
1 parent 62bcb2b commit 802aa6d

File tree

5 files changed

+32
-2
lines changed

5 files changed

+32
-2
lines changed

public/css/index.css

+1
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,7 @@ i.icon.centerlock{top:1.5em}
593593
.repository.view.issue .comment-list .comment .content>.bottom.segment .ui.image{max-height:100%;width:auto;margin:0;vertical-align:middle}
594594
.repository.view.issue .comment-list .comment .content>.bottom.segment span.ui.image{font-size:128px;color:#000}
595595
.repository.view.issue .comment-list .comment .content>.bottom.segment span.ui.image:hover{color:#000}
596+
.repository.view.issue .comment-list .comment:target>.content{box-shadow:0 0 10px #8c8c8c}
596597
.repository.view.issue .comment-list .comment .ui.form .field:first-child{clear:none}
597598
.repository.view.issue .comment-list .comment .ui.form .tab.segment{border:0;padding:10px 0 0}
598599
.repository.view.issue .comment-list .comment .ui.form textarea{height:200px;font-family:'SF Mono',Consolas,Menlo,'Liberation Mono',Monaco,'Lucida Console',monospace}

public/js/index.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/js/index.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

web_src/js/index.js

+25
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,28 @@ function initInstall() {
586586
});
587587
}
588588

589+
function initIssueComments() {
590+
if ($('.repository.view.issue .comments').length === 0) return;
591+
592+
$(document).click((event) => {
593+
const urlTarget = $(':target');
594+
if (urlTarget.length === 0) return;
595+
596+
const urlTargetId = urlTarget.attr('id');
597+
if (!urlTargetId) return;
598+
if (!/^(issue|pull)(comment)?-\d+$/.test(urlTargetId)) return;
599+
600+
const $target = $(event.target);
601+
602+
if ($target.closest(`#${urlTargetId}`).length === 0) {
603+
const scrollPosition = $(window).scrollTop();
604+
window.location.hash = '';
605+
$(window).scrollTop(scrollPosition);
606+
window.history.pushState(null, null, ' ');
607+
}
608+
});
609+
}
610+
589611
function initRepository() {
590612
if ($('.repository').length === 0) {
591613
return;
@@ -733,6 +755,9 @@ function initRepository() {
733755
return false;
734756
});
735757

758+
// Issue Comments
759+
initIssueComments();
760+
736761
// Issue/PR Context Menus
737762
$('.context-dropdown').dropdown({
738763
action: 'hide'

web_src/less/_repository.less

+4
Original file line numberDiff line numberDiff line change
@@ -844,6 +844,10 @@
844844
}
845845
}
846846

847+
&:target > .content {
848+
box-shadow: 0 0 10px #8c8c8c;
849+
}
850+
847851
.ui.form {
848852
.field:first-child {
849853
clear: none;

0 commit comments

Comments
 (0)