loading up the forgejo repo on tangled to test page performance
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

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 <git@yardenshoham.com>
Co-authored-by: silverwind <me@silverwind.io>
Co-authored-by: delvh <dev.lh@web.de>
Co-authored-by: Giteabot <teabot@gitea.io>
(cherry picked from commit 4efe7884a3c99235b39998472ea430bffe0799e5)

authored by

Yarden Shoham
silverwind
delvh
Giteabot
and committed by
Earl Warren
4249512c 8bc4c1c9

+25 -25
+25 -25
web_src/js/features/repo-branch.js
··· 8 8 9 9 function initRepoCreateBranchButton() { 10 10 // 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')}`; 17 + 18 + const fromSpanName = el.getAttribute('data-modal-from-span') || '#modal-create-branch-from-span'; 19 + document.querySelector(fromSpanName).textContent = el.getAttribute('data-branch-from'); 21 20 22 - $(fromSpanName).text($(this).attr('data-branch-from')); 23 - $($(this).attr('data-modal')).modal('show'); 24 - }); 21 + $(el.getAttribute('data-modal')).modal('show'); 22 + }); 23 + } 25 24 } 26 25 27 26 function initRepoRenameBranchButton() { 28 - $('.show-rename-branch-modal').on('click', function () { 29 - const target = $(this).attr('data-modal'); 30 - const $modal = $(target); 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; 31 33 32 - const oldBranchName = $(this).attr('data-old-branch-name'); 33 - $modal.find('input[name=from]').val(oldBranchName); 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'); 34 37 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'); 38 - 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 + } 42 42 }