Skip to content

Commit

Permalink
refactor: corrected xblock dropdown menu
Browse files Browse the repository at this point in the history
  • Loading branch information
PKulkoRaccoonGang committed Nov 15, 2024
1 parent 29add8c commit 6b6fb77
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions cms/static/js/views/pages/container.js
Original file line number Diff line number Diff line change
Expand Up @@ -483,21 +483,18 @@ function($, _, Backbone, gettext, BasePage,
// not present yet during the domReady event, we have to handle displaying it ourselves.
subMenu.classList.toggle('is-shown');

try {
if (this.options.isIframeEmbed) {
window.parent.postMessage(
{
type: 'toggleDropdownMenu',
message: 'Sends a message when the dropdown menu is toggled',
payload: {
subMenuHeight: subMenu.offsetHeight,
}
}, document.referrer
);
}
} catch (e) {
console.error(e);
// Calculate the viewport height and the dropdown menu height.
// Check if the dropdown would overflow beyond the iframe height based on the user's click position.
// If the dropdown overflows, adjust its position to display above the click point.
const courseUnitXBlockIframeHeight = window.innerHeight;
const courseXBlockDropdownHeight = subMenu.offsetHeight;
const clickYPosition = event.clientY;

if ((courseXBlockDropdownHeight + clickYPosition) > courseUnitXBlockIframeHeight) {
// Move the dropdown menu upward to prevent it from overflowing out of the viewport.
subMenu.style.top = `-${courseXBlockDropdownHeight}px`;
}

// if propagation is not stopped, the event will bubble up to the
// body element, which will close the dropdown.
event.stopPropagation();
Expand Down

0 comments on commit 6b6fb77

Please sign in to comment.