Skip to content

Commit 203a626

Browse files
committed
js: embed: Add .isso-target class to currently linked comment
1 parent 8c3d07a commit 203a626

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

isso/js/embed.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,19 @@ function init() {
5454
// and the call to fetch those is in fetchComments()
5555
isso_thread.append(heading);
5656
isso_thread.append('<div id="isso-root"></div>');
57+
58+
window.addEventListener('hashchange', function() {
59+
if (!window.location.hash.match("^#isso-[0-9]+$")) {
60+
return;
61+
}
62+
63+
var existingTarget = $(".isso-target");
64+
if (existingTarget != null) {
65+
existingTarget.classList.remove("isso-target");
66+
}
67+
68+
$(window.location.hash + " > .isso-text-wrapper").classList.add("isso-target");
69+
});
5770
}
5871

5972
function fetchComments() {
@@ -105,6 +118,11 @@ function fetchComments() {
105118
if (window.location.hash.length > 0 &&
106119
window.location.hash.match("^#isso-[0-9]+$")) {
107120
$(window.location.hash).scrollIntoView();
121+
122+
// We can't just set the id to `#isso-target` because it's already set to `#isso-[number]`
123+
// So a class `.isso-target` has to be used instead, and then we can manually remove the
124+
// class from the old target comment in the `hashchange` listener.
125+
$(window.location.hash + " > .isso-text-wrapper").classList.add("isso-target");
108126
}
109127
},
110128
function(err) {

0 commit comments

Comments
 (0)