Skip to content

Commit

Permalink
after CR
Browse files Browse the repository at this point in the history
  • Loading branch information
tischsoic committed Sep 10, 2023
1 parent 472effa commit b9de87f
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 42 deletions.
25 changes: 14 additions & 11 deletions src/bundle/Resources/public/js/scripts/admin.context.menu.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
(function (global, doc, ibexa) {
const adapatItemsContainer = doc.querySelector('.ibexa-context-menu');
const adaptedItemsContainer = doc.querySelector('.ibexa-context-menu');

if (!adapatItemsContainer) {
if (!adaptedItemsContainer) {
return;
}

const menuButtons = [
...adapatItemsContainer.querySelectorAll(
...adaptedItemsContainer.querySelectorAll(
'.ibexa-context-menu__item > .ibexa-btn:not(.ibexa-btn--more), .ibexa-context-menu__item > .ibexa-split-btn',
),
];
const popupMenuElement = adapatItemsContainer.querySelector('.ibexa-context-menu__item--more .ibexa-multilevel-popup-menu');
const showPopupButton = adapatItemsContainer.querySelector('.ibexa-btn--more');
const popupMenuElement = adaptedItemsContainer.querySelector('.ibexa-context-menu__item--more .ibexa-multilevel-popup-menu');
const showPopupButton = adaptedItemsContainer.querySelector('.ibexa-btn--more');

if (!showPopupButton) {
return;
}

const adaptiveItems = new ibexa.core.AdaptiveItems({
itemHiddenClass: 'ibexa-context-menu__item--hidden',
container: adapatItemsContainer,
container: adaptedItemsContainer,
getActiveItem: () => {
return adapatItemsContainer.querySelector('.ibexa-context-menu__item');
return adaptedItemsContainer.querySelector('.ibexa-context-menu__item');
},
onAdapted: (visibleItems, hiddenItems) => {
const hiddenButtonsIds = [...hiddenItems].map((item) => item.querySelector('.ibexa-btn').id);
Expand All @@ -35,11 +35,13 @@
},
});
const clickRelatedBtn = (relatedBtnId) => {
const button = doc.getElementById(relatedBtnId);
const relatedBtn = doc.getElementById(relatedBtnId);

button.click();
relatedBtn.click();
};
const addRelatedBtnIdToMenuItem = (itemElement, relatedBtnId) => {
itemElement.dataset.relatedBtnId = relatedBtnId;
};
const addRelatedBtnIdToMenuItem = (itemElement, relatedBtnId) => (itemElement.dataset.relatedBtnId = relatedBtnId);
const multilevelPopupMenu = new ibexa.core.MultilevelPopupMenu({
container: popupMenuElement,
triggerElement: showPopupButton,
Expand Down Expand Up @@ -127,8 +129,9 @@
};

multilevelPopupMenu.init();

const topBranch = multilevelPopupMenu.generateMenu(menuTree);

adaptiveItems.init();
adapatItemsContainer.classList.remove('ibexa-context-menu--before-adaptive-items-init');
adaptedItemsContainer.classList.remove('ibexa-context-menu--before-adaptive-items-init');
})(window, window.document, window.ibexa);
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
multilevelPopupMenusContainers.forEach((container) => {
const multilevelPopupMenu = new ibexa.core.MultilevelPopupMenu({
container,
triggerElement: doc.querySelector('#asdf'),
triggerElement: doc.querySelector(container.dataset.triggerElementSelector),
});

multilevelPopupMenu.init();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,46 +29,43 @@

const itemsWithSubitems = this.container.querySelectorAll('.ibexa-popup-menu__item--has-subitems');

this.initBranch(
this.triggerElement,
topBranch,
this.referenceElement,
this.initialBranchPlacement,
this.initialBranchFallbackPlacements,
this.processBranchOnInitAfter,
this.processItemOnInitAfter,
);
this.initBranch({
triggerElement: this.triggerElement,
branchElement: topBranch,
referenceElement: this.referenceElement,
placement: this.initialBranchPlacement,
fallbackPlacements: this.initialBranchFallbackPlacements,
processBranchAfter: this.processBranchOnInitAfter,
processBranchItemAfter: this.processItemOnInitAfter,
});
this.triggerElement.branchElement = topBranch;

itemsWithSubitems.forEach((itemElement) => {
const branchElement = itemElement.querySelector(':scope > .ibexa-multilevel-popup-menu__branch');
const parentBranchElement = itemElement.closest('.ibexa-popup-menu');

this.initBranch(
itemElement,
branchElement,
undefined,
undefined,
undefined,
this.processBranchOnInitAfter,
this.processItemOnInitAfter,
);
this.initBranch({
triggerElement: itemElement,
branchElement: branchElement,
processBranchAfter: this.processBranchOnInitAfter,
processBranchItemAfter: this.processItemOnInitAfter,
});

itemElement.branchElement = branchElement;
branchElement.itemElement = itemElement;
branchElement.parentBranchElement = parentBranchElement;
});
}

initBranch(
initBranch({
triggerElement,
branchElement,
referenceElement = null,
placement = 'right-start',
fallbackPlacements = ['right-end', 'left-start', 'left-end'],
processBranchAfter = () => {},
processBranchItemAfter = () => {},
) {
}) {
doc.body.appendChild(branchElement);

const isTopBranch = !triggerElement.classList.contains('ibexa-popup-menu__item');
Expand Down Expand Up @@ -143,7 +140,7 @@
}

updateBranchAndParentBranchesOpenState(branchElement) {
const isTopBranch = !(branchElement?.parentBranchElement ?? null);
const isTopBranch = !branchElement?.parentBranchElement;

if (isTopBranch) {
return;
Expand Down Expand Up @@ -265,7 +262,7 @@

processAfterCreated(newBranchElement, data);

this.initBranch(triggerElement, newBranchElement, null, placement, fallbackPlacements);
this.initBranch({ triggerElement, branchElement: newBranchElement, placement, fallbackPlacements });

const parentBranchElement = triggerElement.closest('.ibexa-popup-menu');

Expand Down Expand Up @@ -355,10 +352,10 @@
}
}

isOurBranch(branch) {
isBranchBelongingToThisMenu(branch) {
const topBranch = this.triggerElement.branchElement;

return !!branch && (topBranch === branch || this.isOurBranch(branch.parentBranchElement));
return !!branch && (topBranch === branch || this.isBranchBelongingToThisMenu(branch.parentBranchElement));
}

handleClickOutside(event) {
Expand All @@ -371,7 +368,7 @@
const closestPopup = event.target.closest('.ibexa-popup-menu');
const isPopupMenuExpanded = !topBranch.classList.contains('ibexa-popup-menu--hidden');
const isClickInsideTrigger = this.triggerElement.contains(event.target);
const isClickInsideOurBranch = this.isOurBranch(closestPopup);
const isClickInsideOurBranch = this.isBranchBelongingToThisMenu(closestPopup);

if (!isPopupMenuExpanded || isClickInsideTrigger || isClickInsideOurBranch) {
return;
Expand Down
2 changes: 1 addition & 1 deletion src/bundle/Resources/public/scss/_popup-menu.scss
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@
display: none;
}

&--no-absolute {
&--initial-position {
position: initial;
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/bundle/Resources/public/scss/_split-button.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
}

&__main-btn {
border-top-right-radius: 0px;
border-bottom-right-radius: 0px;
border-top-right-radius: 0;
border-bottom-right-radius: 0;
}

&__split {
Expand All @@ -20,8 +20,8 @@

&__toggle-btn {
margin-left: calculateRem(-1px);
border-top-left-radius: 0px;
border-bottom-left-radius: 0px;
border-top-left-radius: 0;
border-bottom-left-radius: 0;

.ibexa-icon {
transition: all $ibexa-admin-transition-duration $ibexa-admin-transition;
Expand Down

0 comments on commit b9de87f

Please sign in to comment.