From 9e1f2da02ed0e78635248cc3eb54d1f7b183a89e Mon Sep 17 00:00:00 2001 From: Sebastian Serth Date: Thu, 6 Oct 2022 00:24:23 +0200 Subject: [PATCH] Fallback to default height if editor offset cannot be determined Fixes CODEOCEAN-B6, Fixes CODEOCEAN-E1, Fixes CODEOCEAN-BZ --- app/assets/javascripts/editor/editor.js.erb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/editor/editor.js.erb b/app/assets/javascripts/editor/editor.js.erb index e0809247..a0d0203e 100644 --- a/app/assets/javascripts/editor/editor.js.erb +++ b/app/assets/javascripts/editor/editor.js.erb @@ -231,9 +231,14 @@ var CodeOceanEditor = { }, calculateEditorHeight: function (element, considerStatusbar) { - let bottom = considerStatusbar ? ($('#statusbar').height() || 0) : 0; + const jqueryElement = $(element); + if (jqueryElement.length === 0) { + return 0; + } + + const bottom = considerStatusbar ? ($('#statusbar').height() || 0) : 0; // calculate needed size: window height - position of top of ACE editor - height of autosave label below editor - 5 for bar margins - return window.innerHeight - $(element).offset().top - bottom - 5; + return window.innerHeight - jqueryElement.offset().top - bottom - 5; }, resizeParentOfAceEditor: function (element) {