code.gitea.io/gitea@v1.21.7/web_src/js/features/repo-release.js (about)

     1  import $ from 'jquery';
     2  import {hideElem, showElem} from '../utils/dom.js';
     3  import {initComboMarkdownEditor} from './comp/ComboMarkdownEditor.js';
     4  
     5  export function initRepoRelease() {
     6    $(document).on('click', '.remove-rel-attach', function() {
     7      const uuid = $(this).data('uuid');
     8      const id = $(this).data('id');
     9      $(`input[name='attachment-del-${uuid}']`).attr('value', true);
    10      hideElem($(`#attachment-${id}`));
    11    });
    12  }
    13  
    14  export function initRepoReleaseNew() {
    15    const $repoReleaseNew = $('.repository.new.release');
    16    if (!$repoReleaseNew.length) return;
    17  
    18    initTagNameEditor();
    19    initRepoReleaseEditor();
    20  }
    21  
    22  function initTagNameEditor() {
    23    const el = document.getElementById('tag-name-editor');
    24    if (!el) return;
    25  
    26    const existingTags = JSON.parse(el.getAttribute('data-existing-tags'));
    27    if (!Array.isArray(existingTags)) return;
    28  
    29    const defaultTagHelperText = el.getAttribute('data-tag-helper');
    30    const newTagHelperText = el.getAttribute('data-tag-helper-new');
    31    const existingTagHelperText = el.getAttribute('data-tag-helper-existing');
    32  
    33    document.getElementById('tag-name').addEventListener('keyup', (e) => {
    34      const value = e.target.value;
    35      const tagHelper = document.getElementById('tag-helper');
    36      if (existingTags.includes(value)) {
    37        // If the tag already exists, hide the target branch selector.
    38        hideElem('#tag-target-selector');
    39        tagHelper.textContent = existingTagHelperText;
    40      } else {
    41        showElem('#tag-target-selector');
    42        tagHelper.textContent = value ? newTagHelperText : defaultTagHelperText;
    43      }
    44    });
    45  }
    46  
    47  function initRepoReleaseEditor() {
    48    const $editor = $('.repository.new.release .combo-markdown-editor');
    49    if ($editor.length === 0) {
    50      return;
    51    }
    52    const _promise = initComboMarkdownEditor($editor);
    53  }