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'); require('flatpickr');
//import('bootstrap-vue'); //import('bootstrap-vue');
import('bootstrap'); import('bootstrap');
import('webpack-jquery-ui'); require('webpack-jquery-ui');
import('webpack-jquery-ui/css'); require('webpack-jquery-ui/css');
// const frameReady = require('/public/main/inc/lib/javascript/jquery.frameready.js');
//
// global.frameReady = frameReady;
// window.frameReady = frameReady;
require('./vendor'); require('./vendor');
import('./main'); import('./main');
require('bootstrap-daterangepicker'); require('bootstrap-daterangepicker');
import('qtip2');
//require('bootstrap-daterangepicker/daterangepicker.js'); //require('bootstrap-daterangepicker/daterangepicker.js');
require('blueimp-file-upload'); require('blueimp-file-upload');

@ -10,6 +10,10 @@ global.jQuery = $;
import('webpack-jquery-ui'); import('webpack-jquery-ui');
import('webpack-jquery-ui/css'); 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'); var hljs = require('highlight.js');
global.hljs = hljs; global.hljs = hljs;

@ -4,107 +4,121 @@
* @param {Array} resources * @param {Array} resources
* @constructor * @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) { var targetWindow = document.querySelector(targetSelector);
count++; /**
* @type {Document}
if (!parentScript.hasOwnProperty('deps')) { */
return; 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; /**
})(); * @param {Object} parentScript
var scripsLoadedCount = 0; */
function countScripts(parentScript) {
count++;
targetWindow.onload = function () { if (!parentScript.hasOwnProperty('deps')) {
scripsLoadedCount = 0; return;
}
targetDocument = targetWindow.contentDocument; parentScript.deps.forEach(countScripts);
}
scripts.forEach(function (script) { scripts.forEach(countScripts);
createScript(script);
});
stylesheets.forEach(function (stylesheet) { return count;
createStylesheet(stylesheet); })();
}); var scripsLoadedCount = 0;
};
/** targetWindow.onload = function () {
* @param {Object} script scripsLoadedCount = 0;
*/
function createScript(script) {
/**
* @type {HTMLScriptElement}
*/
var elParent = targetWindow.contentDocument.createElement('script');
elParent.async = false;
elParent.onload = function () {
scripsLoadedCount++;
if (!script.hasOwnProperty('deps')) { targetDocument = targetWindow.contentDocument;
tryExecuteCallback();
return; scripts.forEach(function (script) {
} createScript(script);
});
script.deps.forEach(function (scriptB) { stylesheets.forEach(function (stylesheet) {
createScript(scriptB); 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'); function createScript(script) {
el.setAttribute('href', stylesheet.src); /**
el.setAttribute('rel', "stylesheet"); * @type {HTMLScriptElement}
el.setAttribute('type', "text/css"); */
if (targetDocument.head) { var elParent = targetWindow.contentDocument.createElement('script');
targetDocument.head.appendChild(el); 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) { * @param {Object} stylesheet
return; */
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; $my_style = $platform_theme;
$ajaxUrl = api_get_path(WEB_AJAX_PATH).'lp.ajax.php?a=get_item_prerequisites&'.api_get_cidreq(); $ajaxUrl = api_get_path(WEB_AJAX_PATH).'lp.ajax.php?a=get_item_prerequisites&'.api_get_cidreq();
$htmlHeadXtra[] = '<script> $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() { $(function() {
$("div#log_content_cleaner").bind("click", function() { $("div#log_content_cleaner").bind("click", function() {
$("div#log_content").empty(); $("div#log_content").empty();
@ -167,7 +160,6 @@ if ($allowLpItemTip) {
</script>'; </script>';
} }
// Impress js
if ('impress' === $lp->getDefaultViewMod()) { if ('impress' === $lp->getDefaultViewMod()) {
$lp_id = $lp->getIid(); $lp_id = $lp->getIid();
$url = api_get_path(WEB_CODE_PATH)."lp/lp_impress.php?lp_id=$lp_id&".api_get_cidreq(); $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) { switch ($lpType) {
case CLp::LP_TYPE: case CLp::LP_TYPE:
$oLP->stop_previous_item(); $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); $preReqCheck = $oLP->prerequisites_match($lp_item_id);
if (true === $preReqCheck) { if (true === $preReqCheck) {
@ -250,7 +242,7 @@ if (!isset($src)) {
case CLp::SCORM_TYPE: case CLp::SCORM_TYPE:
// save old if asset // save old if asset
$oLP->stop_previous_item(); // save status manually 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); $preReqCheck = $oLP->prerequisites_match($lp_item_id);
if (true === $preReqCheck) { if (true === $preReqCheck) {
$src = $oLP->get_link('http', $lp_item_id, $get_toc_list); $src = $oLP->get_link('http', $lp_item_id, $get_toc_list);
@ -261,7 +253,7 @@ if (!isset($src)) {
break; break;
case CLp::AICC_TYPE: case CLp::AICC_TYPE:
$oLP->stop_previous_item(); // save status manually if asset $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); $preReqCheck = $oLP->prerequisites_match($lp_item_id);
if (true === $preReqCheck) { if (true === $preReqCheck) {
$src = $oLP->get_link( $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('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().'" />'); $template->assign('lp_preview_image', '<img src="'.$lpPreviewImagePath.'" alt="'.$oLP->getNameNoTags().'" />');
$frameReady = Display::getFrameReadyBlock('#content_id, #content_id_blank'); //$frameReady = Display::getFrameReadyBlock('#content_id, #content_id_blank');
$template->assign('frame_ready', $frameReady); //$template->assign('frame_ready', $frameReady);
$template->assign('frame_ready', '');
$template->displayTemplate('@ChamiloCore/LearnPath/view.html.twig'); $template->displayTemplate('@ChamiloCore/LearnPath/view.html.twig');
// Restore a global setting. // Restore a global setting.

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

Loading…
Cancel
Save