Browse Source

Learnpath: Fix frameReady when change item - refs BT#15389

Angel Fernando Quiroz Campos 5 years ago
parent
commit
33601ce60e

+ 1 - 1
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

+ 9 - 8
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() + ')();');
     }
 };

+ 1 - 1
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);

+ 3 - 3
main/template/default/learnpath/view.tpl

@@ -338,7 +338,7 @@
                         function(){
                             //  $("<div>I am a div courses</div>").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(){
                             //  $("<div>I am a div courses</div>").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(){
                             //  $("<div>I am a div courses</div>").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 }}"},