|
41 | 41 | return; |
42 | 42 | } |
43 | 43 |
|
44 | | - if (this.findAncestor(this, 'joomla-tab')) { |
| 44 | + if (this.parentNode.closest('joomla-tab')) { |
45 | 45 | this.isNested = true; |
46 | 46 | } |
47 | 47 |
|
|
72 | 72 |
|
73 | 73 | // Add the parent tab to the array for activation |
74 | 74 | if (element) { |
75 | | - const currentTabSet = this.findAncestor(element, 'joomla-tab'); |
76 | | - const parentTabSet = this.findAncestor(currentTabSet, 'joomla-tab'); |
| 75 | + const currentTabSet = element.closest('joomla-tab'); |
| 76 | + |
| 77 | + if (this.isNested) { |
| 78 | + const parentTab = currentTabSet.closest('section'); |
77 | 79 |
|
78 | | - if (parentTabSet) { |
79 | | - const parentTab = this.findAncestor(currentTabSet, 'section'); |
80 | 80 | if (parentTab) { |
81 | 81 | tabLinkHash.push(`#tab-${parentTab.id}`); |
82 | 82 | } |
|
151 | 151 |
|
152 | 152 | if (element) { |
153 | 153 | // Activate any parent tabs (nested tables) |
154 | | - const currentTabSet = this.findAncestor(element, 'joomla-tab'); |
155 | | - const parentTabSet = this.findAncestor(currentTabSet, 'joomla-tab'); |
| 154 | + const currentTabSet = element.closest('joomla-tab'); |
156 | 155 |
|
157 | | - if (parentTabSet) { |
158 | | - const parentTab = this.findAncestor(currentTabSet, 'section'); |
| 156 | + if (this.isNested) { |
| 157 | + const parentTabSet = currentTabSet.closest('joomla-tab'); |
| 158 | + const parentTab = currentTabSet.closest('section'); |
159 | 159 | parentTabSet.showTab(parentTab); |
160 | 160 | // Now activate the given tab |
161 | 161 | this.show(element); |
|
273 | 273 | } |
274 | 274 |
|
275 | 275 | showTab(tab) { |
276 | | - const tabLink = document.querySelector(`#${tab.id}`); |
| 276 | + const tabLink = document.querySelector(`#tab-${tab.id}`); |
277 | 277 | tabLink.click(); |
278 | 278 | } |
279 | 279 |
|
|
383 | 383 | } |
384 | 384 | } |
385 | 385 |
|
386 | | - findAncestor(el, tagName) { |
387 | | - let element = el; |
388 | | - while (element.nodeName.toLowerCase() !== tagName) { |
389 | | - // Ensure we haven't reached the top of the dom tree |
390 | | - if (element.parentElement === null) { |
391 | | - return false; |
392 | | - } |
393 | | - element = element.parentElement; |
394 | | - } |
395 | | - return element; |
396 | | - } |
397 | | - |
398 | 386 | /* Method to dispatch events */ |
399 | 387 | dispatchCustomEvent(eventName, element, related) { |
400 | 388 | const OriginalCustomEvent = new CustomEvent(eventName, { bubbles: true, cancelable: true }); |
|
0 commit comments