debian-mirror-gitlab/app/assets/javascripts/blob/blob_blame_link.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

36 lines
1.3 KiB
JavaScript
Raw Normal View History

2023-01-13 00:05:48 +05:30
import { getPageParamValue, getPageSearchString } from './utils';
export function addBlameLink(containerSelector, linkClass) {
2022-10-02 17:18:49 +05:30
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 blameLink = document.createElement('a');
2023-01-13 00:05:48 +05:30
const { blamePath } = document.querySelector('.line-numbers').dataset;
2022-10-02 17:18:49 +05:30
blameLink.classList.add('file-line-blame');
2023-01-13 00:05:48 +05:30
const blamePerPage = document.querySelector('.js-per-page')?.dataset?.blamePerPage;
const pageNumber = getPageParamValue(lineNumber, blamePerPage);
const searchString = getPageSearchString(blamePath, pageNumber);
blameLink.href = `${blamePath}${searchString}#L${lineNumber}`;
2022-10-02 17:18:49 +05:30
const wrapper = document.createElement('div');
wrapper.classList.add('line-links', 'diff-line-num');
wrapper.appendChild(blameLink);
wrapper.appendChild(lineLinkCopy);
lineLink.replaceWith(wrapper);
}
});
}