Skip to content

Commit

Permalink
Merge pull request #1409 from appsembler/vladyslav/hide-html-elements…
Browse files Browse the repository at this point in the history
…-in-iframe

Hide site elements if render in iframe
  • Loading branch information
VladyslavTy authored Aug 14, 2024
2 parents cd7be06 + 9c2f374 commit 6290527
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 6290527

Please sign in to comment.