Skip to content

Commit

Permalink
Popover ordering.
Browse files Browse the repository at this point in the history
Move a popover to the front when it first opens, if it is clicked in, or
if focus moves into it.  Other popovers are behind the "active" popover
in the order they appear in the DOM.
  • Loading branch information
drgrice1 committed Jan 12, 2024
1 parent 364abbb commit cefcc66
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
14 changes: 14 additions & 0 deletions htdocs/js/Feedback/feedback.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
(() => {
const feedbackPopovers = [];

const initializeFeedback = (feedbackBtn) => {
if (feedbackBtn.dataset.popoverInitialized) return;
feedbackBtn.dataset.popoverInitialized = 'true';
Expand All @@ -7,6 +9,7 @@
sanitize: false,
container: feedbackBtn.parentElement
});
feedbackPopovers.push(feedbackPopover);

// Render MathJax previews.
if (window.MathJax) {
Expand All @@ -25,6 +28,17 @@
setTimeout(() => feedbackPopover.update());
});

const moveToFront = () => {
if (feedbackPopover.tip) feedbackPopover.tip.style.zIndex = 18;
for (const popover of feedbackPopovers) {
if (popover === feedbackPopover) continue;
if (popover.tip) popover.tip.style.setProperty('z-index', null);
}
};
feedbackPopover.tip?.addEventListener('click', moveToFront);
feedbackPopover.tip?.addEventListener('focusin', moveToFront);
moveToFront();

// Make a click on the popover header close the popover.
feedbackPopover.tip
?.querySelector('.popover-header')
Expand Down
2 changes: 1 addition & 1 deletion htdocs/js/Problem/problem.scss
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@
--bs-popover-body-padding-x: 0;
--bs-popover-body-padding-y: 0;
--bs-popover-max-width: 600px;
--bs-popover-zindex: 18;
--bs-popover-zindex: 17;
position: absolute;
min-width: 200px;

Expand Down

0 comments on commit cefcc66

Please sign in to comment.