|
106 | 106 | divider.role = "separator"; |
107 | 107 | menuBottomUl.appendChild(divider); |
108 | 108 | } |
109 | | - |
| 109 | + |
110 | 110 | // Clone and add all menu items to bottom menu |
111 | 111 | menuItems.forEach(item => { |
112 | 112 | const clone = item.cloneNode(true); |
| 113 | + |
113 | 114 | if (clone.tagName === 'LI') { |
114 | 115 | menuBottomUl.appendChild(clone); |
115 | | - } else { |
116 | | - const items = clone.querySelectorAll(':scope > li'); |
117 | | - items.forEach(item => { |
118 | | - const dropdownButton = item.querySelector('.dropdown button') || item.querySelector('.dropdown-toggle'); |
119 | | - if (dropdownButton) { |
120 | | - // Create a new span with bold text |
121 | | - const buttonText = dropdownButton.textContent.trim(); |
122 | | - const boldSpan = document.createElement('span'); |
123 | | - boldSpan.className = "dropdown-submenu-title"; |
124 | | - boldSpan.textContent = buttonText; |
125 | | - |
126 | | - // Add the bold span as a list item |
127 | | - const headerLi = document.createElement('li'); |
128 | | - headerLi.appendChild(boldSpan); |
129 | | - appendDivider(); |
130 | | - menuBottomUl.appendChild(headerLi); |
131 | | - appendDivider(); |
132 | | - |
133 | | - // Get all child items from the dropdown menu |
134 | | - const childItems = item.querySelectorAll('.dropdown-menu > li') || item.querySelectorAll('ul > li'); |
135 | | - if (childItems) { |
136 | | - childItems.forEach(childItem => { |
137 | | - const _childItem = childItem.cloneNode(true); |
138 | | - _childItem.className = `${_childItem.className} dropdown-submenu`; |
139 | | - menuBottomUl.appendChild(_childItem); |
140 | | - }); |
| 116 | + |
| 117 | + const dropdownButton = clone.querySelector('.dropdown button') || clone.querySelector('.dropdown-toggle'); |
| 118 | + if (dropdownButton) { |
| 119 | + dropdownButton.addEventListener('click', function(e) { |
| 120 | + e.preventDefault(); |
| 121 | + e.stopPropagation(); |
| 122 | + const parentElement = dropdownButton.closest('.dropdown'); |
| 123 | + if (parentElement) { |
| 124 | + parentElement.classList.toggle('open'); |
141 | 125 | } |
142 | | - appendDivider(); |
143 | | - } else if (item.tagName === 'LI') { |
144 | | - menuBottomUl.appendChild(item); |
145 | | - } |
146 | | - }); |
| 126 | + }); |
| 127 | + } |
147 | 128 | } |
148 | 129 | }); |
149 | 130 | } |
|
0 commit comments