From 03fbc2bb54cb11816f5286c465f3991527ce15a7 Mon Sep 17 00:00:00 2001 From: Tom Reijnders Date: Thu, 22 Sep 2022 21:34:28 +0200 Subject: [PATCH] Fixed #1163 - Standalone page is not working when launched through LTI --- .../Nottingham/common_html5/js/xenith.js | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/modules/xerte/parent_templates/Nottingham/common_html5/js/xenith.js b/modules/xerte/parent_templates/Nottingham/common_html5/js/xenith.js index e14b80568..e32abff03 100644 --- a/modules/xerte/parent_templates/Nottingham/common_html5/js/xenith.js +++ b/modules/xerte/parent_templates/Nottingham/common_html5/js/xenith.js @@ -742,9 +742,13 @@ window.onhashchange = function() { } // force lightbox to close - if (parent.window.$.featherlight.current()) { - parent.window.$.featherlight.current().close(); + // catch error - in case we're in an iframe, i.e. bootstrap or LMS LTI link + try { + if (parent.window.$.featherlight.current()) { + parent.window.$.featherlight.current().close(); + } } + catch(e) {} } // Get the page info from the URL (called on project load & when page changed via browser fwd/back btns) @@ -1943,11 +1947,15 @@ function x_changePage(x_gotoPage, addHistory) { } // if this page is already shown in a lightbox then don't try to open another lightbox - load in the existing one - if (standAlonePage && x_pages[x_gotoPage].getAttribute('linkTarget') == 'lightbox' && - parent.window.$ && parent.window.$.featherlight && parent.window.$.featherlight.current()) { - standAlonePage = false; - addHistory = false; + // catch error - when in iframe, i.e. in bootstrap or LMS LTI + try { + if (standAlonePage && x_pages[x_gotoPage].getAttribute('linkTarget') == 'lightbox' && + parent.window.$ && parent.window.$.featherlight && parent.window.$.featherlight.current()) { + standAlonePage = false; + addHistory = false; + } } + catch(e) {} if (x_params.forcePage1 == 'true') { addHistory = false;