From 6c64181bf4061cecd1a71b02aa946116735b806f Mon Sep 17 00:00:00 2001 From: Jannat Patel Date: Tue, 22 Feb 2022 11:15:02 +0530 Subject: [PATCH] fix: overlay position when related courses --- school/lms/widgets/CourseOutline.html | 2 +- school/public/css/style.css | 33 +++++++++++++-------------- school/www/batch/learn.py | 1 - school/www/courses/course.html | 32 ++++++++++++++------------ school/www/courses/course.js | 30 ++++++++++++++++++++++++ 5 files changed, 64 insertions(+), 34 deletions(-) diff --git a/school/lms/widgets/CourseOutline.html b/school/lms/widgets/CourseOutline.html index 970de9ed..e4144d62 100644 --- a/school/lms/widgets/CourseOutline.html +++ b/school/lms/widgets/CourseOutline.html @@ -4,7 +4,7 @@ {{ _("Course Content") }} {% for chapter in get_chapters(course.name) %} -
+
diff --git a/school/www/courses/course.js b/school/www/courses/course.js index e5f8c8ab..80068c4a 100644 --- a/school/www/courses/course.js +++ b/school/www/courses/course.js @@ -41,6 +41,12 @@ frappe.ready(() => { create_certificate(e); }); + $(document).scroll(function() { + let timer; + clearTimeout(timer); + timer = setTimeout(() => { handle_overlay_display.apply(this, arguments); }, 500); + }); + }) var check_mentor_request = () => { @@ -226,3 +232,27 @@ const create_certificate = (e) => { } }) }; + + +const element_not_in_viewport = (el) => { + const rect = el.getBoundingClientRect(); + return rect.bottom < 0 || rect.right < 0 || rect.left > window.innerWidth || rect.top > window.innerHeight; +} + +const handle_overlay_display = () => { + const element = $(".related-courses").length && $(".related-courses")[0]; + if (element && element_not_in_viewport(element)) { + $(".course-overlay-card").css({ + "position": "fixed", + "top": "30%", + "bottom": "inherit" + }); + } + else if (element && !element_not_in_viewport(element)) { + $(".course-overlay-card").css({ + "position": "absolute", + "top": "inherit", + "bottom": "5%" + }); + } +}