diff options
author | wxiaoguang <wxiaoguang@gmail.com> | 2023-02-08 00:08:44 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-08 00:08:44 +0800 |
commit | 2c6cc0b8c982b3d49a5b208f75e15b2269584312 (patch) | |
tree | 09746485be5f6c534082585f137c921d6a34ab75 /web_src/js/features/repo-code.js | |
parent | d5fa2e7510844ad092804b7c11bf6847f7c4e45d (diff) | |
download | gitea-2c6cc0b8c982b3d49a5b208f75e15b2269584312.tar.gz gitea-2c6cc0b8c982b3d49a5b208f75e15b2269584312.zip |
Fix links for the menus in the view file page (#22795)
Diffstat (limited to 'web_src/js/features/repo-code.js')
-rw-r--r-- | web_src/js/features/repo-code.js | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/web_src/js/features/repo-code.js b/web_src/js/features/repo-code.js index 083a17bf21..1c59913132 100644 --- a/web_src/js/features/repo-code.js +++ b/web_src/js/features/repo-code.js @@ -3,6 +3,7 @@ import {svg} from '../svg.js'; import {invertFileFolding} from './file-fold.js'; import {createTippy} from '../modules/tippy.js'; import {copyToClipboard} from './clipboard.js'; +import {toAbsoluteUrl} from '../utils.js'; export const singleAnchorRegex = /^#(L|n)([1-9][0-9]*)$/; export const rangeAnchorRegex = /^#(L[1-9][0-9]*)-(L[1-9][0-9]*)$/; @@ -19,17 +20,18 @@ function selectRange($list, $select, $from) { $list.removeClass('active'); // add hashchange to permalink - const $issue = $('a.ref-in-new-issue'); + const $refInNewIssue = $('a.ref-in-new-issue'); const $copyPermalink = $('a.copy-line-permalink'); const $viewGitBlame = $('a.view_git_blame'); const updateIssueHref = function (anchor) { - if ($issue.length === 0) { + if ($refInNewIssue.length === 0) { return; } - let href = $issue.attr('href'); - href = `${href.replace(/%23L\d+$|%23L\d+-L\d+$/, '')}%23${anchor}`; - $issue.attr('href', href); + const urlIssueNew = $refInNewIssue.attr('data-url-issue-new'); + const urlParamBodyLink = $refInNewIssue.attr('data-url-param-body-link'); + const issueContent = `${toAbsoluteUrl(urlParamBodyLink)}#${anchor}`; // the default content for issue body + $refInNewIssue.attr('href', `${urlIssueNew}?body=${encodeURIComponent(issueContent)}`); }; const updateViewGitBlameFragment = function (anchor) { @@ -188,7 +190,7 @@ export function initRepoCodeView() { currentTarget.closest('tr').outerHTML = blob; }); $(document).on('click', '.copy-line-permalink', async (e) => { - const success = await copyToClipboard(e.currentTarget.getAttribute('data-url')); + const success = await copyToClipboard(toAbsoluteUrl(e.currentTarget.getAttribute('data-url'))); if (!success) return; document.querySelector('.code-line-button')?._tippy?.hide(); }); |