Skip to content
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
42 changes: 33 additions & 9 deletions amd/build/editor_modal.min.js

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

42 changes: 33 additions & 9 deletions amd/src/editor_modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,20 @@ let session = null;
let requestCounter = 0;
let openAttemptCount = 0;
let openResponseTimer = null;
let hostWindow = null;
let hostDocument = null;

const getHostWindow = () => {
let candidate = window;
try {
while (candidate.parent && candidate.parent !== candidate && candidate.parent.document) {
candidate = candidate.parent;
}
} catch {
// Cross-origin parent — stay where we are.
}
return candidate;
};

const MAX_OPEN_ATTEMPTS = 3;
const OPEN_RESPONSE_TIMEOUT_MS = 3000;
Expand Down Expand Up @@ -105,7 +119,8 @@ const setSaveLabel = async(key, fallback) => {
};

const createLoadingModal = async() => {
const modal = document.createElement('div');
const targetDocument = hostDocument || document;
const modal = targetDocument.createElement('div');
modal.className = 'exeweb-loading-modal';
modal.id = 'exeweb-loading-modal';

Expand All @@ -126,7 +141,7 @@ const createLoadingModal = async() => {
</div>
`;

document.body.appendChild(modal);
targetDocument.body.appendChild(modal);
return modal;
};

Expand Down Expand Up @@ -431,6 +446,8 @@ export const close = async(skipConfirm) => {
}

const wasShowingLoader = isSaving || (skipConfirm === true);
const activeWindow = hostWindow || window;
const activeDocument = hostDocument || document;

overlay.remove();
overlay = null;
Expand All @@ -445,9 +462,11 @@ export const close = async(skipConfirm) => {
openAttemptCount = 0;
clearOpenResponseTimer();

document.body.style.overflow = '';
window.removeEventListener('message', handleMessage);
document.removeEventListener('keydown', handleKeydown);
activeDocument.body.style.overflow = '';
activeWindow.removeEventListener('message', handleMessage);
activeDocument.removeEventListener('keydown', handleKeydown);
hostWindow = null;
hostDocument = null;

if (wasShowingLoader) {
setTimeout(() => {
Expand Down Expand Up @@ -527,11 +546,16 @@ export const open = async(cmid, editorUrl, activityName, packageUrl, saveUrl, se
});
overlay.appendChild(iframe);

document.body.appendChild(overlay);
document.body.style.overflow = 'hidden';
// Attach the overlay to the topmost same-origin window so the modal covers
// the full viewport even when triggered from inside a small frame (e.g. the
// FRAME display mode top frame, or the embedded iframe).
hostWindow = getHostWindow();
hostDocument = hostWindow.document;
hostDocument.body.appendChild(overlay);
hostDocument.body.style.overflow = 'hidden';

window.addEventListener('message', handleMessage);
document.addEventListener('keydown', handleKeydown);
hostWindow.addEventListener('message', handleMessage);
hostDocument.addEventListener('keydown', handleKeydown);
};

export const init = () => {
Expand Down
5 changes: 5 additions & 0 deletions locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ function exeweb_display_frame($exeweb, $cm, $course, $file) {
$PAGE->set_pagelayout('frametop');
$PAGE->activityheader->set_description(exeweb_get_intro($exeweb, $cm, true));
exeweb_print_header($exeweb, $cm, $course);
// Show action bar with Edit button in the top frame.
echo $PAGE->get_renderer('mod_exeweb')->generate_action_bar($cm);
if (!exeweb_is_teacher_mode_visible($exeweb)) {
exeweb_require_teacher_mode_hider_for_content_frame();
}
Expand Down Expand Up @@ -218,6 +220,9 @@ function exeweb_print_workaround($exeweb, $cm, $course, $file) {

exeweb_print_header($exeweb, $cm, $course);

// Show action bar with Edit button when user has edit capability.
echo $PAGE->get_renderer('mod_exeweb')->generate_action_bar($cm);

echo '<div class="exewebworkaround">';
switch ($exeweb->display) {
case RESOURCELIB_DISPLAY_POPUP:
Expand Down
Loading