diff --git a/routers/web/repo/find.go b/routers/web/repo/find.go index 07b372279882..9da4237c1edd 100644 --- a/routers/web/repo/find.go +++ b/routers/web/repo/find.go @@ -7,6 +7,7 @@ import ( "net/http" "code.gitea.io/gitea/modules/base" + "code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/services/context" ) @@ -17,7 +18,7 @@ const ( // FindFiles render the page to find repository files func FindFiles(ctx *context.Context) { path := ctx.Params("*") - ctx.Data["TreeLink"] = ctx.Repo.RepoLink + "/src/" + path - ctx.Data["DataLink"] = ctx.Repo.RepoLink + "/tree-list/" + path + ctx.Data["TreeLink"] = ctx.Repo.RepoLink + "/src/" + util.PathEscapeSegments(path) + ctx.Data["DataLink"] = ctx.Repo.RepoLink + "/tree-list/" + util.PathEscapeSegments(path) ctx.HTML(http.StatusOK, tplFindFiles) } diff --git a/web_src/js/features/imagediff.js b/web_src/js/features/imagediff.js index 7b77b30ccc76..d567632f5f15 100644 --- a/web_src/js/features/imagediff.js +++ b/web_src/js/features/imagediff.js @@ -98,8 +98,10 @@ export function initImageDiff() { const text = await resp.text(); const bounds = getDefaultSvgBoundsIfUndefined(text, info.path); if (bounds) { - info.$images.attr('width', bounds.width); - info.$images.attr('height', bounds.height); + info.$images.each(function() { + this.setAttribute('width', bounds.width); + this.setAttribute('height', bounds.height); + }); hideElem(info.$boundsInfo); } } diff --git a/web_src/js/features/repo-diff.js b/web_src/js/features/repo-diff.js index 20a65779326f..262ce2abffd1 100644 --- a/web_src/js/features/repo-diff.js +++ b/web_src/js/features/repo-diff.js @@ -13,16 +13,20 @@ import {POST, GET} from '../modules/fetch.js'; const {pageData, i18n} = window.config; function initRepoDiffReviewButton() { - const $reviewBox = $('#review-box'); - const $counter = $reviewBox.find('.review-comments-counter'); + const reviewBox = document.getElementById('review-box'); + if (!reviewBox) return; + + const $reviewBox = $(reviewBox); + const counter = reviewBox.querySelector('.review-comments-counter'); + if (!counter) return; $(document).on('click', 'button[name="pending_review"]', (e) => { const $form = $(e.target).closest('form'); // Watch for the form's submit event. $form.on('submit', () => { - const num = parseInt($counter.attr('data-pending-comment-number')) + 1 || 1; - $counter.attr('data-pending-comment-number', num); - $counter.text(num); + const num = parseInt(counter.getAttribute('data-pending-comment-number')) + 1 || 1; + counter.setAttribute('data-pending-comment-number', num); + counter.textContent = num; // Force the browser to reflow the DOM. This is to ensure that the browser replay the animation $reviewBox.removeClass('pulse'); $reviewBox.width(); @@ -65,7 +69,7 @@ function initRepoDiffConversationForm() { formData.append(submitter.name, submitter.value); } - const response = await POST($form.attr('action'), {data: formData}); + const response = await POST(e.target.getAttribute('action'), {data: formData}); const $newConversationHolder = $(await response.text()); const {path, side, idx} = $newConversationHolder.data(); @@ -118,7 +122,7 @@ export function initRepoDiffConversationNav() { const index = $conversations.index($conversation); const previousIndex = index > 0 ? index - 1 : $conversations.length - 1; const $previousConversation = $conversations.eq(previousIndex); - const anchor = $previousConversation.find('.comment').first().attr('id'); + const anchor = $previousConversation.find('.comment').first()[0].getAttribute('id'); window.location.href = `#${anchor}`; }); $(document).on('click', '.next-conversation', (e) => { @@ -127,7 +131,7 @@ export function initRepoDiffConversationNav() { const index = $conversations.index($conversation); const nextIndex = index < $conversations.length - 1 ? index + 1 : 0; const $nextConversation = $conversations.eq(nextIndex); - const anchor = $nextConversation.find('.comment').first().attr('id'); + const anchor = $nextConversation.find('.comment').first()[0].getAttribute('id'); window.location.href = `#${anchor}`; }); } @@ -173,8 +177,7 @@ function initRepoDiffShowMore() { $(document).on('click', 'a#diff-show-more-files', (e) => { e.preventDefault(); - const $target = $(e.target); - const linkLoadMore = $target.attr('data-href'); + const linkLoadMore = e.target.getAttribute('data-href'); loadMoreFiles(linkLoadMore); }); diff --git a/web_src/js/features/repo-settings.js b/web_src/js/features/repo-settings.js index 58b714fbb7bf..dc1db8ab29a9 100644 --- a/web_src/js/features/repo-settings.js +++ b/web_src/js/features/repo-settings.js @@ -8,22 +8,22 @@ const {appSubUrl, csrfToken} = window.config; export function initRepoSettingsCollaboration() { // Change collaborator access mode - $('.page-content.repository .ui.dropdown.access-mode').each((_, e) => { - const $dropdown = $(e); + $('.page-content.repository .ui.dropdown.access-mode').each((_, el) => { + const $dropdown = $(el); const $text = $dropdown.find('> .text'); $dropdown.dropdown({ async action(_text, value) { - const lastValue = $dropdown.attr('data-last-value'); + const lastValue = el.getAttribute('data-last-value'); try { - $dropdown.attr('data-last-value', value); + el.setAttribute('data-last-value', value); $dropdown.dropdown('hide'); const data = new FormData(); - data.append('uid', $dropdown.attr('data-uid')); + data.append('uid', el.getAttribute('data-uid')); data.append('mode', value); - await POST($dropdown.attr('data-url'), {data}); + await POST(el.getAttribute('data-url'), {data}); } catch { $text.text('(error)'); // prevent from misleading users when error occurs - $dropdown.attr('data-last-value', lastValue); + el.setAttribute('data-last-value', lastValue); } }, onChange(_value, text, _$choice) { @@ -32,9 +32,9 @@ export function initRepoSettingsCollaboration() { onHide() { // set to the really selected value, defer to next tick to make sure `action` has finished its work because the calling order might be onHide -> action setTimeout(() => { - const $item = $dropdown.dropdown('get item', $dropdown.attr('data-last-value')); + const $item = $dropdown.dropdown('get item', el.getAttribute('data-last-value')); if ($item) { - $dropdown.dropdown('set selected', $dropdown.attr('data-last-value')); + $dropdown.dropdown('set selected', el.getAttribute('data-last-value')); } else { $text.text('(none)'); // prevent from misleading users when the access mode is undefined } @@ -45,11 +45,13 @@ export function initRepoSettingsCollaboration() { } export function initRepoSettingSearchTeamBox() { - const $searchTeamBox = $('#search-team-box'); - $searchTeamBox.search({ + const searchTeamBox = document.getElementById('search-team-box'); + if (!searchTeamBox) return; + + $(searchTeamBox).search({ minCharacters: 2, apiSettings: { - url: `${appSubUrl}/org/${$searchTeamBox.attr('data-org-name')}/teams/-/search?q={query}`, + url: `${appSubUrl}/org/${searchTeamBox.getAttribute('data-org-name')}/teams/-/search?q={query}`, headers: {'X-Csrf-Token': csrfToken}, onResponse(response) { const items = []; @@ -77,11 +79,11 @@ export function initRepoSettingGitHook() { export function initRepoSettingBranches() { if (!$('.repository.settings.branches').length) return; $('.toggle-target-enabled').on('change', function () { - const $target = $($(this).attr('data-target')); + const $target = $(this.getAttribute('data-target')); $target.toggleClass('disabled', !this.checked); }); $('.toggle-target-disabled').on('change', function () { - const $target = $($(this).attr('data-target')); + const $target = $(this.getAttribute('data-target')); if (this.checked) $target.addClass('disabled'); // only disable, do not auto enable }); $('#dismiss_stale_approvals').on('change', function () {