Highlight comments if hash is present in URL
This commit is contained in:
21
assets/js/components/comment-highlight.js
Normal file
21
assets/js/components/comment-highlight.js
Normal file
@@ -0,0 +1,21 @@
|
||||
KB.on('dom.ready', function () {
|
||||
function highlightComment() {
|
||||
if (window.location.hash.indexOf('#comment-') === 0) {
|
||||
var commentElement = KB.find(window.location.hash);
|
||||
|
||||
if (commentElement) {
|
||||
var commentsElement = document.querySelectorAll('.comment');
|
||||
|
||||
commentsElement.forEach(function (element) {
|
||||
KB.dom(element).removeClass('comment-highlighted');
|
||||
});
|
||||
|
||||
commentElement.addClass('comment-highlighted');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
window.addEventListener('hashchange', highlightComment);
|
||||
|
||||
highlightComment();
|
||||
});
|
||||
Reference in New Issue
Block a user