1
1
mirror of https://github.com/go-gitea/gitea synced 2024-11-18 16:14:26 +00:00
gitea/web_src/js/features/repo-release.js
silverwind d5b2bf9044
Update JS dependencies, add new eslint rules (#24597)
- Update all JS dependencies
- Enable new eslint rules, fix issue (some via autofix)
- Fix some missed eslint rule renames from [unicorn
v25](https://github.com/sindresorhus/eslint-plugin-unicorn/releases/tag/v25.0.0)
- Tested Monaco, Katex, Swagger UI

---------

Co-authored-by: 6543 <6543@obermui.de>
Co-authored-by: Giteabot <teabot@gitea.io>
2023-05-09 02:35:49 +00:00

54 lines
1.7 KiB
JavaScript

import $ from 'jquery';
import {hideElem, showElem} from '../utils/dom.js';
import {initComboMarkdownEditor} from './comp/ComboMarkdownEditor.js';
export function initRepoRelease() {
$(document).on('click', '.remove-rel-attach', function() {
const uuid = $(this).data('uuid');
const id = $(this).data('id');
$(`input[name='attachment-del-${uuid}']`).attr('value', true);
hideElem($(`#attachment-${id}`));
});
}
export function initRepoReleaseNew() {
const $repoReleaseNew = $('.repository.new.release');
if (!$repoReleaseNew.length) return;
initTagNameEditor();
initRepoReleaseEditor();
}
function initTagNameEditor() {
const el = document.getElementById('tag-name-editor');
if (!el) return;
const existingTags = JSON.parse(el.getAttribute('data-existing-tags'));
if (!Array.isArray(existingTags)) return;
const defaultTagHelperText = el.getAttribute('data-tag-helper');
const newTagHelperText = el.getAttribute('data-tag-helper-new');
const existingTagHelperText = el.getAttribute('data-tag-helper-existing');
document.getElementById('tag-name').addEventListener('keyup', (e) => {
const value = e.target.value;
const tagHelper = document.getElementById('tag-helper');
if (existingTags.includes(value)) {
// If the tag already exists, hide the target branch selector.
hideElem('#tag-target-selector');
tagHelper.textContent = existingTagHelperText;
} else {
showElem('#tag-target-selector');
tagHelper.textContent = value ? newTagHelperText : defaultTagHelperText;
}
});
}
function initRepoReleaseEditor() {
const $editor = $('.repository.new.release .combo-markdown-editor');
if ($editor.length === 0) {
return;
}
const _promise = initComboMarkdownEditor($editor);
}