Skip to content

Commit 2ffbdfb

Browse files
committed
LP: Restoring Display::getFrameReadyBlock function to inject js/css libs in LP content - refs BT#21508
1 parent ef07803 commit 2ffbdfb

File tree

4 files changed

+53
-21
lines changed

4 files changed

+53
-21
lines changed

public/main/inc/lib/display.lib.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Chamilo\CoreBundle\Entity\ExtraField;
1010
use Chamilo\CoreBundle\Entity\ExtraFieldValues;
1111
use Chamilo\CoreBundle\Framework\Container;
12+
use Chamilo\CoreBundle\Repository\ColorThemeRepository;
1213
use ChamiloSession as Session;
1314
use Symfony\Component\HttpFoundation\Response;
1415

@@ -2660,4 +2661,17 @@ public static function prose(string $contents): string
26602661
</div>
26612662
";
26622663
}
2664+
2665+
public static function getFrameReadyBlock(
2666+
string $frameName,
2667+
string $itemType = '',
2668+
string $jsConditionalFunction = 'function () { return false; }'
2669+
): string {
2670+
return '$.frameReady(function() {},
2671+
"'.$frameName.'",
2672+
[
2673+
],
2674+
'.$jsConditionalFunction
2675+
.');';
2676+
}
26632677
}

public/main/lp/ScormApi.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ public static function saveItem(
561561
$return .= "updateGamification('$stars', '$score'); \n";
562562

563563
$position = $myLP->isFirstOrLastItem($item_id);
564-
$return .= "checkCurrentItemPosition('$position'); \n";
564+
$return .= "checkCurrentItemPosition('$item_id'); \n";
565565

566566
if ($mediaplayer) {
567567
$return .= $mediaplayer;

public/main/lp/lp_view.php

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,12 @@
188188
$get_toc_list = $oLP->get_toc();
189189
$get_teacher_buttons = $oLP->get_teacher_toc_buttons();
190190

191+
$itemType = '';
191192
$type_quiz = false;
192193
foreach ($get_toc_list as $toc) {
193-
if ($toc['id'] == $lp_item_id && 'quiz' === $toc['type']) {
194-
$type_quiz = true;
194+
if ($toc['id'] == $lp_item_id) {
195+
$itemType = $toc['type'];
196+
$type_quiz = 'quiz' === $toc['type'];
195197
}
196198
}
197199

@@ -559,9 +561,16 @@
559561
$template->assign('disable_js_in_lp_view', (int) ('true' === api_get_setting('lp.disable_js_in_lp_view')));
560562
$template->assign('lp_preview_image', '<img src="'.$lpPreviewImagePath.'" alt="'.$oLP->getNameNoTags().'" />');
561563

562-
//$frameReady = Display::getFrameReadyBlock('#content_id, #content_id_blank');
563-
//$template->assign('frame_ready', $frameReady);
564-
$template->assign('frame_ready', '');
564+
$frameReady = Display::getFrameReadyBlock(
565+
'#content_id, #content_id_blank',
566+
$itemType,
567+
'function () {
568+
var arr = ["link", "sco", "xapi", "quiz", "h5p"];
569+
570+
return $.inArray(olms.lms_item_type, arr) !== -1;
571+
}'
572+
);
573+
$template->assign('frame_ready', $frameReady);
565574
$template->displayTemplate('@ChamiloCore/LearnPath/view.html.twig');
566575

567576
// Restore a global setting.

public/main/lp/scorm_api.php

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1713,28 +1713,37 @@ function switch_item(current_item, next_item)
17131713

17141714
// @todo add loadForumThread inside lp_nav.php to do only one request instead of 3!
17151715
//loadForumThread(olms.lms_lp_id, next_item);
1716-
//checkCurrentItemPosition(olms.lms_item_id);
1716+
checkCurrentItemPosition(olms.lms_item_id);
17171717

17181718
return true;
17191719
}
17201720

17211721
/**
17221722
* Hide or show the navigation buttons if the current item is the First or Last
17231723
*/
1724-
var checkCurrentItemPosition = function(position) {
1725-
if (position == 'first') {
1726-
$("#scorm-previous").hide();
1727-
$("#scorm-next").show();
1728-
} else if (position == 'none') {
1729-
$("#scorm-previous").show();
1730-
$("#scorm-next").show();
1731-
} else if (position == 'last') {
1732-
$("#scorm-previous").show();
1733-
$("#scorm-next").hide();
1734-
} else if (position == 'both') {
1735-
$("#scorm-previous").hide();
1736-
$("#scorm-next").hide();
1737-
}
1724+
var checkCurrentItemPosition = function(lpItemId) {
1725+
var currentItem = $.getJSON(
1726+
'<?php echo api_get_path(WEB_AJAX_PATH); ?>lp.ajax.php' + courseUrl,
1727+
{
1728+
a: 'check_item_position',
1729+
lp_item: lpItemId
1730+
}
1731+
).done(function(parsedResponse,statusText,jqXhr) {
1732+
var position = jqXhr.responseJSON;
1733+
if (position == 'first') {
1734+
$("#scorm-previous").hide();
1735+
$("#scorm-next").show();
1736+
} else if (position == 'none') {
1737+
$("#scorm-previous").show();
1738+
$("#scorm-next").show();
1739+
} else if (position == 'last') {
1740+
$("#scorm-previous").show();
1741+
$("#scorm-next").hide();
1742+
} else if (position == 'both') {
1743+
$("#scorm-previous").hide();
1744+
$("#scorm-next").hide();
1745+
}
1746+
});
17381747
}
17391748

17401749
/**

0 commit comments

Comments
 (0)