forked from adamlaska/circleci-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhighlightURLHash.js
More file actions
25 lines (24 loc) · 905 Bytes
/
highlightURLHash.js
File metadata and controls
25 lines (24 loc) · 905 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// This function will highlight a dom element with the ID found in the URL fragment
// Added to draw attention to specific entries in only the insights table
// Highlight can be generalized to rest of documentation later see main.scss
export function highlightURLHash() {
addHighlightClassIfInUrl();
window.addEventListener(
'hashchange',
() => {
const highlightElem = document.querySelector('.highlight');
if (highlightElem) highlightElem.classList.remove('highlight');
addHighlightClassIfInUrl();
},
false,
);
}
export function addHighlightClassIfInUrl() {
const hash = window.location.hash;
const searchParams = new URLSearchParams(window.location.search);
const isHighlighted = searchParams.has('highlight');
if (isHighlighted && hash) {
const hashElem = document.querySelector(window.location.hash);
hashElem.classList.add('highlight');
}
}