code.gitea.io/gitea@v1.21.7/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 $('.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 } 21 22 $(fromSpanName).text($(this).attr('data-branch-from')); 23 $($(this).attr('data-modal')).modal('show'); 24 }); 25 } 26 27 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); 34 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 }); 42 }