aboutsummaryrefslogtreecommitdiffstats
path: root/web_src/js/features
diff options
context:
space:
mode:
authorwxiaoguang <wxiaoguang@gmail.com>2024-05-02 18:45:23 +0800
committerGitHub <noreply@github.com>2024-05-02 10:45:23 +0000
commitebe6f4cad775a82d11c916c9af716beec394768b (patch)
tree7b13a7faf0fdcb1f7835b1a27cd91ff809694ac6 /web_src/js/features
parent82eca44581100d96e11097db743804bc398d1742 (diff)
downloadgitea-ebe6f4cad775a82d11c916c9af716beec394768b.tar.gz
gitea-ebe6f4cad775a82d11c916c9af716beec394768b.zip
Fix branch selector UI (#30803)
Fix #30802
Diffstat (limited to 'web_src/js/features')
-rw-r--r--web_src/js/features/repo-legacy.js25
1 files changed, 14 insertions, 11 deletions
diff --git a/web_src/js/features/repo-legacy.js b/web_src/js/features/repo-legacy.js
index 18d98c891d..670e60def0 100644
--- a/web_src/js/features/repo-legacy.js
+++ b/web_src/js/features/repo-legacy.js
@@ -19,7 +19,7 @@ import {initCompReactionSelector} from './comp/ReactionSelector.js';
import {initRepoSettingBranches} from './repo-settings.js';
import {initRepoPullRequestMergeForm} from './repo-issue-pr-form.js';
import {initRepoPullRequestCommitStatus} from './repo-issue-pr-status.js';
-import {hideElem, showElem} from '../utils/dom.js';
+import {hideElem, queryElemChildren, showElem} from '../utils/dom.js';
import {POST} from '../modules/fetch.js';
import {initRepoIssueCommentEdit} from './repo-issue-edit.js';
@@ -56,16 +56,19 @@ export function initRepoCommentForm() {
}
function initBranchSelector() {
- const $selectBranch = $('.ui.select-branch');
+ const elSelectBranch = document.querySelector('.ui.dropdown.select-branch');
+ const isForNewIssue = elSelectBranch.getAttribute('data-for-new-issue') === 'true';
+
+ const $selectBranch = $(elSelectBranch);
const $branchMenu = $selectBranch.find('.reference-list-menu');
- const $isNewIssue = $branchMenu.hasClass('new-issue');
- $branchMenu.find('.item:not(.no-select)').on('click', async function () {
- const selectedValue = $(this).data('id');
+ $branchMenu.find('.item:not(.no-select)').on('click', async function (e) {
+ e.preventDefault();
+ const selectedValue = $(this).data('id'); // eg: "refs/heads/my-branch"
const editMode = $('#editing_mode').val();
$($(this).data('id-selector')).val(selectedValue);
- if ($isNewIssue) {
- $selectBranch.find('.ui .branch-name').text($(this).data('name'));
- return;
+ if (isForNewIssue) {
+ elSelectBranch.querySelector('.text-branch-name').textContent = this.getAttribute('data-name');
+ return; // only update UI&form, do not send request/reload
}
if (editMode === 'true') {
@@ -84,9 +87,9 @@ export function initRepoCommentForm() {
});
$selectBranch.find('.reference.column').on('click', function () {
hideElem($selectBranch.find('.scrolling.reference-list-menu'));
- $selectBranch.find('.reference .text').removeClass('black');
- showElem($($(this).data('target')));
- $(this).find('.text').addClass('black');
+ showElem(this.getAttribute('data-target'));
+ queryElemChildren(this.parentNode, '.branch-tag-item', (el) => el.classList.remove('active'));
+ this.classList.add('active');
return false;
});
}