Skip to content

Commit

Permalink
Update the position of the search bar and drop-down menus on window r…
Browse files Browse the repository at this point in the history
  • Loading branch information
dtdesign committed Sep 13, 2024
1 parent 9426e76 commit cdba464
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 0 deletions.
14 changes: 14 additions & 0 deletions ts/WoltLabSuite/Core/Ui/Dropdown/Simple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,19 @@ function onScroll() {
});
}

/**
* Recalculates drop-down positions on page resize.
*/
function onWindowResize() {
_dropdowns.forEach((dropdown, containerId) => {
if (!dropdown.classList.contains("dropdownOpen")) {
return;
}

UiDropdownSimple.setAlignment(dropdown, _menus.get(containerId)!);
});
}

/**
* Notifies callbacks on status change.
*/
Expand Down Expand Up @@ -379,6 +392,7 @@ const UiDropdownSimple = {
DomChangeListener.add("WoltLabSuite/Core/Ui/Dropdown/Simple", () => UiDropdownSimple.initAll());

document.addEventListener("scroll", onScroll);
window.addEventListener("resize", () => onWindowResize(), { passive: true });

// expose on window object for backward compatibility
window.bc_wcfSimpleDropdown = this;
Expand Down
14 changes: 14 additions & 0 deletions ts/WoltLabSuite/Core/Ui/Search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,20 @@ function initSearchBar(): void {

_pageHeaderSearchMobile?.setAttribute("aria-expanded", "false");
});

window.addEventListener(
"resize",
() => {
if (_isMobile || !_pageHeader.classList.contains("searchBarOpen")) {
return;
}

UiAlignment.set(_pageHeaderSearch, _topMenu, {
horizontal: "right",
});
},
{ passive: true },
);
}

function initMobileSearch(): void {
Expand Down
12 changes: 12 additions & 0 deletions wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Dropdown/Simple.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Search.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit cdba464

Please sign in to comment.