From 878af3c07620c9b86c246ae15cd3116dcfb48112 Mon Sep 17 00:00:00 2001 From: Vladyslav Tymofeiev <“vladyslavty@softwareplanetgroup.com”> Date: Tue, 13 Aug 2024 18:43:05 +0300 Subject: [PATCH 1/4] Add handler of iframe rendering --- common/static/js/src/iframe-render.js | 13 +++++++++++++ lms/static/sass/shared-v2/_base.scss | 5 +++++ lms/templates/main.html | 1 + 3 files changed, 19 insertions(+) create mode 100644 common/static/js/src/iframe-render.js diff --git a/common/static/js/src/iframe-render.js b/common/static/js/src/iframe-render.js new file mode 100644 index 000000000000..a66debfe8b9a --- /dev/null +++ b/common/static/js/src/iframe-render.js @@ -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'); + }); + }); + } +}); diff --git a/lms/static/sass/shared-v2/_base.scss b/lms/static/sass/shared-v2/_base.scss index 584cf5799faf..a90a065b38df 100644 --- a/lms/static/sass/shared-v2/_base.scss +++ b/lms/static/sass/shared-v2/_base.scss @@ -24,3 +24,8 @@ @extend .sr-only; } +// Hide element when rendered in iFrame +.hidden-in-iframe { + display: none !important; +} + diff --git a/lms/templates/main.html b/lms/templates/main.html index 48edc767a132..fd826785eefc 100644 --- a/lms/templates/main.html +++ b/lms/templates/main.html @@ -211,6 +211,7 @@ <%static:optional_include_mako file="body-extra.html" is_theming_enabled="True" /> + From 9c2f37476e1713dc1709196dcd1384579ba47cef Mon Sep 17 00:00:00 2001 From: Vladyslav Tymofeiev <“vladyslavty@softwareplanetgroup.com”> Date: Wed, 14 Aug 2024 10:13:34 +0300 Subject: [PATCH 2/4] Fix typo in footer classname --- common/static/js/src/iframe-render.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/static/js/src/iframe-render.js b/common/static/js/src/iframe-render.js index a66debfe8b9a..8264b1ae0783 100644 --- a/common/static/js/src/iframe-render.js +++ b/common/static/js/src/iframe-render.js @@ -1,5 +1,5 @@ // List of the classes to hide while rendered in an iframe -const classesToHide = ['.global-header', '.wrapper-course-material', 'a--footer']; +const classesToHide = ['.global-header', '.wrapper-course-material', '.a--footer']; document.addEventListener('DOMContentLoaded', function () { // Check if rendered in iframe From a7c6b5fa09d8fd1d917a51b3ae689c62817cf6ff Mon Sep 17 00:00:00 2001 From: Vladyslav Tymofeiev <“vladyslavty@softwareplanetgroup.com”> Date: Fri, 16 Aug 2024 17:21:11 +0300 Subject: [PATCH 3/4] Refactor event to hide elements --- common/static/js/src/iframe-render.js | 13 ----------- lms/static/lms/js/iframe-render.js | 31 +++++++++++++++++++++++++++ lms/static/sass/shared-v2/_base.scss | 2 +- lms/templates/main.html | 2 +- 4 files changed, 33 insertions(+), 15 deletions(-) delete mode 100644 common/static/js/src/iframe-render.js create mode 100644 lms/static/lms/js/iframe-render.js diff --git a/common/static/js/src/iframe-render.js b/common/static/js/src/iframe-render.js deleted file mode 100644 index 8264b1ae0783..000000000000 --- a/common/static/js/src/iframe-render.js +++ /dev/null @@ -1,13 +0,0 @@ -// 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'); - }); - }); - } -}); diff --git a/lms/static/lms/js/iframe-render.js b/lms/static/lms/js/iframe-render.js new file mode 100644 index 000000000000..f5b5bce6b20a --- /dev/null +++ b/lms/static/lms/js/iframe-render.js @@ -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'); + }); + }); + } +}); diff --git a/lms/static/sass/shared-v2/_base.scss b/lms/static/sass/shared-v2/_base.scss index a90a065b38df..450a1aa51b75 100644 --- a/lms/static/sass/shared-v2/_base.scss +++ b/lms/static/sass/shared-v2/_base.scss @@ -25,7 +25,7 @@ } // Hide element when rendered in iFrame -.hidden-in-iframe { +.hidden-element { display: none !important; } diff --git a/lms/templates/main.html b/lms/templates/main.html index fd826785eefc..af1d51fe9cbc 100644 --- a/lms/templates/main.html +++ b/lms/templates/main.html @@ -123,6 +123,7 @@ }).call(this, require || RequireJS.require); + <%block name="js_overrides"> ${render_require_js_path_overrides(settings.REQUIRE_JS_PATH_OVERRIDES) | n, decode.utf8} @@ -211,7 +212,6 @@ <%static:optional_include_mako file="body-extra.html" is_theming_enabled="True" /> - From 71f097879ea41ee45510de86cd3b2d236bb28029 Mon Sep 17 00:00:00 2001 From: Vladyslav Tymofeiev <“vladyslavty@softwareplanetgroup.com”> Date: Fri, 16 Aug 2024 18:03:09 +0300 Subject: [PATCH 4/4] Add hide_elements parameter that determine if we need to hide the html elements after finish auth process --- lms/static/js/student_account/views/FinishAuthView.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lms/static/js/student_account/views/FinishAuthView.js b/lms/static/js/student_account/views/FinishAuthView.js index 870c56b61591..ac09152c8289 100644 --- a/lms/static/js/student_account/views/FinishAuthView.js +++ b/lms/static/js/student_account/views/FinishAuthView.js @@ -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]) { @@ -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)) { @@ -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);