|
29 | 29 |
|
30 | 30 | const itemsWithSubitems = this.container.querySelectorAll('.ibexa-popup-menu__item--has-subitems'); |
31 | 31 |
|
32 | | - this.initBranch( |
33 | | - this.triggerElement, |
34 | | - topBranch, |
35 | | - this.referenceElement, |
36 | | - this.initialBranchPlacement, |
37 | | - this.initialBranchFallbackPlacements, |
38 | | - this.processBranchOnInitAfter, |
39 | | - this.processItemOnInitAfter, |
40 | | - ); |
| 32 | + this.initBranch({ |
| 33 | + triggerElement: this.triggerElement, |
| 34 | + branchElement: topBranch, |
| 35 | + referenceElement: this.referenceElement, |
| 36 | + placement: this.initialBranchPlacement, |
| 37 | + fallbackPlacements: this.initialBranchFallbackPlacements, |
| 38 | + processBranchAfter: this.processBranchOnInitAfter, |
| 39 | + processBranchItemAfter: this.processItemOnInitAfter, |
| 40 | + }); |
41 | 41 | this.triggerElement.branchElement = topBranch; |
42 | 42 |
|
43 | 43 | itemsWithSubitems.forEach((itemElement) => { |
44 | 44 | const branchElement = itemElement.querySelector(':scope > .ibexa-multilevel-popup-menu__branch'); |
45 | 45 | const parentBranchElement = itemElement.closest('.ibexa-popup-menu'); |
46 | 46 |
|
47 | | - this.initBranch( |
48 | | - itemElement, |
49 | | - branchElement, |
50 | | - undefined, |
51 | | - undefined, |
52 | | - undefined, |
53 | | - this.processBranchOnInitAfter, |
54 | | - this.processItemOnInitAfter, |
55 | | - ); |
| 47 | + this.initBranch({ |
| 48 | + triggerElement: itemElement, |
| 49 | + branchElement: branchElement, |
| 50 | + processBranchAfter: this.processBranchOnInitAfter, |
| 51 | + processBranchItemAfter: this.processItemOnInitAfter, |
| 52 | + }); |
56 | 53 |
|
57 | 54 | itemElement.branchElement = branchElement; |
58 | 55 | branchElement.itemElement = itemElement; |
59 | 56 | branchElement.parentBranchElement = parentBranchElement; |
60 | 57 | }); |
61 | 58 | } |
62 | 59 |
|
63 | | - initBranch( |
| 60 | + initBranch({ |
64 | 61 | triggerElement, |
65 | 62 | branchElement, |
66 | 63 | referenceElement = null, |
67 | 64 | placement = 'right-start', |
68 | 65 | fallbackPlacements = ['right-end', 'left-start', 'left-end'], |
69 | 66 | processBranchAfter = () => {}, |
70 | 67 | processBranchItemAfter = () => {}, |
71 | | - ) { |
| 68 | + }) { |
72 | 69 | doc.body.appendChild(branchElement); |
73 | 70 |
|
74 | 71 | const isTopBranch = !triggerElement.classList.contains('ibexa-popup-menu__item'); |
|
143 | 140 | } |
144 | 141 |
|
145 | 142 | updateBranchAndParentBranchesOpenState(branchElement) { |
146 | | - const isTopBranch = !(branchElement?.parentBranchElement ?? null); |
| 143 | + const isTopBranch = !branchElement?.parentBranchElement; |
147 | 144 |
|
148 | 145 | if (isTopBranch) { |
149 | 146 | return; |
|
265 | 262 |
|
266 | 263 | processAfterCreated(newBranchElement, data); |
267 | 264 |
|
268 | | - this.initBranch(triggerElement, newBranchElement, null, placement, fallbackPlacements); |
| 265 | + this.initBranch({ triggerElement, branchElement: newBranchElement, placement, fallbackPlacements }); |
269 | 266 |
|
270 | 267 | const parentBranchElement = triggerElement.closest('.ibexa-popup-menu'); |
271 | 268 |
|
|
355 | 352 | } |
356 | 353 | } |
357 | 354 |
|
358 | | - isOurBranch(branch) { |
| 355 | + isBranchBelongingToThisMenu(branch) { |
359 | 356 | const topBranch = this.triggerElement.branchElement; |
360 | 357 |
|
361 | | - return !!branch && (topBranch === branch || this.isOurBranch(branch.parentBranchElement)); |
| 358 | + return !!branch && (topBranch === branch || this.isBranchBelongingToThisMenu(branch.parentBranchElement)); |
362 | 359 | } |
363 | 360 |
|
364 | 361 | handleClickOutside(event) { |
|
371 | 368 | const closestPopup = event.target.closest('.ibexa-popup-menu'); |
372 | 369 | const isPopupMenuExpanded = !topBranch.classList.contains('ibexa-popup-menu--hidden'); |
373 | 370 | const isClickInsideTrigger = this.triggerElement.contains(event.target); |
374 | | - const isClickInsideOurBranch = this.isOurBranch(closestPopup); |
| 371 | + const isClickInsideOurBranch = this.isBranchBelongingToThisMenu(closestPopup); |
375 | 372 |
|
376 | 373 | if (!isPopupMenuExpanded || isClickInsideTrigger || isClickInsideOurBranch) { |
377 | 374 | return; |
|
0 commit comments