LPs: Fix frameready load

pull/3844/head
Julio Montoya 5 years ago
parent 4791a8a353
commit 00bfa31cd1
  1. 11
      assets/js/app.js
  2. 4
      assets/js/lp.js
  3. 176
      public/main/inc/lib/javascript/jquery.frameready.js
  4. 19
      public/main/lp/lp_view.php
  5. 28
      src/CoreBundle/Resources/views/LearnPath/view.html.twig

@ -20,11 +20,18 @@ require('select2/dist/js/select2.full.min');
require('flatpickr');
//import('bootstrap-vue');
import('bootstrap');
import('webpack-jquery-ui');
import('webpack-jquery-ui/css');
require('webpack-jquery-ui');
require('webpack-jquery-ui/css');
// const frameReady = require('/public/main/inc/lib/javascript/jquery.frameready.js');
//
// global.frameReady = frameReady;
// window.frameReady = frameReady;
require('./vendor');
import('./main');
require('bootstrap-daterangepicker');
import('qtip2');
//require('bootstrap-daterangepicker/daterangepicker.js');
require('blueimp-file-upload');

@ -10,6 +10,10 @@ global.jQuery = $;
import('webpack-jquery-ui');
import('webpack-jquery-ui/css');
const frameReady = require('/public/main/inc/lib/javascript/jquery.frameready.js');
global.frameReady = frameReady;
window.frameReady = frameReady;
var hljs = require('highlight.js');
global.hljs = hljs;

@ -4,107 +4,121 @@
* @param {Array} resources
* @constructor
*/
$.frameReady = function (callback, targetSelector, resources) {
/**
* @type {window}
*/
var targetWindow = document.querySelector(targetSelector);
/**
* @type {Document}
*/
var targetDocument = null;
var scripts = resources.filter(function (resource) {
return resource.type === 'script';
});
var stylesheets = resources.filter(function (resource) {
return resource.type === 'stylesheet';
});
var scriptsCount = (function () {
var count = 0;
(function (factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['jquery'], factory);
} else if (typeof module === 'object' && typeof module.exports === 'object') {
factory(require('jquery'));
} else {
// Browser globals
factory(jQuery);
}
}(function ($) {
$.frameReady = function (callback, targetSelector, resources) {
/**
* @param {Object} parentScript
* @type {window}
*/
function countScripts(parentScript) {
count++;
if (!parentScript.hasOwnProperty('deps')) {
return;
}
var targetWindow = document.querySelector(targetSelector);
/**
* @type {Document}
*/
var targetDocument = null;
parentScript.deps.forEach(countScripts);
}
var scripts = resources.filter(function (resource) {
return resource.type === 'script';
});
var stylesheets = resources.filter(function (resource) {
return resource.type === 'stylesheet';
});
scripts.forEach(countScripts);
var scriptsCount = (function () {
var count = 0;
return count;
})();
var scripsLoadedCount = 0;
/**
* @param {Object} parentScript
*/
function countScripts(parentScript) {
count++;
targetWindow.onload = function () {
scripsLoadedCount = 0;
if (!parentScript.hasOwnProperty('deps')) {
return;
}
targetDocument = targetWindow.contentDocument;
parentScript.deps.forEach(countScripts);
}
scripts.forEach(function (script) {
createScript(script);
});
scripts.forEach(countScripts);
stylesheets.forEach(function (stylesheet) {
createStylesheet(stylesheet);
});
};
return count;
})();
var scripsLoadedCount = 0;
/**
* @param {Object} script
*/
function createScript(script) {
/**
* @type {HTMLScriptElement}
*/
var elParent = targetWindow.contentDocument.createElement('script');
elParent.async = false;
elParent.onload = function () {
scripsLoadedCount++;
targetWindow.onload = function () {
scripsLoadedCount = 0;
if (!script.hasOwnProperty('deps')) {
tryExecuteCallback();
targetDocument = targetWindow.contentDocument;
return;
}
scripts.forEach(function (script) {
createScript(script);
});
script.deps.forEach(function (scriptB) {
createScript(scriptB);
stylesheets.forEach(function (stylesheet) {
createStylesheet(stylesheet);
});
};
elParent.setAttribute('src', script.src);
targetDocument.body.appendChild(elParent);
}
/**
* @param {Object} stylesheet
*/
function createStylesheet(stylesheet) {
/**
* @type {HTMLLinkElement}
* @param {Object} script
*/
var el = targetWindow.contentDocument.createElement('link');
el.setAttribute('href', stylesheet.src);
el.setAttribute('rel', "stylesheet");
el.setAttribute('type', "text/css");
if (targetDocument.head) {
targetDocument.head.appendChild(el);
function createScript(script) {
/**
* @type {HTMLScriptElement}
*/
var elParent = targetWindow.contentDocument.createElement('script');
elParent.async = false;
elParent.onload = function () {
scripsLoadedCount++;
if (!script.hasOwnProperty('deps')) {
tryExecuteCallback();
return;
}
script.deps.forEach(function (scriptB) {
createScript(scriptB);
});
};
elParent.setAttribute('src', script.src);
targetDocument.body.appendChild(elParent);
}
}
function tryExecuteCallback() {
if (scripsLoadedCount < scriptsCount) {
return;
/**
* @param {Object} stylesheet
*/
function createStylesheet(stylesheet) {
/**
* @type {HTMLLinkElement}
*/
var el = targetWindow.contentDocument.createElement('link');
el.setAttribute('href', stylesheet.src);
el.setAttribute('rel', "stylesheet");
el.setAttribute('type', "text/css");
if (targetDocument.head) {
targetDocument.head.appendChild(el);
}
}
targetWindow.contentWindow.eval('(' + callback.toString() + ')();');
}
};
function tryExecuteCallback() {
if (scripsLoadedCount < scriptsCount) {
return;
}
targetWindow.contentWindow.eval('(' + callback.toString() + ')();');
}
};
}));

@ -90,13 +90,6 @@ $platform_theme = api_get_setting('stylesheets');
$my_style = $platform_theme;
$ajaxUrl = api_get_path(WEB_AJAX_PATH).'lp.ajax.php?a=get_item_prerequisites&'.api_get_cidreq();
$htmlHeadXtra[] = '<script>
<!--
var jQueryFrameReadyConfigPath = \''.api_get_jquery_web_path().'\';
-->
</script>';
$htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.frameready.js"></script>';
$htmlHeadXtra[] = '<script>
$(function() {
$("div#log_content_cleaner").bind("click", function() {
$("div#log_content").empty();
@ -167,7 +160,6 @@ if ($allowLpItemTip) {
</script>';
}
// Impress js
if ('impress' === $lp->getDefaultViewMod()) {
$lp_id = $lp->getIid();
$url = api_get_path(WEB_CODE_PATH)."lp/lp_impress.php?lp_id=$lp_id&".api_get_cidreq();
@ -208,7 +200,7 @@ if (!isset($src)) {
switch ($lpType) {
case CLp::LP_TYPE:
$oLP->stop_previous_item();
$htmlHeadXtra[] = '<script src="scorm_api.php" type="text/javascript"></script>';
$htmlHeadXtra[] = '<script src="scorm_api.php"></script>';
$preReqCheck = $oLP->prerequisites_match($lp_item_id);
if (true === $preReqCheck) {
@ -250,7 +242,7 @@ if (!isset($src)) {
case CLp::SCORM_TYPE:
// save old if asset
$oLP->stop_previous_item(); // save status manually if asset
$htmlHeadXtra[] = '<script src="scorm_api.php" type="text/javascript"></script>';
$htmlHeadXtra[] = '<script src="scorm_api.php"></script>';
$preReqCheck = $oLP->prerequisites_match($lp_item_id);
if (true === $preReqCheck) {
$src = $oLP->get_link('http', $lp_item_id, $get_toc_list);
@ -261,7 +253,7 @@ if (!isset($src)) {
break;
case CLp::AICC_TYPE:
$oLP->stop_previous_item(); // save status manually if asset
$htmlHeadXtra[] = '<script src="'.$oLP->get_js_lib().'" type="text/javascript"></script>';
$htmlHeadXtra[] = '<script src="'.$oLP->get_js_lib().'"></script>';
$preReqCheck = $oLP->prerequisites_match($lp_item_id);
if (true === $preReqCheck) {
$src = $oLP->get_link(
@ -567,8 +559,9 @@ $template->assign('menu_location', $menuLocation);
$template->assign('disable_js_in_lp_view', (int) api_get_configuration_value('disable_js_in_lp_view'));
$template->assign('lp_preview_image', '<img src="'.$lpPreviewImagePath.'" alt="'.$oLP->getNameNoTags().'" />');
$frameReady = Display::getFrameReadyBlock('#content_id, #content_id_blank');
$template->assign('frame_ready', $frameReady);
//$frameReady = Display::getFrameReadyBlock('#content_id, #content_id_blank');
//$template->assign('frame_ready', $frameReady);
$template->assign('frame_ready', '');
$template->displayTemplate('@ChamiloCore/LearnPath/view.html.twig');
// Restore a global setting.

@ -147,17 +147,15 @@
<div id="flag-mobile" class="visible-xs-block" aria-hidden="true"></div>
{% include '@ChamiloCore/LearnPath/scorm_list.html.twig' %}
</div>
{# end TOC layout #}
</div>
</div>
{# end left zone #}
{% endif %}
{# Right zone #}
<div id="learning_path_right_zone" class="{{ show_left_column == 1 ? 'content-scorm' : 'no-right-col' }}">
<div class="lp-view-zone-container">
<div class="lp-view-tabs">
<div id="navTabsbar" class="nav-tabs-bar">
<div id="navTabBar" class="nav-tabs-bar">
<ul id="navTabs" class="nav nav-tabs tabs-right" role="tablist">
<li role="presentation" class="active">
<a href="#lp-view-content" title="{{ 'Lesson'|get_lang }}"
@ -179,7 +177,6 @@
{% include '@ChamiloCore/LearnPath/menubar.html.twig' %}
<div id="tab-iframe" class="tab-content">
<div role="tabpanel" class="tab-pane active" id="lp-view-content">
<div id="wrapper-iframe">
{% if lp_mode == 'fullscreen' %}
@ -191,7 +188,9 @@
border="0"
frameborder="0"
allowfullscreen="true"
webkitallowfullscreen="true" mozallowfullscreen="true"></iframe>
webkitallowfullscreen="true"
mozallowfullscreen="true">
</iframe>
{% else %}
<iframe
id="content_id"
@ -201,7 +200,9 @@
border="0"
frameborder="0"
allowfullscreen="true"
webkitallowfullscreen="true" mozallowfullscreen="true"></iframe>
webkitallowfullscreen="true"
mozallowfullscreen="true">
</iframe>
{% endif %}
</div>
</div>
@ -260,10 +261,10 @@
$(this).attr('title', '{{ "Collapse" | get_lang }}');
}
if($('#navTabsbar').is(':hidden')) {
$('#navTabsbar').show();
if($('#navTabBar').is(':hidden')) {
$('#navTabBar').show();
} else {
$('#navTabsbar').hide();
$('#navTabBar').hide();
}
});
{% else %}
@ -304,22 +305,21 @@
});
$('.scorm_item_normal a, #scorm-previous, #scorm-next').on('click', function () {
$('.lp-view-tabs').animate({opacity: 0}, 500);
//$('.lp-view-tabs').animate({opacity: 0}, 500);
});
$('#learning_path_right_zone #lp-view-content iframe').on('load', function () {
$('.lp-view-tabs a[href="#lp-view-content"]').tab('show');
$('.lp-view-tabs').animate({opacity: 1}, 500);
//$('.lp-view-tabs').animate({opacity: 1}, 500);
});
{% if lp_mode == 'embedded' %}
$('.scorm_item_normal a, #scorm-previous, #scorm-next').on('click', function () {
/*$('.scorm_item_normal a, #scorm-previous, #scorm-next').on('click', function () {
$('.lp-view-tabs').animate({opacity: 0}, 500);
if ($('#flag-mobile').is(':visible') && !$('#learning_path_main').is('.lp-view-collapsed')) {
$('#lp-view-expand-toggle').trigger('click');
}
});
});*/
{% endif %}
loadForumThread({{ lp_id }}, {{ lp_current_item_id }});

Loading…
Cancel
Save