Skip to content

Commit

Permalink
Merge pull request #1410 from appsembler/main
Browse files Browse the repository at this point in the history
Update from `main` (production)
  • Loading branch information
VladyslavTy authored Aug 20, 2024
2 parents 00edcf9 + 3914714 commit 2aa1ec0
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lms/static/js/student_account/views/FinishAuthView.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@
courseId: $.url('?course_id'),
courseMode: $.url('?course_mode'),
emailOptIn: $.url('?email_opt_in'),
purchaseWorkflow: $.url('?purchase_workflow')
purchaseWorkflow: $.url('?purchase_workflow'),
hideElements: $.url('?hide_elements')
};
for (var key in queryParams) {
if (queryParams[key]) {
Expand All @@ -64,6 +65,7 @@
this.emailOptIn = queryParams.emailOptIn;
this.nextUrl = this.urls.defaultNextUrl;
this.purchaseWorkflow = queryParams.purchaseWorkflow;
this.hideElements = queryParams.hideElements;
if (queryParams.next) {
// Ensure that the next URL is internal for security reasons
if (! window.isExternal(queryParams.next)) {
Expand All @@ -76,6 +78,9 @@
try {
var next = _.bind(this.enrollment, this);
this.checkEmailOptIn(next);
if (this.hideElements) {
document.cookie = 'hideElements=' + this.hideElements + '; path=/';
}
} catch (err) {
this.updateTaskDescription(gettext('Error') + ': ' + err.message);
this.redirect(this.nextUrl);
Expand Down
31 changes: 31 additions & 0 deletions lms/static/lms/js/iframe-render.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// List of the classes to hide while rendered in an iframe
const classesToHide = ['.global-header', '.wrapper-course-material', '.a--footer'];

// Function to get a cookie by name
function getCookieByName(name) {
let cname = name + "=";
let decodedCookie = decodeURIComponent(document.cookie);
let cookies = decodedCookie.split(';');
for (let i = 0; i < cookies.length; i++) {
let c = cookies[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return "";
}

document.addEventListener('DOMContentLoaded', function () {
const hideElements = getCookieByName('hideElements');

if (hideElements) {
classesToHide.forEach(function (className) {
document.querySelectorAll(className).forEach(function (element) {
element.classList.add('hidden-element');
});
});
}
});
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-element {
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 @@ -123,6 +123,7 @@
}).call(this, require || RequireJS.require);
</script>
<script type="text/javascript" src="${static.url("lms/js/require-config.js")}"></script>
<script type="text/javascript" src="${static.url("lms/js/iframe-render.js")}"></script>
<%block name="js_overrides">
${render_require_js_path_overrides(settings.REQUIRE_JS_PATH_OVERRIDES) | n, decode.utf8}
</%block>
Expand Down

0 comments on commit 2aa1ec0

Please sign in to comment.