Skip to content
Merged
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
47 changes: 47 additions & 0 deletions lms/templates/courseware/courseware-chromeless.html
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,50 @@
% endif
</nav>
% endif

<script type="text/javascript">

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not consolidate this with the earlier iframe check? Appending the <base> tag can happen here, right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can, I just thought repeating myself to keep the functionality isolated would be good. Also it's worth noting that the base tag script needs to be in the head. Not a strong reason though. Let me know if you prefer combining them.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I put it at the bottom originally so that most of the page would be loaded by the time it ran. It may not be important, but keeping it there may cut down on events as things resize and fill in during load.

(function() {
// If this view is rendered in an iframe within the learning microfrontend app
// it will report the height of its contents to the parent window when the
// document loads, window resizes, or DOM mutates.
if (window !== window.parent) {
var learningAppReferrer = "${settings.LEARNING_MICROFRONTEND_URL | n, js_escaped_string}";
if (document.referrer === learningAppReferrer) {

var lastHeight = window.offsetHeight;
var lastWidth = window.offsetWidth;
var contentElement = document.getElementById('content');

function dispatchResizeMessage() {
var newHeight = contentElement.offsetHeight;
var newWidth = contentElement.offsetWidth;

if (newWidth === lastWidth && newHeight === lastHeight) {
return;
}

window.parent.postMessage({
type: 'plugin.resize',
payload: {
width: newWidth,
height: newHeight,
}
}, document.referrer
);

lastHeight = newHeight;
lastWidth = newWidth;
}

// Create an observer instance linked to the callback function
const observer = new MutationObserver(dispatchResizeMessage);

// Start observing the target node for configured mutations
observer.observe(document.body, { attributes: true, childList: true, subtree: true });

window.addEventListener('load', dispatchResizeMessage);
window.addEventListener('resize', dispatchResizeMessage);
}
}
}());
</script>