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

     1  import {hideElem, showElem} from '../utils/dom.js';
     2  import {initComboMarkdownEditor} from './comp/ComboMarkdownEditor.js';
     3  
     4  export function initRepoRelease() {
     5    document.addEventListener('click', (e) => {
     6      if (e.target.matches('.remove-rel-attach')) {
     7        const uuid = e.target.getAttribute('data-uuid');
     8        const id = e.target.getAttribute('data-id');
     9        document.querySelector(`input[name='attachment-del-${uuid}']`).value = 'true';
    10        hideElem(`#attachment-${id}`);
    11      }
    12    });
    13  }
    14  
    15  export function initRepoReleaseNew() {
    16    if (!document.querySelector('.repository.new.release')) 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    const tagNameInput = document.getElementById('tag-name');
    34    const hideTargetInput = function(tagNameInput) {
    35      const value = tagNameInput.value;
    36      const tagHelper = document.getElementById('tag-helper');
    37      if (existingTags.includes(value)) {
    38        // If the tag already exists, hide the target branch selector.
    39        hideElem('#tag-target-selector');
    40        tagHelper.textContent = existingTagHelperText;
    41      } else {
    42        showElem('#tag-target-selector');
    43        tagHelper.textContent = value ? newTagHelperText : defaultTagHelperText;
    44      }
    45    };
    46    hideTargetInput(tagNameInput); // update on page load because the input may have a value
    47    tagNameInput.addEventListener('input', (e) => {
    48      hideTargetInput(e.target);
    49    });
    50  }
    51  
    52  function initRepoReleaseEditor() {
    53    const editor = document.querySelector('.repository.new.release .combo-markdown-editor');
    54    if (!editor) {
    55      return;
    56    }
    57    initComboMarkdownEditor(editor);
    58  }