From 33601ce60e18f193af08099ae1ea4882c55f6560 Mon Sep 17 00:00:00 2001 From: Angel Fernando Quiroz Campos Date: Mon, 6 May 2019 18:12:53 -0500 Subject: [PATCH] Learnpath: Fix frameReady when change item - refs BT#15389 --- main/document/showinframes.php | 2 +- main/inc/lib/javascript/jquery.frameready.js | 17 +++++++++-------- main/lp/lp_view.php | 2 +- main/template/default/learnpath/view.tpl | 6 +++--- 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/main/document/showinframes.php b/main/document/showinframes.php index 525200ad65..30ef99ab67 100755 --- a/main/document/showinframes.php +++ b/main/document/showinframes.php @@ -174,7 +174,7 @@ if (api_is_course_admin()) { $frameheight = 165; } -$frameReady = Display::getFrameReadyBlock('top.mainFrame'); +$frameReady = Display::getFrameReadyBlock('#mainFrame'); $web_odf_supported_files = DocumentManager::get_web_odf_extension_list(); // PDF should be displayed with viewerJS diff --git a/main/inc/lib/javascript/jquery.frameready.js b/main/inc/lib/javascript/jquery.frameready.js index da5f2bef02..79318f2ae3 100755 --- a/main/inc/lib/javascript/jquery.frameready.js +++ b/main/inc/lib/javascript/jquery.frameready.js @@ -4,11 +4,11 @@ * @param {Array} resources * @constructor */ -$.frameReady = function (callback, target, resources) { +$.frameReady = function (callback, targetSelector, resources) { /** * @type {window} */ - var targetWindow = eval(target); + var targetWindow = document.querySelector(targetSelector); /** * @type {Document} */ @@ -41,9 +41,12 @@ $.frameReady = function (callback, target, resources) { return count; })(); + var scripsLoadedCount = 0; targetWindow.onload = function () { - targetDocument = targetWindow.document; + scripsLoadedCount = 0; + + targetDocument = targetWindow.contentDocument; scripts.forEach(function (script) { createScript(script); @@ -54,8 +57,6 @@ $.frameReady = function (callback, target, resources) { }); }; - var scripsLoadedCount = 0; - /** * @param {Object} script */ @@ -63,7 +64,7 @@ $.frameReady = function (callback, target, resources) { /** * @type {HTMLScriptElement} */ - var elParent = targetWindow.document.createElement('script'); + var elParent = targetWindow.contentDocument.createElement('script'); elParent.async = false; elParent.onload = function () { scripsLoadedCount++; @@ -90,7 +91,7 @@ $.frameReady = function (callback, target, resources) { /** * @type {HTMLLinkElement} */ - var el = targetWindow.document.createElement('link'); + var el = targetWindow.contentDocument.createElement('link'); el.setAttribute('href', stylesheet.src); el.setAttribute('rel', "stylesheet"); el.setAttribute('type', "text/css"); @@ -103,6 +104,6 @@ $.frameReady = function (callback, target, resources) { return; } - targetWindow.eval('(' + callback.toString() + ')();'); + targetWindow.contentWindow.eval('(' + callback.toString() + ')();'); } }; diff --git a/main/lp/lp_view.php b/main/lp/lp_view.php index 71daebe583..9977a92fcf 100755 --- a/main/lp/lp_view.php +++ b/main/lp/lp_view.php @@ -621,7 +621,7 @@ $template->assign( ) ); -$frameReady = Display::getFrameReadyBlock('top.content_name'); +$frameReady = Display::getFrameReadyBlock('#content_id, #content_id_blank'); $template->assign('frame_ready', $frameReady); $view = $template->get_template('learnpath/view.tpl'); $content = $template->fetch($view); diff --git a/main/template/default/learnpath/view.tpl b/main/template/default/learnpath/view.tpl index 31ed79ccb6..3171a0b6cc 100644 --- a/main/template/default/learnpath/view.tpl +++ b/main/template/default/learnpath/view.tpl @@ -338,7 +338,7 @@ function(){ // $("
I am a div courses
").prependTo("body"); }, - "top.content_name", + "#content_id", [ { type:"script", id:"_fr1", src:"{{ jquery_web_path }}", deps: [ { type:"script", id:"_fr4", src:"{{ jquery_ui_js_web_path }}"}, @@ -353,7 +353,7 @@ function(){ // $("
I am a div courses
").prependTo("body"); }, - "top.content_name", + "#content_id", [ { type:"script", id:"_fr1", src:"{{ jquery_web_path }}", deps: [ { type:"script", id:"_fr4", src:"{{ jquery_ui_js_web_path }}"}, @@ -368,7 +368,7 @@ function(){ // $("
I am a div courses
").prependTo("body"); }, - "top.content_name", + "#content_id", [ { type:"script", id:"_fr1", src:"{{ jquery_web_path }}", deps: [ { type:"script", id:"_fr4", src:"{{ jquery_ui_js_web_path }}"},