From 65d67cdeec924949c7fffce15dda29b8079ea11b Mon Sep 17 00:00:00 2001 From: Sebastian Serth Date: Tue, 28 Feb 2023 01:13:10 +0100 Subject: [PATCH] Check for intervention modal visibility before displaying it --- app/assets/javascripts/editor/editor.js.erb | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/editor/editor.js.erb b/app/assets/javascripts/editor/editor.js.erb index 49d8ddf8..88b6969e 100644 --- a/app/assets/javascripts/editor/editor.js.erb +++ b/app/assets/javascripts/editor/editor.js.erb @@ -878,6 +878,11 @@ var CodeOceanEditor = { // timeUntilIntervention passed if (editor.data('tips-interventions')) { const modal = $('#tips-intervention-modal'); + if (!modal.isPresent()) { + // The modal is not present (e.g., because the site was navigated), so we don't continue here. + return; + } + modal.find('.modal-footer').html(I18n.t("exercises.implement.intervention.explanation", {duration: Math.round(percentile75 / 60)})); new bootstrap.Modal(modal).show(); $.ajax({ @@ -890,6 +895,11 @@ var CodeOceanEditor = { }); } else if (editor.data('break-interventions')) { const modal = $('#break-intervention-modal'); + if (!modal.isPresent()) { + // The modal is not present (e.g., because the site was navigated), so we don't continue here. + return; + } + modal.find('.modal-footer').html(I18n.t("exercises.implement.intervention.explanation", {duration: Math.round(percentile75 / 60)})); new bootstrap.Modal(modal).show(); $.ajax({ @@ -905,7 +915,12 @@ var CodeOceanEditor = { // only show intervention if user did not requested for a comment already if (!button.prop('disabled')) { $('#rfc_intervention_text').show(); - modal = $('#comment-modal'); + const modal = $('#comment-modal'); + if (!modal.isPresent()) { + // The modal is not present (e.g., because the site was navigated), so we don't continue here. + return; + } + modal.find('.modal-footer').html(I18n.t("exercises.implement.intervention.explanation", {duration: Math.round(percentile75 / 60)})); modal.on('hidden.bs.modal', function () { modal.find('.modal-footer').text('');