LP: Don't load frameReady resources for external content - refs BT#19446

pull/4128/head
Angel Fernando Quiroz Campos 4 years ago
parent 0bad2d866b
commit 34d45f6b3b
  1. 16
      main/inc/lib/display.lib.php
  2. 7
      main/inc/lib/javascript/jquery.frameready.js
  3. 39
      main/lp/lp_view.php
  4. 5
      main/template/default/learnpath/view.tpl
  5. 10
      main/template/rainbow/learnpath/view.tpl

@ -2887,13 +2887,11 @@ HTML;
return $content; return $content;
} }
/** public static function getFrameReadyBlock(
* @param string $frameName string $frameName,
* string $itemType = '',
* @return string string $jsConditionalFunction = 'function () { return false; }'
*/ ): string {
public static function getFrameReadyBlock($frameName)
{
$webPublicPath = api_get_path(WEB_PUBLIC_PATH); $webPublicPath = api_get_path(WEB_PUBLIC_PATH);
$videoFeatures = [ $videoFeatures = [
@ -2989,8 +2987,8 @@ HTML;
{type:"stylesheet", src: "'.$webPublicPath.'assets/mediaelement/build/mediaelementplayer.min.css"}, {type:"stylesheet", src: "'.$webPublicPath.'assets/mediaelement/build/mediaelementplayer.min.css"},
{type:"stylesheet", src: "'.$webPublicPath.'assets/mediaelement/plugins/vrview/vrview.css"}, {type:"stylesheet", src: "'.$webPublicPath.'assets/mediaelement/plugins/vrview/vrview.css"},
'.$fileCustomCssMedia.', '.$fileCustomCssMedia.',
'.$translateHtml.' '.$translateHtml.',
]);'; ], '.$jsConditionalFunction.');';
return $frameReady; return $frameReady;
} }

@ -2,9 +2,10 @@
* @param {function} callback * @param {function} callback
* @param {string} target * @param {string} target
* @param {Array} resources * @param {Array} resources
* @param {function} conditional
* @constructor * @constructor
*/ */
$.frameReady = function (callback, targetSelector, resources) { $.frameReady = function (callback, targetSelector, resources, conditional) {
/** /**
* @type {window} * @type {window}
*/ */
@ -46,6 +47,10 @@ $.frameReady = function (callback, targetSelector, resources) {
targetWindow.onload = function () { targetWindow.onload = function () {
scripsLoadedCount = 0; scripsLoadedCount = 0;
if (typeof conditional === 'function' && conditional()) {
return;
}
targetDocument = targetWindow.contentDocument; targetDocument = targetWindow.contentDocument;
scripts.forEach(function (script) { scripts.forEach(function (script) {

@ -124,7 +124,7 @@ $htmlHeadXtra[] = api_get_css_asset('qtip2/jquery.qtip.min.css');
$htmlHeadXtra[] = api_get_asset('qtip2/jquery.qtip.min.js'); $htmlHeadXtra[] = api_get_asset('qtip2/jquery.qtip.min.js');
$htmlHeadXtra[] = '<script type="text/javascript" src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.frameready.js"></script>'; $htmlHeadXtra[] = '<script type="text/javascript" src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.frameready.js"></script>';
$htmlHeadXtra[] = '<script> $htmlHeadXtra[] = '<script>
$(function() { $(function() {
$("div#log_content_cleaner").bind("click", function() { $("div#log_content_cleaner").bind("click", function() {
$("div#log_content").empty(); $("div#log_content").empty();
}); });
@ -135,34 +135,34 @@ var chamilo_xajax_handler = window.oxajax;
$allowLpItemTip = api_get_configuration_value('hide_accessibility_label_on_lp_item') === false; $allowLpItemTip = api_get_configuration_value('hide_accessibility_label_on_lp_item') === false;
if ($allowLpItemTip) { if ($allowLpItemTip) {
$htmlHeadXtra[] = '<script> $htmlHeadXtra[] = '<script>
$(function() { $(function() {
$(".scorm_item_normal").qtip({ $(".scorm_item_normal").qtip({
content: { content: {
text: function(event, api) { text: function(event, api) {
var item = $(this); var item = $(this);
var itemId = $(this).attr("id"); var itemId = $(this).attr("id");
itemId = itemId.replace("toc_", ""); itemId = itemId.replace("toc_", "");
var textToShow = ""; var textToShow = "";
$.ajax({ $.ajax({
type: "GET", type: "GET",
url: "'.$ajaxUrl.'&item_id="+ itemId, url: "'.$ajaxUrl.'&item_id="+ itemId,
async: false async: false
}) })
.then(function(content) { .then(function(content) {
if (content == 1) { if (content == 1) {
textToShow = "'.addslashes(get_lang('LPItemCanBeAccessed')).'"; textToShow = "'.addslashes(get_lang('LPItemCanBeAccessed')).'";
api.set("style.classes", "qtip-green qtip-shadow"); api.set("style.classes", "qtip-green qtip-shadow");
} else { } else {
textToShow = content; textToShow = content;
api.set("style.classes", "qtip-red qtip-shadow"); api.set("style.classes", "qtip-red qtip-shadow");
} }
return textToShow; return textToShow;
}); });
return textToShow; return textToShow;
} }
} }
}); });
}); });
</script>'; </script>';
} }
@ -212,11 +212,11 @@ if ($debug) {
$get_toc_list = $lp->get_toc(); $get_toc_list = $lp->get_toc();
$get_teacher_buttons = $lp->get_teacher_toc_buttons(); $get_teacher_buttons = $lp->get_teacher_toc_buttons();
$itemType = '';
$type_quiz = false;
foreach ($get_toc_list as $toc) { foreach ($get_toc_list as $toc) {
if ($toc['id'] == $lp_item_id && $toc['type'] == 'quiz') { if ($toc['id'] == $lp_item_id) {
$type_quiz = true; $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. // Update status, total_time from lp_item_view table when you finish the exercises in learning path.
if ($debug) { if ($debug) {
error_log('$type_quiz: '.$type_quiz);
error_log('$_REQUEST[exeId]: '.intval($_REQUEST['exeId'])); error_log('$_REQUEST[exeId]: '.intval($_REQUEST['exeId']));
error_log('$lp_id: '.$lp_id); error_log('$lp_id: '.$lp_id);
error_log('$_GET[lp_item_id]: '.intval($_GET['lp_item_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); $template->assign('frame_ready', $frameReady);
// Ofaj // Ofaj

@ -376,10 +376,7 @@
{% endif %} {% endif %}
{% if disable_js_in_lp_view == 0 %} {% if disable_js_in_lp_view == 0 %}
$(function() { $(function() {
var arr = ['link', 'sco']; {{ frame_ready }}
if ($.inArray(olms.lms_item_type, arr) == -1) {
{{ frame_ready }}
}
}); });
{% endif %} {% endif %}

@ -330,13 +330,9 @@
})(); })();
{% endif %} {% endif %}
{% if disable_js_in_lp_view == 0 %} {% if disable_js_in_lp_view == 0 %}
$(function() { $(function() {
var arr = ['link', 'sco']; {{ frame_ready }}
});
if ($.inArray(olms.lms_item_type, arr) == -1) {
{{ frame_ready }}
}
});
{% endif %} {% endif %}
$(window).on('resize', function () { $(window).on('resize', function () {

Loading…
Cancel
Save