blob: 41dfd7b82b8a0e9b63f59f31f8c6eb242b184536 (
plain)
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
26
27
28
29
30
31
|
function addBlameLink(containerSelector, linkClass) {
const containerEl = document.querySelector(containerSelector);
if (!containerEl) {
return;
}
containerEl.addEventListener('mouseover', (e) => {
const isLineLink = e.target.classList.contains(linkClass);
if (isLineLink) {
const lineLink = e.target;
const lineLinkCopy = lineLink.cloneNode(true);
lineLinkCopy.classList.remove(linkClass, 'diff-line-num');
const { lineNumber } = lineLink.dataset;
const { blamePath } = document.querySelector('.line-numbers').dataset;
const blameLink = document.createElement('a');
blameLink.classList.add('file-line-blame');
blameLink.href = `${blamePath}#L${lineNumber}`;
const wrapper = document.createElement('div');
wrapper.classList.add('line-links', 'diff-line-num');
wrapper.appendChild(blameLink);
wrapper.appendChild(lineLinkCopy);
lineLink.replaceWith(wrapper);
}
});
}
export default addBlameLink;
|