Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: [FC-0070] Listen to xBlock interaction events #35694

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions cms/static/js/views/container.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,17 @@ function($, _, XBlockView, ModuleUtils, gettext, StringUtils, NotificationView)
newParent = undefined;
},
update: function(event, ui) {
try {
window.parent.postMessage(
{
type: 'refreshPositions',
message: 'Refresh positions of all xblocks',
payload: {}
}, document.referrer
);
} catch (e) {
console.error(e);
}
// When dragging from one ol to another, this method
// will be called twice (once for each list). ui.sender will
// be null if the change is related to the list the element
Expand Down
118 changes: 105 additions & 13 deletions cms/static/js/views/pages/container.js
Original file line number Diff line number Diff line change
Expand Up @@ -391,12 +391,16 @@ function($, _, Backbone, gettext, BasePage,

editXBlock: function(event, options) {
event.preventDefault();
const isAccessButton = event.currentTarget.className === 'access-button';
const primaryHeader = $(event.target).closest('.xblock-header-primary, .nav-actions');
const usageId = encodeURI(primaryHeader.attr('data-usage-id'));
try {
if (this.options.isIframeEmbed) {
window.parent.postMessage(
if (this.options.isIframeEmbed && isAccessButton) {
return window.parent.postMessage(
{
type: 'editXBlock',
payload: {}
type: 'manageXBlockAccess',
message: 'Open the manage access modal',
payload: { usageId }
}, document.referrer
);
}
Expand All @@ -417,8 +421,26 @@ function($, _, Backbone, gettext, BasePage,
|| (useNewProblemEditor === 'True' && blockType === 'problem')
) {
var destinationUrl = primaryHeader.attr('authoring_MFE_base_url')
+ '/' + blockType
+ '/' + encodeURI(primaryHeader.attr('data-usage-id'));
+ '/' + blockType
+ '/' + encodeURI(primaryHeader.attr('data-usage-id'));

try {
if (this.options.isIframeEmbed) {
return window.parent.postMessage(
{
type: 'newXBlockEditor',
message: 'Open the new XBlock editor',
payload: {
blockType,
usageId: encodeURI(primaryHeader.attr('data-usage-id')),
}
}, document.referrer
);
}
} catch (e) {
console.error(e);
}

var upstreamRef = primaryHeader.attr('data-upstream-ref');
if(upstreamRef) {
destinationUrl += '?upstreamLibRef=' + upstreamRef;
Expand Down Expand Up @@ -548,6 +570,65 @@ function($, _, Backbone, gettext, BasePage,
// Code in 'base.js' normally handles toggling these dropdowns but since this one is
// not present yet during the domReady event, we have to handle displaying it ourselves.
subMenu.classList.toggle('is-shown');

if (!subMenu.classList.contains('is-shown') && this.options.isIframeEmbed) {
try {
window.parent.postMessage(
{
type: 'toggleCourseXBlockDropdown',
message: 'Adjust the height of the dropdown menu',
payload: { courseXBlockDropdownHeight: 0 }
}, document.referrer
);
} catch (error) {
console.error(error);
}
bradenmacdonald marked this conversation as resolved.
Show resolved Hide resolved
}

// 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 (courseUnitXBlockIframeHeight < courseXBlockDropdownHeight) {
// If the dropdown menu is taller than the iframe, adjust the height of the dropdown menu.
try {
window.parent.postMessage(
{
type: 'toggleCourseXBlockDropdown',
message: 'Adjust the height of the dropdown menu',
payload: { courseXBlockDropdownHeight },
}, document.referrer
);
} catch (error) {
console.error(error);
}
} else if ((courseXBlockDropdownHeight + clickYPosition) > courseUnitXBlockIframeHeight) {
if (courseXBlockDropdownHeight > courseUnitXBlockIframeHeight / 2) {
// If the dropdown menu is taller than half the iframe, send a message to adjust its height.
try {
window.parent.postMessage(
{
type: 'toggleCourseXBlockDropdown',
message: 'Adjust the height of the dropdown menu',
payload: {
courseXBlockDropdownHeight: courseXBlockDropdownHeight / 2,
},
}, document.referrer
);
} catch (error) {
console.error(error);
}
} else {
// Move the dropdown menu upward to prevent it from overflowing out of the viewport.
if (this.options.isIframeEmbed) {
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 @@ -588,12 +669,15 @@ function($, _, Backbone, gettext, BasePage,

copyXBlock: function(event) {
event.preventDefault();
const primaryHeader = $(event.target).closest('.xblock-header-primary, .nav-actions');
const usageId = encodeURI(primaryHeader.attr('data-usage-id'));
try {
if (this.options.isIframeEmbed) {
window.parent.postMessage(
return window.parent.postMessage(
{
type: 'copyXBlock',
payload: {}
message: 'Copy the XBlock',
payload: { usageId }
}, document.referrer
);
}
Expand Down Expand Up @@ -645,12 +729,16 @@ function($, _, Backbone, gettext, BasePage,

duplicateXBlock: function(event) {
event.preventDefault();
const primaryHeader = $(event.target).closest('.xblock-header-primary, .nav-actions');
const blockType = primaryHeader.attr('data-block-type');
const usageId = encodeURI(primaryHeader.attr('data-usage-id'));
try {
if (this.options.isIframeEmbed) {
window.parent.postMessage(
return window.parent.postMessage(
{
type: 'duplicateXBlock',
payload: {}
message: 'Duplicate the XBlock',
payload: { blockType, usageId }
}, document.referrer
);
}
Expand Down Expand Up @@ -702,12 +790,15 @@ function($, _, Backbone, gettext, BasePage,

deleteXBlock: function(event) {
event.preventDefault();
const primaryHeader = $(event.target).closest('.xblock-header-primary, .nav-actions');
const usageId = encodeURI(primaryHeader.attr('data-usage-id'));
try {
if (this.options.isIframeEmbed) {
window.parent.postMessage(
return window.parent.postMessage(
{
type: 'deleteXBlock',
payload: {}
message: 'Delete the XBlock',
payload: { usageId }
}, document.referrer
);
}
Expand Down Expand Up @@ -868,12 +959,13 @@ function($, _, Backbone, gettext, BasePage,
|| (useNewProblemEditor === 'True' && blockType.includes('problem')))
){
var destinationUrl;
if (useVideoGalleryFlow === "True" && blockType.includes("video")) {
if (useVideoGalleryFlow === 'True' && blockType.includes('video')) {
destinationUrl = this.$('.xblock-header-primary').attr("authoring_MFE_base_url") + '/course-videos/' + encodeURI(data.locator);
}
else {
destinationUrl = this.$('.xblock-header-primary').attr("authoring_MFE_base_url") + '/' + blockType[1] + '/' + encodeURI(data.locator);
}
bradenmacdonald marked this conversation as resolved.
Show resolved Hide resolved

window.location.href = destinationUrl;
return;
}
Expand Down
6 changes: 6 additions & 0 deletions cms/static/sass/course-unit-mfe-iframe-bundle.scss
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
background-color: $primary;
color: $white;
border-color: $transparent;
color: $white;
}

&:focus {
Expand Down Expand Up @@ -327,6 +328,7 @@

.wrapper-content.wrapper {
padding: $baseline / 4;
background-color: #f8f7f6;
}

.btn-default.action-edit.title-edit-button {
Expand Down Expand Up @@ -656,3 +658,7 @@ select {
.wrapper-comp-setting.metadata-list-enum .action.setting-clear.active {
margin-top: 0;
}

.wrapper-xblock .xblock-header-primary .header-actions .wrapper-nav-sub {
z-index: $zindex-dropdown;
}
2 changes: 2 additions & 0 deletions cms/static/sass/partials/cms/theme/_variables-v1.scss
Original file line number Diff line number Diff line change
Expand Up @@ -313,3 +313,5 @@ $light-background-color: #e1dddb !default;
$border-color: #707070 !default;
$base-font-size: 18px !default;
$dark: #212529;

$zindex-dropdown: 100;
Loading