Implement external assets

This commit is contained in:
Malte Jürgens 2023-09-15 18:20:16 +02:00
parent 2e234300a2
commit a61e7c7a39
No known key found for this signature in database
22 changed files with 826 additions and 119 deletions

View file

@ -6,7 +6,8 @@ export function initRepoRelease() {
el.addEventListener('click', (e) => {
const uuid = e.target.getAttribute('data-uuid');
const id = e.target.getAttribute('data-id');
document.querySelector(`input[name='attachment-del-${uuid}']`).value = 'true';
document.querySelector(`input[name='attachment-del-${uuid}']`).value =
'true';
hideElem(`#attachment-${id}`);
});
}
@ -17,6 +18,7 @@ export function initRepoReleaseNew() {
initTagNameEditor();
initRepoReleaseEditor();
initAddExternalLinkButton();
}
function initTagNameEditor() {
@ -45,9 +47,49 @@ function initTagNameEditor() {
}
function initRepoReleaseEditor() {
const editor = document.querySelector('.repository.new.release .combo-markdown-editor');
const editor = document.querySelector(
'.repository.new.release .combo-markdown-editor',
);
if (!editor) {
return;
}
initComboMarkdownEditor(editor);
}
let newAttachmentCount = 0;
function initAddExternalLinkButton() {
const addExternalLinkButton = document.getElementById('add-external-link');
if (!addExternalLinkButton) return;
addExternalLinkButton.addEventListener('click', () => {
newAttachmentCount += 1;
const attachmentTemplate = document.getElementById('attachment-template');
const newAttachment = attachmentTemplate.cloneNode(true);
newAttachment.id = `attachment-N${newAttachmentCount}`;
newAttachment.classList.remove('tw-hidden');
const attachmentName = newAttachment.querySelector(
'input[name="attachment-template-new-name"]',
);
attachmentName.name = `attachment-new-name-${newAttachmentCount}`;
attachmentName.required = true;
const attachmentExtUrl = newAttachment.querySelector(
'input[name="attachment-template-new-exturl"]',
);
attachmentExtUrl.name = `attachment-new-exturl-${newAttachmentCount}`;
attachmentExtUrl.required = true;
const attachmentDel = newAttachment.querySelector('.remove-rel-attach');
attachmentDel.addEventListener('click', () => {
newAttachment.remove();
});
attachmentTemplate.parentNode.insertBefore(
newAttachment,
attachmentTemplate,
);
});
}