code.gitea.io/gitea@v1.22.3/web_src/js/features/repo-branch.js (about) 1 import $ from 'jquery'; 2 import {toggleElem} from '../utils/dom.js'; 3 4 export function initRepoBranchButton() { 5 initRepoCreateBranchButton(); 6 initRepoRenameBranchButton(); 7 } 8 9 function initRepoCreateBranchButton() { 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 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'); 20 21 $(el.getAttribute('data-modal')).modal('show'); 22 }); 23 } 24 } 25 26 function initRepoRenameBranchButton() { 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; 33 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'); 37 38 const text = modal.querySelector('[data-rename-branch-to]'); 39 text.textContent = text.getAttribute('data-rename-branch-to').replace('%s', oldBranchName); 40 }); 41 } 42 }