Skip to content

Commit 4efe788

Browse files
yardenshohamsilverwinddelvhGiteaBot
authored
Remove jQuery from the create/rename branch modals (except Fomantic) (#30109)
- Switched to plain JavaScript - Tested the create/rename branch modals' functionality and they work as before # Demo using JavaScript without jQuery ![demo](https://github.com/go-gitea/gitea/assets/20454870/ca53155e-856e-44ca-9852-12ff60065735) --------- Signed-off-by: Yarden Shoham <[email protected]> Co-authored-by: silverwind <[email protected]> Co-authored-by: delvh <[email protected]> Co-authored-by: Giteabot <[email protected]>
1 parent 643e6b0 commit 4efe788

File tree

1 file changed

+25
-25
lines changed

1 file changed

+25
-25
lines changed

web_src/js/features/repo-branch.js

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,35 +8,35 @@ export function initRepoBranchButton() {
88

99
function initRepoCreateBranchButton() {
1010
// 2 pages share this code, one is the branch list page, the other is the commit view page: create branch/tag from current commit (dirty code)
11-
$('.show-create-branch-modal').on('click', function () {
12-
let modalFormName = $(this).attr('data-modal-form');
13-
if (!modalFormName) {
14-
modalFormName = '#create-branch-form';
15-
}
16-
$(modalFormName)[0].action = $(modalFormName).attr('data-base-action') + $(this).attr('data-branch-from-urlcomponent');
17-
let fromSpanName = $(this).attr('data-modal-from-span');
18-
if (!fromSpanName) {
19-
fromSpanName = '#modal-create-branch-from-span';
20-
}
11+
for (const el of document.querySelectorAll('.show-create-branch-modal')) {
12+
el.addEventListener('click', () => {
13+
const modalFormName = el.getAttribute('data-modal-form') || '#create-branch-form';
14+
const modalForm = document.querySelector(modalFormName);
15+
if (!modalForm) return;
16+
modalForm.action = `${modalForm.getAttribute('data-base-action')}${el.getAttribute('data-branch-from-urlcomponent')}`;
2117

22-
$(fromSpanName).text($(this).attr('data-branch-from'));
23-
$($(this).attr('data-modal')).modal('show');
24-
});
18+
const fromSpanName = el.getAttribute('data-modal-from-span') || '#modal-create-branch-from-span';
19+
document.querySelector(fromSpanName).textContent = el.getAttribute('data-branch-from');
20+
21+
$(el.getAttribute('data-modal')).modal('show');
22+
});
23+
}
2524
}
2625

2726
function initRepoRenameBranchButton() {
28-
$('.show-rename-branch-modal').on('click', function () {
29-
const target = $(this).attr('data-modal');
30-
const $modal = $(target);
31-
32-
const oldBranchName = $(this).attr('data-old-branch-name');
33-
$modal.find('input[name=from]').val(oldBranchName);
27+
for (const el of document.querySelectorAll('.show-rename-branch-modal')) {
28+
el.addEventListener('click', () => {
29+
const target = el.getAttribute('data-modal');
30+
const modal = document.querySelector(target);
31+
const oldBranchName = el.getAttribute('data-old-branch-name');
32+
modal.querySelector('input[name=from]').value = oldBranchName;
3433

35-
// display the warning that the branch which is chosen is the default branch
36-
const $warn = $modal.find('.default-branch-warning');
37-
toggleElem($warn, $(this).attr('data-is-default-branch') === 'true');
34+
// display the warning that the branch which is chosen is the default branch
35+
const warn = modal.querySelector('.default-branch-warning');
36+
toggleElem(warn, el.getAttribute('data-is-default-branch') === 'true');
3837

39-
const $text = $modal.find('[data-rename-branch-to]');
40-
$text.text($text.attr('data-rename-branch-to').replace('%s', oldBranchName));
41-
});
38+
const text = modal.querySelector('[data-rename-branch-to]');
39+
text.textContent = text.getAttribute('data-rename-branch-to').replace('%s', oldBranchName);
40+
});
41+
}
4242
}

0 commit comments

Comments
 (0)