(hideButton: Element)
| 12 | ] as const; |
| 13 | |
| 14 | function generateSubmenu(hideButton: Element): void { |
| 15 | if (closestElementOptional('.rgh-quick-comment-hiding-details', hideButton)) { |
| 16 | // Already generated |
| 17 | return; |
| 18 | } |
| 19 | |
| 20 | const detailsElement = closestElement('details', hideButton); |
| 21 | detailsElement.classList.add('rgh-quick-comment-hiding-details'); |
| 22 | |
| 23 | const comment = closestElement('.unminimized-comment', hideButton); |
| 24 | const hideCommentForm = $(formSelector, comment); |
| 25 | |
| 26 | // Generate dropdown |
| 27 | const newForm = hideCommentForm.cloneNode(); |
| 28 | const fields = [...hideCommentForm.elements].map(field => field.cloneNode()); |
| 29 | newForm.append(<i hidden>{fields}</i>); // Add existing fields (comment ID, token) |
| 30 | newForm.setAttribute('novalidate', 'true'); // Ignore the form's required attributes |
| 31 | |
| 32 | // Imitate existing menu, reset classes |
| 33 | newForm.className = ''; |
| 34 | newForm.classList.add( |
| 35 | 'js-comment-minimize', |
| 36 | 'dropdown-menu', |
| 37 | 'dropdown-menu-sw', |
| 38 | 'color-fg-default', |
| 39 | 'show-more-popover', |
| 40 | 'anim-scale-in', |
| 41 | ); |
| 42 | |
| 43 | for (const reason of $$('option:not([value=""])', hideCommentForm.elements.classifier)) { |
| 44 | newForm.append( |
| 45 | <button |
| 46 | type="submit" |
| 47 | name="classifier" |
| 48 | value={reason.value} |
| 49 | className="dropdown-item btn-link" |
| 50 | role="menuitem" |
| 51 | > |
| 52 | {reason.textContent} |
| 53 | </button>, |
| 54 | ); |
| 55 | } |
| 56 | |
| 57 | // Close immediately after the clicking option |
| 58 | newForm.addEventListener('click', () => { |
| 59 | detailsElement.open = false; |
| 60 | }); |
| 61 | |
| 62 | detailsElement.append(newForm); |
| 63 | } |
| 64 | |
| 65 | // Shows menu on top of mainDropdownContent when "Hide" is clicked; |
| 66 | // Hide it when dropdown closes. |
no test coverage detected