]> git.mjollnir.org Git - moodle.git/commitdiff
javascript: MDL-19475 replace require_js calls with $PAGE->requires->js.
authortjhunt <tjhunt>
Mon, 15 Jun 2009 07:57:53 +0000 (07:57 +0000)
committertjhunt <tjhunt>
Mon, 15 Jun 2009 07:57:53 +0000 (07:57 +0000)
This is the final batch.

15 files changed:
lib/questionlib.php
mod/quiz/edit.php
mod/quiz/mod_form.php
mod/quiz/review.php
mod/quiz/summary.php
mod/quiz/view.php
mod/resource/type/file/resource.class.php
mod/wiki/view.php
portfolio/type/download/file.php
question/editlib.php
question/qengine.js
question/type/questiontype.php
tag/coursetagslib.php
tag/edit.php
theme/lines/meta.php

index f5ee6e35a0277b9e5f1c46439006622fa6ec3ce4..b4753ad5c652241a4432446f89f59e58d69a1e15 100644 (file)
@@ -2112,18 +2112,19 @@ function question_init_qenginejs_script() {
 
 /// FUNCTIONS THAT SIMPLY WRAP QUESTIONTYPE METHODS //////////////////////////////////
 /**
- * Get the HTML that needs to be included in the head tag when the
- * questions in $questionlist are printed in the gives states.
+ * Give the questions in $questionlist a chance to request the CSS or JavaScript
+ * they need, before the header is printed.
+ *
+ * If your code is going to call the print_question function, it must call this
+ * funciton before print_header.
  *
- * @global object
- * @global array
  * @param array $questionlist a list of questionids of the questions what will appear on this page.
  * @param array $questions an array of question objects, whose keys are question ids.
  *      Must contain all the questions in $questionlist
  * @param array $states an array of question state objects, whose keys are question ids.
  *      Must contain the state of all the questions in $questionlist
  *
- * @return string some HTML code that can go inside the head tag.
+ * @return string Deprecated. Some HTML code that can go inside the head tag.
  */
 function get_html_head_contributions($questionlist, &$questions, &$states) {
     global $CFG, $PAGE, $QTYPES;
@@ -2133,30 +2134,34 @@ function get_html_head_contributions($questionlist, &$questions, &$states) {
     $PAGE->requires->js('question/qengine.js');
 
     // An inline script to record various lang strings, etc. that qengine.js needs.
-    $contributions = array(question_init_qenginejs_script());
+    $contributions = array();
 
     // Anything that questions on this page need.
     foreach ($questionlist as $questionid) {
         $question = $questions[$questionid];
-        $contributions = array_merge($contributions,
-                $QTYPES[$question->qtype]->get_html_head_contributions(
-                $question, $states[$questionid]));
+        $newcontributions = $QTYPES[$question->qtype]->
+                get_html_head_contributions($question, $states[$questionid]);
+        if (!empty($newcontributions)) {
+            $contributions = array_merge($contributions, $newcontributions);
+        }
     }
 
     return implode("\n", array_unique($contributions));
 }
 
 /**
- * Like @see{get_html_head_contributions} but for the editing page
+ * Like {@link get_html_head_contributions()} but for the editing page
  * question/question.php.
  *
- * @global array
  * @param $question A question object. Only $question->qtype is used.
- * @return string some HTML code that can go inside the head tag.
+ * @return string Deprecated. Some HTML code that can go inside the head tag.
  */
 function get_editing_head_contributions($question) {
     global $QTYPES;
     $contributions = $QTYPES[$question->qtype]->get_editing_head_contributions();
+    if (empty($contributions)) {
+        $contributions = array();
+    }
     return implode("\n", array_unique($contributions));
 }
 
@@ -3001,5 +3006,3 @@ function question_get_toggleflag_checksum($attemptid, $questionid, $sessionid, $
     }
     return md5($attemptid . "_" . $user->secret . "_" . $questionid . "_" . $sessionid);
 }
-
-?>
index 744dcbc259fa38a26475c5a1f6bf06fcacd78a1b..0fd54e4f43508d59c6e585b47167ac723a8b557c 100644 (file)
@@ -50,7 +50,8 @@
 require_once('../../config.php');
 require_once($CFG->dirroot . '/mod/quiz/editlib.php');
 require_once($CFG->dirroot . '/question/category_class.php');
-require_js(array('yui_yahoo', 'yui_dom-event', 'yui_container', 'yui_dragdrop'));
+$PAGE->requires->yui_lib('container');
+$PAGE->requires->yui_lib('dragdrop');
 
 /**
  * Callback function called from question_list() function
index 7d623f8b595fb41665b1e5e2b651f3ce648b740d..f258a220ad289651d336bcc1758ee2e95cc01fc6 100644 (file)
@@ -37,7 +37,7 @@ class mod_quiz_mod_form extends moodleform_mod {
 
     function definition() {
 
-        global $COURSE, $CFG, $DB;
+        global $COURSE, $CFG, $DB, $PAGE;
         $quizconfig = get_config('quiz');
         $mform    =& $this->_form;
 
@@ -111,8 +111,8 @@ class mod_quiz_mod_form extends moodleform_mod {
         if (!empty($this->_cm)) {
             $pagegroup[] = &$mform->createElement('checkbox', 'repaginatenow', '', get_string('repaginatenow', 'quiz'), array('id' => 'id_repaginatenow'));
             $mform->disabledIf('repaginatenow', 'shufflequestions', 'eq', 1);
-            require_js(array('yui_yahoo', 'yui_dom', 'yui_event'));
-            require_js('mod/quiz/edit.js');
+            $PAGE->requires->yui_lib('event');
+            $PAGE->requires->js('mod/quiz/edit.js');
         }
 
         $mform->addGroup($pagegroup, 'questionsperpagegrp', get_string('newpage', 'quiz'), null, false);
index 2922389028a534287ec5706176ad7839aa8de339..22e9a397da3f3dc71bb75dda9c0598c02b76f7e7 100644 (file)
@@ -72,7 +72,7 @@
     }
 
 /// Print the page header
-    require_js('mod/quiz/quiz.js');
+    $PAGE->requires->js('mod/quiz/quiz.js');
     $headtags = $attemptobj->get_html_head_contributions($page);
     if ($accessmanager->securewindow_required($attemptobj->is_preview_user())) {
         $accessmanager->setup_secure_page($attemptobj->get_course()->shortname.': '.format_string($attemptobj->get_quiz_name()), $headtags);
index e9e67e24e09e7da0018636a6aaf4adf1196ac8c5..bd0677937c526e784c6059897a90add5c8a53ba5 100644 (file)
@@ -44,7 +44,7 @@ $attemptobj->load_questions();
 $attemptobj->load_question_states();
 
 /// Print the page header
-require_js('mod/quiz/quiz.js');
+$PAGE->requires->js('mod/quiz/quiz.js');
 $title = get_string('summaryofattempt', 'quiz');
 if ($accessmanager->securewindow_required($attemptobj->is_preview_user())) {
     $accessmanager->setup_secure_page($attemptobj->get_course()->shortname . ': ' .
index db1f16126f1d6c459bb30ea85c9859c24741c85c..ebf50b3854178b9d97782db0bf563ba7151a6782 100644 (file)
@@ -70,7 +70,7 @@
     if ($accessmanager->securewindow_required($canpreview)) {
         $bodytags = 'onload="popupchecker(\'' . get_string('popupblockerwarning', 'quiz') . '\');"';
     }
-    require_js(array('yui_yahoo', 'yui_event'));
+    $PAGE->requires->yui_lib('event');
 
     // Note: MDL-19010 there will be further changes to printing header and blocks.
     // The code will be much nicer than this eventually.
index 7c87efe4f46ef2babeba1d745227ffd4574d70cd..20c5bfde08554510b1048099f91f97c6d1345bbe 100644 (file)
@@ -192,7 +192,7 @@ class resource_file extends resource_base {
     * @param    CFG     global object
     */
     function display() {
-        global $CFG, $THEME, $USER;
+        global $CFG, $THEME, $USER, $PAGE;
 
     /// Set up generic stuff first, including checking for access
         parent::display();
@@ -387,10 +387,7 @@ class resource_file extends resource_base {
         /// display the resource into a object tag
             if ($resource->options == "objectframe") {
             ///Yahoo javascript libaries for updating embedded object size
-                require_js(array('yui_utilities'));
-                require_js(array('yui_container'));
-                require_js(array('yui_dom-event'));
-                require_js(array('yui_dom'));
+                $PAGE->requires->yui_lib('container');
 
             ///Moodle Header and navigation bar
                 $navigation = build_navigation($this->navlinks, $cm);
index 7ca02b7478fb3953781eb3a115ab83224ad1a56e..dbc4ef710e6851dd98fe0d05d91f3d7df6e1ad35 100644 (file)
@@ -8,7 +8,7 @@
     require_once("lib.php");
     #require_once("$CFG->dirroot/course/lib.php"); // For side-blocks    
     require_once($CFG->libdir . '/ajax/ajaxlib.php');
-    require_js(array('yui_yahoo', 'yui_event', 'yui_connection'));
+    $PAGE->requires->yui_lib('connection');
 
     $ewiki_action = optional_param('ewiki_action', '', PARAM_ALPHA);     // Action on Wiki-Page
     $id           = optional_param('id', 0, PARAM_INT);                  // Course Module ID, or
index b1c8465aee7fbb4a21db38c3418fa18828f06589..1aeff5f6e18e412d1dc1aa2daea99774f03ce719 100644 (file)
@@ -11,7 +11,7 @@ if (empty($CFG->enableportfolios)) {
 }
 
 require_once($CFG->libdir.'/portfoliolib.php');
-require_js(array('yui_yahoo', 'yui_dom'));
+$PAGE->requires->yui_lib('dom');
 $id = required_param('id', PARAM_INT);
 
 require_login();
index f5d2323e406feae0a6199dda44a028924d4ce1ef..901d436efb6113316f8e912d8e48b6ee88d28e8a 100644 (file)
@@ -140,8 +140,6 @@ abstract class question_bank_column_base {
     public function __construct(question_bank_view $qbank) {
         $this->qbank = $qbank;
         $this->init();
-        require_js(array('yui_yahoo','yui_event'));
-        require_js('question/qbank.js');
     }
 
     /**
@@ -811,7 +809,7 @@ class question_bank_view {
         $this->init_columns($this->wanted_columns());
         $this->init_sort();
 
-        $PAGE->requires->yui_lib('dom-event');
+        $PAGE->requires->yui_lib('container');
     }
 
     protected function wanted_columns() {
@@ -1099,11 +1097,14 @@ class question_bank_view {
      */
     public function display($tabname, $page, $perpage, $sortorder,
             $sortorderdecoded, $cat, $recurse, $showhidden, $showquestiontext){
+        global $PAGE;
 
         if ($this->process_actions_needing_ui()) {
             return;
         }
 
+        $PAGE->requires->js('question/qbank.js');
+
         // Category selection form
         print_heading(get_string('questionbank', 'question'), '', 2);
 
@@ -1904,13 +1905,14 @@ function print_qtype_to_add_option($qtype, $localizedname) {
  * @param boolean $disabled if true, the button will be disabled.
  */
 function create_new_question_button($categoryid, $params, $caption, $tooltip = '', $disabled = false) {
-    global $CFG;
+    global $CFG, $PAGE;
     static $choiceformprinted = false;
     $params['category'] = $categoryid;
     print_single_button($CFG->wwwroot . '/question/addquestion.php', $params,
             $caption,'get', '', false, $tooltip, $disabled);
     helpbutton('types', get_string('createnewquestion', 'question'), 'question');
-    require_js(array('yui_yahoo','yui_dom','yui_event', 'yui_dragdrop', 'yui_container'));
+    $PAGE->requires->yui_lib('dragdrop');
+    $PAGE->requires->yui_lib('container');
     if (!$choiceformprinted) {
         echo '<div id="qtypechoicecontainer">';
         print_choose_qtype_to_add_form(array());
index be5eeca373392f1ee8dc0ef90851cb711d7c9dac..c159f751226f14dee4996e026e4d89bddcc8a1b3 100644 (file)
@@ -1,5 +1,5 @@
 // This script, and the YUI libraries that it needs, are inluded by
-// the require_js calls in get_html_head_contributions in lib/questionlib.php.
+// the $PAGE->requires->js calls in get_html_head_contributions in lib/questionlib.php.
 
 question_flag_changer = {
     flag_state_listeners: new Object(),
index b4054f35ef70b05d376a8975b585ec0fca6a257a..b2c9b235bcc286f8ed2bc964c3a32abe004e8f81 100644 (file)
@@ -800,22 +800,22 @@ class default_questiontype {
     // Used by the following function, so that it only returns results once per quiz page.
     private $htmlheadalreadydone = false;
     /**
-     * If this question type requires extra CSS or JavaScript to function,
-     * then this method will return an array of <link ...> tags that reference
-     * those stylesheets. This function will also call require_js()
-     * from ajaxlib.php, to get any necessary JavaScript linked in too.
+     * Hook to allow question types to include required JavaScrip or CSS on pages
+     * where they are going to be printed.
      *
-     * Remember that there may be more than one question of this type on a page.
-     * try to avoid including JS and CSS more than once.
+     * If this question type requires extra CSS or JavaScript to function,
+     * then this method, which will be called before print_header on any page
+     * where this question is going to be printed, is a chance to call
+     * $PAGE->requires->js, $PAGE->requiers->css, and so on.
      *
      * The two parameters match the first two parameters of print_question.
      *
      * @param object $question The question object.
      * @param object $state    The state object.
      *
-     * @return an array of bits of HTML to add to the head of pages where
-     * this question is print_question-ed in the body. The array should use
-     * integer array keys, which have no significance.
+     * @return array Deprecated. An array of bits of HTML to add to the head of
+     * pages where this question is print_question-ed in the body. The array
+     * should use integer array keys, which have no significance.
      */
     function get_html_head_contributions(&$question, &$state) {
         // We only do this once for this question type, no matter how often this
@@ -829,7 +829,7 @@ class default_questiontype {
         // script.js or script.php that exist in the plugin folder.
         // Core question types should not use this mechanism. Their styles
         // should be included in the standard theme.
-        return $this->find_standard_scripts_and_css();
+        $this->find_standard_scripts_and_css();
     }
 
     /**
@@ -845,7 +845,7 @@ class default_questiontype {
         // script.js or script.php that exist in the plugin folder.
         // Core question types should not use this mechanism. Their styles
         // should be included in the standard theme.
-        return $this->find_standard_scripts_and_css();
+        $this->find_standard_scripts_and_css();
     }
 
     /**
@@ -857,29 +857,24 @@ class default_questiontype {
      * @return array as required by get_html_head_contributions or get_editing_head_contributions.
      */
     protected function find_standard_scripts_and_css() {
+        global $PAGE;
+
         $plugindir = $this->plugin_dir();
-        $baseurl = $this->plugin_baseurl();
+        $plugindirrel = 'question/type/' . $this->name();
 
         if (file_exists($plugindir . '/script.js')) {
-            require_js($baseurl . '/script.js');
+            $PAGE->requires->js($plugindirrel . '/script.js');
         }
         if (file_exists($plugindir . '/script.php')) {
-            require_js($baseurl . '/script.php');
+            $PAGE->requires->js($plugindirrel . '/script.php');
         }
 
-        $stylesheets = array();
         if (file_exists($plugindir . '/styles.css')) {
-            $stylesheets[] = 'styles.css';
+            $PAGE->requires->css($plugindirrel . '/styles.css');
         }
         if (file_exists($plugindir . '/styles.php')) {
-            $stylesheets[] = 'styles.php';
-        }
-        $contributions = array();
-        foreach ($stylesheets as $stylesheet) {
-            $contributions[] = '<link rel="stylesheet" type="text/css" href="' .
-                    $baseurl . '/' . $stylesheet . '" />';
+            $PAGE->requires->css($plugindirrel . '/styles.php');
         }
-        return $contributions;
     }
 
     /**
index 2bc0a7d91defa0861ce5f85991871f637e3edb8a..ce8cf694b9aa33fcb6630379f78bf1a5c88fd86a 100644 (file)
@@ -242,7 +242,7 @@ function coursetag_print_cloud($tagcloud, $return=false, $max_size=180, $min_siz
  */
 function coursetag_get_jscript($coursetagdivs = '') {
 
-    global $CFG, $DB;
+    global $CFG, $DB, $PAGE;
 
     $tabscript = '';
     if ($coursetagdivs) {
@@ -291,7 +291,7 @@ EOT;
         //]]>
     </script>';
 
-    require_js('blocks/tags/coursetags.js');
+    $PAGE->requires->js('blocks/tags/coursetags.js');
 
     return $str;
 }
index e940ec830ad0ef14f40221d4aec64ea23dce19b7..e9cad2e20afb1c74be13ba8c3fabdc05fc5f6862 100644 (file)
@@ -4,7 +4,8 @@ require_once('../config.php');
 require_once('lib.php');
 require_once('edit_form.php');
 
-require_js(array('yui_dom-event', 'yui_connection', 'yui_animation', 'yui_autocomplete'));
+$PAGE->requires->yui_lib('animation');
+$PAGE->requires->yui_lib('autocomplete');
 
 require_login();
 
index b94d59a767ff966d7feea682950b9b78717bd172..762d879f1d162db3c745db75d791366d7899ba70 100755 (executable)
@@ -1,4 +1,6 @@
-<?php require_js(array('yui_yahoo','yui_dom','yui_event','yui_animation')); ?>
+<?php
+
+$PAGE->requires->yui_lib('animation')->in_head(); ?>
 
 <!--[if IE 7]>
     <link rel="stylesheet" type="text/css" href="<?php echo $CFG->httpsthemewww ?>/lines/styles_ie7.css" />