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

Hide site elements if render in iframe #1409

Merged
merged 2 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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'];
VladyslavTy marked this conversation as resolved.
Show resolved Hide resolved

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
Loading