From 34d45f6b3b45be991210252af8226296e3cfa0cb Mon Sep 17 00:00:00 2001 From: Angel Fernando Quiroz Campos Date: Mon, 29 Nov 2021 12:38:12 -0500 Subject: [PATCH] LP: Don't load frameReady resources for external content - refs BT#19446 --- main/inc/lib/display.lib.php | 16 ++++---- main/inc/lib/javascript/jquery.frameready.js | 7 +++- main/lp/lp_view.php | 39 ++++++++++++-------- main/template/default/learnpath/view.tpl | 5 +-- main/template/rainbow/learnpath/view.tpl | 10 ++--- 5 files changed, 40 insertions(+), 37 deletions(-) diff --git a/main/inc/lib/display.lib.php b/main/inc/lib/display.lib.php index b4babacb96..c754f1054d 100755 --- a/main/inc/lib/display.lib.php +++ b/main/inc/lib/display.lib.php @@ -2887,13 +2887,11 @@ HTML; return $content; } - /** - * @param string $frameName - * - * @return string - */ - public static function getFrameReadyBlock($frameName) - { + public static function getFrameReadyBlock( + string $frameName, + string $itemType = '', + string $jsConditionalFunction = 'function () { return false; }' + ): string { $webPublicPath = api_get_path(WEB_PUBLIC_PATH); $videoFeatures = [ @@ -2989,8 +2987,8 @@ HTML; {type:"stylesheet", src: "'.$webPublicPath.'assets/mediaelement/build/mediaelementplayer.min.css"}, {type:"stylesheet", src: "'.$webPublicPath.'assets/mediaelement/plugins/vrview/vrview.css"}, '.$fileCustomCssMedia.', - '.$translateHtml.' - ]);'; + '.$translateHtml.', + ], '.$jsConditionalFunction.');'; return $frameReady; } diff --git a/main/inc/lib/javascript/jquery.frameready.js b/main/inc/lib/javascript/jquery.frameready.js index 45b5fbd58a..70c0681026 100755 --- a/main/inc/lib/javascript/jquery.frameready.js +++ b/main/inc/lib/javascript/jquery.frameready.js @@ -2,9 +2,10 @@ * @param {function} callback * @param {string} target * @param {Array} resources + * @param {function} conditional * @constructor */ -$.frameReady = function (callback, targetSelector, resources) { +$.frameReady = function (callback, targetSelector, resources, conditional) { /** * @type {window} */ @@ -46,6 +47,10 @@ $.frameReady = function (callback, targetSelector, resources) { targetWindow.onload = function () { scripsLoadedCount = 0; + if (typeof conditional === 'function' && conditional()) { + return; + } + targetDocument = targetWindow.contentDocument; scripts.forEach(function (script) { diff --git a/main/lp/lp_view.php b/main/lp/lp_view.php index 6d6729099c..1f92c4244a 100755 --- a/main/lp/lp_view.php +++ b/main/lp/lp_view.php @@ -124,7 +124,7 @@ $htmlHeadXtra[] = api_get_css_asset('qtip2/jquery.qtip.min.css'); $htmlHeadXtra[] = api_get_asset('qtip2/jquery.qtip.min.js'); $htmlHeadXtra[] = ''; $htmlHeadXtra[] = ''; } @@ -212,11 +212,11 @@ if ($debug) { $get_toc_list = $lp->get_toc(); $get_teacher_buttons = $lp->get_teacher_toc_buttons(); +$itemType = ''; -$type_quiz = false; foreach ($get_toc_list as $toc) { - if ($toc['id'] == $lp_item_id && $toc['type'] == 'quiz') { - $type_quiz = true; + if ($toc['id'] == $lp_item_id) { + $itemType = $toc['type']; } } @@ -290,7 +290,6 @@ $autostart = 'true'; // Update status, total_time from lp_item_view table when you finish the exercises in learning path. if ($debug) { - error_log('$type_quiz: '.$type_quiz); error_log('$_REQUEST[exeId]: '.intval($_REQUEST['exeId'])); error_log('$lp_id: '.$lp_id); error_log('$_GET[lp_item_id]: '.intval($_GET['lp_item_id'])); @@ -630,7 +629,15 @@ $template->assign( ) ); -$frameReady = Display::getFrameReadyBlock('#content_id, #content_id_blank'); +$frameReady = Display::getFrameReadyBlock( + '#content_id, #content_id_blank', + $itemType, + 'function () { + var arr = ["link", "sco", "xapi"]; + + return $.inArray(olms.lms_item_type, arr) !== -1; + }' +); $template->assign('frame_ready', $frameReady); // Ofaj diff --git a/main/template/default/learnpath/view.tpl b/main/template/default/learnpath/view.tpl index c83bece23b..13b243b6e1 100644 --- a/main/template/default/learnpath/view.tpl +++ b/main/template/default/learnpath/view.tpl @@ -376,10 +376,7 @@ {% endif %} {% if disable_js_in_lp_view == 0 %} $(function() { - var arr = ['link', 'sco']; - if ($.inArray(olms.lms_item_type, arr) == -1) { - {{ frame_ready }} - } + {{ frame_ready }} }); {% endif %} diff --git a/main/template/rainbow/learnpath/view.tpl b/main/template/rainbow/learnpath/view.tpl index 1d0c974b4b..640db8b412 100644 --- a/main/template/rainbow/learnpath/view.tpl +++ b/main/template/rainbow/learnpath/view.tpl @@ -330,13 +330,9 @@ })(); {% endif %} {% if disable_js_in_lp_view == 0 %} - $(function() { - var arr = ['link', 'sco']; - - if ($.inArray(olms.lms_item_type, arr) == -1) { - {{ frame_ready }} - } - }); + $(function() { + {{ frame_ready }} + }); {% endif %} $(window).on('resize', function () {