MDL-37085 Load modchooser only when needed
authorMarina Glancy <marina@moodle.com>
Wed, 12 Dec 2012 05:46:01 +0000 (13:46 +0800)
committerMarina Glancy <marina@moodle.com>
Mon, 14 Jan 2013 04:01:23 +0000 (15:01 +1100)
course/lib.php
course/renderer.php
course/view.php
course/yui/modchooser/modchooser.js
index.php

index 3b68246..983b9fc 100644 (file)
@@ -1800,7 +1800,8 @@ function print_section_add_menus($course, $section, $modnames = null, $vertical=
             $output = html_writer::tag('div', $output, array('class' => 'show addresourcedropdown'));
             $modchooser = html_writer::tag('div', $modchooser, array('class' => 'hide addresourcemodchooser'));
         }
-        $output = $modchooser . $output;
+        $courserenderer = $PAGE->get_renderer('core', 'course');
+        $output = $courserenderer->course_modchooser($modules, $course) . $modchooser . $output;
     }
 
     if ($return) {
@@ -4481,17 +4482,6 @@ function include_course_ajax($course, $usedmodules = array(), $enabledmodules =
     // Load drag and drop upload AJAX.
     dndupload_add_to_course($course, $enabledmodules);
 
-    // Add the module chooser
-    $PAGE->requires->yui_module('moodle-course-modchooser',
-        'M.course.init_chooser',
-        array(array('courseid' => $course->id, 'closeButtonTitle' => get_string('close', 'editor')))
-    );
-    $PAGE->requires->strings_for_js(array(
-            'addresourceoractivity',
-            'modchooserenable',
-            'modchooserdisable',
-    ), 'moodle');
-
     return true;
 }
 
index faf2ea2..009fa34 100644 (file)
@@ -211,7 +211,22 @@ class core_course_renderer extends plugin_renderer_base {
      * @return string The composed HTML for the module
      */
     public function course_modchooser($modules, $course) {
-        global $OUTPUT;
+        static $isdisplayed = false;
+        if ($isdisplayed) {
+            return '';
+        }
+        $isdisplayed = true;
+
+        // Add the module chooser
+        $this->page->requires->yui_module('moodle-course-modchooser',
+        'M.course.init_chooser',
+        array(array('courseid' => $course->id, 'closeButtonTitle' => get_string('close', 'editor')))
+        );
+        $this->page->requires->strings_for_js(array(
+                'addresourceoractivity',
+                'modchooserenable',
+                'modchooserdisable',
+        ), 'moodle');
 
         // Add the header
         $header = html_writer::tag('div', get_string('addresourceoractivity', 'moodle'),
index 00c6754..73ecb65 100644 (file)
     echo html_writer::end_tag('div');
 
     // Include course AJAX
-    if (include_course_ajax($course, $modnamesused)) {
-        // Add the module chooser
-        $renderer = $PAGE->get_renderer('core', 'course');
-        echo $renderer->course_modchooser(get_module_metadata($course, $modnames, $displaysection), $course);
-    }
+    include_course_ajax($course, $modnamesused);
 
     echo $OUTPUT->footer();
index cdc93d0..2bc01b5 100644 (file)
@@ -158,6 +158,6 @@ YUI.add('moodle-course-modchooser', function(Y) {
     }
 },
 '@VERSION@', {
-    requires:['base', 'overlay', 'moodle-core-chooserdialogue', 'transition']
+    requires:['base', 'overlay', 'moodle-core-chooserdialogue', 'transition', 'moodle-course-coursebase']
 }
 );
index 35c8eeb..2c727cb 100644 (file)
--- a/index.php
+++ b/index.php
         }
     }
     // Include course AJAX
-    if (include_course_ajax($SITE, $modnamesused)) {
-        // Add the module chooser
-        $renderer = $PAGE->get_renderer('core', 'course');
-        echo $renderer->course_modchooser(get_module_metadata($SITE, $modnames), $SITE);
-    }
+    include_course_ajax($SITE, $modnamesused);
 
     if (isloggedin() and !isguestuser() and isset($CFG->frontpageloggedin)) {
         $frontpagelayout = $CFG->frontpageloggedin;