From e8c5406971b5107ce65236bda6cdd477be19cdcd Mon Sep 17 00:00:00 2001 From: Yarden Shoham Date: Tue, 26 Mar 2024 01:03:12 +0200 Subject: [PATCH] Remove jQuery `.attr` from the code line range selection (#30077) - Switched from jQuery `attr` to plain javascript `getAttribute` and `setAttribute` - Tested the code line range selection and it works as before --------- Signed-off-by: Yarden Shoham Co-authored-by: silverwind (cherry picked from commit a9a5734185a1a2837cfae42de7b17cf41dbb218a) --- web_src/js/features/repo-code.js | 42 +++++++++++++++----------------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/web_src/js/features/repo-code.js b/web_src/js/features/repo-code.js index befa09000..cb5afa831 100644 --- a/web_src/js/features/repo-code.js +++ b/web_src/js/features/repo-code.js @@ -28,40 +28,38 @@ function selectRange($linesEls, $selectionEndEl, $selectionStartEls) { $linesEls.closest('tr').removeClass('active'); // add hashchange to permalink - const $refInNewIssue = $('a.ref-in-new-issue'); - const $copyPermalink = $('a.copy-line-permalink'); - const $viewGitBlame = $('a.view_git_blame'); + const refInNewIssue = document.querySelector('a.ref-in-new-issue'); + const copyPermalink = document.querySelector('a.copy-line-permalink'); + const viewGitBlame = document.querySelector('a.view_git_blame'); const updateIssueHref = function (anchor) { - if (!$refInNewIssue.length) { - return; - } - const urlIssueNew = $refInNewIssue.attr('data-url-issue-new'); - const urlParamBodyLink = $refInNewIssue.attr('data-url-param-body-link'); + if (!refInNewIssue) return; + const urlIssueNew = refInNewIssue.getAttribute('data-url-issue-new'); + const urlParamBodyLink = refInNewIssue.getAttribute('data-url-param-body-link'); const issueContent = `${toAbsoluteUrl(urlParamBodyLink)}#${anchor}`; // the default content for issue body - $refInNewIssue.attr('href', `${urlIssueNew}?body=${encodeURIComponent(issueContent)}`); + refInNewIssue.setAttribute('href', `${urlIssueNew}?body=${encodeURIComponent(issueContent)}`); }; const updateViewGitBlameFragment = function (anchor) { - if (!$viewGitBlame.length) return; - let href = $viewGitBlame.attr('href'); + if (!viewGitBlame) return; + let href = viewGitBlame.getAttribute('href'); href = `${href.replace(/#L\d+$|#L\d+-L\d+$/, '')}`; if (anchor.length !== 0) { href = `${href}#${anchor}`; } - $viewGitBlame.attr('href', href); + viewGitBlame.setAttribute('href', href); }; - const updateCopyPermalinkUrl = function(anchor) { - if (!$copyPermalink.length) return; - let link = $copyPermalink.attr('data-url'); + const updateCopyPermalinkUrl = function (anchor) { + if (!copyPermalink) return; + let link = copyPermalink.getAttribute('data-url'); link = `${link.replace(/#L\d+$|#L\d+-L\d+$/, '')}#${anchor}`; - $copyPermalink.attr('data-url', link); + copyPermalink.setAttribute('data-url', link); }; if ($selectionStartEls) { - let a = parseInt($selectionEndEl.attr('rel').slice(1)); - let b = parseInt($selectionStartEls.attr('rel').slice(1)); + let a = parseInt($selectionEndEl[0].getAttribute('rel').slice(1)); + let b = parseInt($selectionStartEls[0].getAttribute('rel').slice(1)); let c; if (a !== b) { if (a > b) { @@ -85,11 +83,11 @@ function selectRange($linesEls, $selectionEndEl, $selectionStartEls) { } } $selectionEndEl.closest('tr').addClass('active'); - changeHash(`#${$selectionEndEl.attr('rel')}`); + changeHash(`#${$selectionEndEl[0].getAttribute('rel')}`); - updateIssueHref($selectionEndEl.attr('rel')); - updateViewGitBlameFragment($selectionEndEl.attr('rel')); - updateCopyPermalinkUrl($selectionEndEl.attr('rel')); + updateIssueHref($selectionEndEl[0].getAttribute('rel')); + updateViewGitBlameFragment($selectionEndEl[0].getAttribute('rel')); + updateCopyPermalinkUrl($selectionEndEl[0].getAttribute('rel')); } function showLineButton() {