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 cae1f67
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 29 deletions.
14 changes: 0 additions & 14 deletions cms/static/js/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,20 +76,6 @@ function(
$('.nav-dd .nav-item .wrapper-nav-sub').removeClass('is-shown');
$('.nav-dd .nav-item .title').removeClass('is-selected');
$('.custom-dropdown .dropdown-options').hide();

try {
window.parent.postMessage(
{
type: 'toggleDropdownMenu',
message: 'Sends a message when the dropdown menu is closed',
payload: {
subMenuHeight: 0,
}
}, document.referrer
);
} catch (e) {
console.error(e);
}
});

$('.nav-dd .nav-item, .filterable-column .nav-item').click(function(e) {
Expand Down
1 change: 1 addition & 0 deletions cms/static/js/views/container.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ function($, _, XBlockView, ModuleUtils, gettext, StringUtils, NotificationView)
window.parent.postMessage(
{
type: 'refreshPositions',
message: 'Refresh positions of all xblocks',
payload: {}
}, document.referrer
);
Expand Down
33 changes: 18 additions & 15 deletions cms/static/js/views/pages/container.js
Original file line number Diff line number Diff line change
Expand Up @@ -387,11 +387,13 @@ function($, _, Backbone, gettext, BasePage,

editXBlock: function(event, options) {
event.preventDefault();
var isAccessButton = event.currentTarget.className === 'access-button';
try {
if (this.options.isIframeEmbed && event.currentTarget.className === 'access-button') {
if (this.options.isIframeEmbed && isAccessButton) {
return window.parent.postMessage(
{
type: 'manageXBlockAccess',
message: 'Open the access editor for the XBlock',
payload: {
id: this.findXBlockElement(event.target).data('locator'),
targetElementClassName: event.currentTarget.className,
Expand Down Expand Up @@ -423,6 +425,7 @@ function($, _, Backbone, gettext, BasePage,
return window.parent.postMessage(
{
type: 'newXBlockEditor',
message: 'Open the new XBlock editor',
payload: {
url: pathToNewXBlockEditor,
}
Expand Down Expand Up @@ -483,21 +486,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 Expand Up @@ -543,6 +543,7 @@ function($, _, Backbone, gettext, BasePage,
return window.parent.postMessage(
{
type: 'copyXBlock',
message: 'Copy the XBlock',
payload: {
id: this.findXBlockElement(event.target).data('locator')
}
Expand Down Expand Up @@ -602,6 +603,7 @@ function($, _, Backbone, gettext, BasePage,
return window.parent.postMessage(
{
type: 'duplicateXBlock',
message: 'Duplicate the XBlock',
payload: {
id: this.findXBlockElement(event.target).data('locator')
}
Expand Down Expand Up @@ -647,6 +649,7 @@ function($, _, Backbone, gettext, BasePage,
return window.parent.postMessage(
{
type: 'deleteXBlock',
message: 'Delete the XBlock',
payload: {
id: this.findXBlockElement(event.target).data('locator')
}
Expand Down

0 comments on commit cae1f67

Please sign in to comment.