Skip to content

Commit

Permalink
Add handler of iframe rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
Vladyslav Tymofeiev committed Aug 13, 2024
1 parent cd7be06 commit 878af3c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
13 changes: 13 additions & 0 deletions common/static/js/src/iframe-render.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// List of the classes to hide while rendered in an iframe
const classesToHide = ['.global-header', '.wrapper-course-material', 'a--footer'];

document.addEventListener('DOMContentLoaded', function () {
// Check if rendered in iframe
if (window.self !== window.top) {
classesToHide.forEach(function (className) {
document.querySelectorAll(className).forEach(function (element) {
element.classList.add('hidden-in-iframe');
});
});
}
});
5 changes: 5 additions & 0 deletions lms/static/sass/shared-v2/_base.scss
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,8 @@
@extend .sr-only;
}

// Hide element when rendered in iFrame
.hidden-in-iframe {
display: none !important;
}

1 change: 1 addition & 0 deletions lms/templates/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@
<script type="text/javascript" src="${static.url('js/header/header.js')}"></script>
<%static:optional_include_mako file="body-extra.html" is_theming_enabled="True" />
<script type="text/javascript" src="${static.url('js/src/jquery_extend_patch.js')}"></script>
<script type="text/javascript" src="${static.url('js/src/iframe-render.js')}"></script>
</body>
</html>

Expand Down

0 comments on commit 878af3c

Please sign in to comment.