|
8 | 8 | async function updateMediaType(attachmentsCount, attachmentListElem) { |
9 | 9 | const mediaTypeElem = document.getElementById('media-type'); |
10 | 10 | const spoilerMediaControl = document.querySelector('.spoiler-media-control'); |
| 11 | + const ghostPostMediaControl = document.querySelector('.ghost-post-media-control'); |
11 | 12 |
|
12 | 13 | let mediaTypeDesc; |
13 | 14 | if (attachmentsCount === 0) { |
14 | 15 | mediaTypeDesc = 'Text 📝'; |
15 | 16 | spoilerMediaControl.style.display = 'none'; |
| 17 | + ghostPostMediaControl.style.display = 'block'; |
16 | 18 | } else if (attachmentsCount === 1) { |
17 | 19 | const singleAttachmentType = |
18 | 20 | attachmentListElem.querySelector('select').value; |
19 | 21 | if (singleAttachmentType === 'Image') mediaTypeDesc = 'Image 🖼️'; |
20 | 22 | else mediaTypeDesc = 'Video 🎬'; |
21 | 23 | spoilerMediaControl.style.display = 'block'; |
| 24 | + ghostPostMediaControl.style.display = 'none'; |
22 | 25 | } else { |
23 | 26 | mediaTypeDesc = 'Carousel 🎠'; |
24 | 27 | spoilerMediaControl.style.display = 'block'; |
| 28 | + ghostPostMediaControl.style.display = 'none'; |
25 | 29 | } |
26 | 30 |
|
27 | 31 | mediaTypeElem.innerText = mediaTypeDesc; |
@@ -72,10 +76,56 @@ document.addEventListener('DOMContentLoaded', async () => { |
72 | 76 | const pollAttachmentOptions = document.getElementById( |
73 | 77 | 'poll-attachment-options' |
74 | 78 | ); |
| 79 | + const ghostPostMediaControl = document.querySelector('.ghost-post-media-control'); |
75 | 80 | if (pollAttachmentOptions.style.display === 'none') { |
76 | 81 | pollAttachmentOptions.style.display = 'block'; |
| 82 | + ghostPostMediaControl.style.display = 'none'; |
77 | 83 | } else { |
78 | 84 | pollAttachmentOptions.style.display = 'none'; |
| 85 | + ghostPostMediaControl.style.display = 'block'; |
79 | 86 | } |
80 | 87 | }); |
| 88 | + |
| 89 | + const ghostPostCheckbox = document.querySelector('input[name="ghostPostMedia"]'); |
| 90 | + const topicTagMediaControl = document.querySelector('.topic-tag-media-control'); |
| 91 | + const linkAttachmentMediaControl = document.querySelector('.link-attachment-media-control'); |
| 92 | + const attachImageMediaControl = document.querySelector('.attach-image-media-control'); |
| 93 | + const replyOptionsMediaControl = document.querySelector('.reply-options-media-control'); |
| 94 | + |
| 95 | + const topicTagInput = document.getElementById('topic-tag'); |
| 96 | + const linkAttachmentInput = document.getElementById('link-attachment'); |
| 97 | + const replyControlSelect = document.getElementById('reply-control'); |
| 98 | + const attachmentsList = document.getElementById('attachments-list'); |
| 99 | + const pollAttachmentOptions = document.getElementById('poll-attachment-options'); |
| 100 | + |
| 101 | + if (ghostPostCheckbox) { |
| 102 | + ghostPostCheckbox.addEventListener('change', async () => { |
| 103 | + // When ghost post is checked, disable fields that are not relevant to ghost posts |
| 104 | + if (ghostPostCheckbox.checked) { |
| 105 | + topicTagMediaControl.style.display = 'none'; |
| 106 | + linkAttachmentMediaControl.style.display = 'none'; |
| 107 | + attachPollButton.style.display = 'none'; |
| 108 | + attachImageMediaControl.style.display = 'none'; |
| 109 | + replyOptionsMediaControl.style.display = 'none'; |
| 110 | + |
| 111 | + if (topicTagInput) topicTagInput.value = ''; |
| 112 | + if (linkAttachmentInput) linkAttachmentInput.value = ''; |
| 113 | + if (replyControlSelect) replyControlSelect.value = ''; |
| 114 | + if (attachmentsList) attachmentsList.innerHTML = ''; |
| 115 | + if (pollAttachmentOptions) { |
| 116 | + pollAttachmentOptions.style.display = 'none'; |
| 117 | + const pollInputs = pollAttachmentOptions.querySelectorAll('input[type="text"]'); |
| 118 | + pollInputs.forEach(input => input.value = ''); |
| 119 | + } |
| 120 | + |
| 121 | + await updateMediaType(0, null); |
| 122 | + } else { // When the checkbox is unchecked, enable all fields |
| 123 | + topicTagMediaControl.style.display = 'block'; |
| 124 | + linkAttachmentMediaControl.style.display = 'block'; |
| 125 | + attachPollButton.style.display = 'block'; |
| 126 | + attachImageMediaControl.style.display = 'block'; |
| 127 | + replyOptionsMediaControl.style.display = 'block'; |
| 128 | + } |
| 129 | + }); |
| 130 | + } |
81 | 131 | }); |
0 commit comments