From: tjhunt Date: Mon, 15 Jun 2009 07:57:53 +0000 (+0000) Subject: javascript: MDL-19475 replace require_js calls with $PAGE->requires->js. X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=25ddb7efc990d33aa541b25359f82d038e129f74;p=moodle.git javascript: MDL-19475 replace require_js calls with $PAGE->requires->js. This is the final batch. --- diff --git a/lib/questionlib.php b/lib/questionlib.php index f5ee6e35a0..b4753ad5c6 100644 --- a/lib/questionlib.php +++ b/lib/questionlib.php @@ -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); } - -?> diff --git a/mod/quiz/edit.php b/mod/quiz/edit.php index 744dcbc259..0fd54e4f43 100644 --- a/mod/quiz/edit.php +++ b/mod/quiz/edit.php @@ -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 diff --git a/mod/quiz/mod_form.php b/mod/quiz/mod_form.php index 7d623f8b59..f258a220ad 100644 --- a/mod/quiz/mod_form.php +++ b/mod/quiz/mod_form.php @@ -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); diff --git a/mod/quiz/review.php b/mod/quiz/review.php index 2922389028..22e9a397da 100644 --- a/mod/quiz/review.php +++ b/mod/quiz/review.php @@ -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); diff --git a/mod/quiz/summary.php b/mod/quiz/summary.php index e9e67e24e0..bd0677937c 100644 --- a/mod/quiz/summary.php +++ b/mod/quiz/summary.php @@ -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 . ': ' . diff --git a/mod/quiz/view.php b/mod/quiz/view.php index db1f16126f..ebf50b3854 100644 --- a/mod/quiz/view.php +++ b/mod/quiz/view.php @@ -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. diff --git a/mod/resource/type/file/resource.class.php b/mod/resource/type/file/resource.class.php index 7c87efe4f4..20c5bfde08 100644 --- a/mod/resource/type/file/resource.class.php +++ b/mod/resource/type/file/resource.class.php @@ -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); diff --git a/mod/wiki/view.php b/mod/wiki/view.php index 7ca02b7478..dbc4ef710e 100644 --- a/mod/wiki/view.php +++ b/mod/wiki/view.php @@ -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 diff --git a/portfolio/type/download/file.php b/portfolio/type/download/file.php index b1c8465aee..1aeff5f6e1 100644 --- a/portfolio/type/download/file.php +++ b/portfolio/type/download/file.php @@ -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(); diff --git a/question/editlib.php b/question/editlib.php index f5d2323e40..901d436efb 100644 --- a/question/editlib.php +++ b/question/editlib.php @@ -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 '
'; print_choose_qtype_to_add_form(array()); diff --git a/question/qengine.js b/question/qengine.js index be5eeca373..c159f75122 100644 --- a/question/qengine.js +++ b/question/qengine.js @@ -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(), diff --git a/question/type/questiontype.php b/question/type/questiontype.php index b4054f35ef..b2c9b235bc 100644 --- a/question/type/questiontype.php +++ b/question/type/questiontype.php @@ -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 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[] = ''; + $PAGE->requires->css($plugindirrel . '/styles.php'); } - return $contributions; } /** diff --git a/tag/coursetagslib.php b/tag/coursetagslib.php index 2bc0a7d91d..ce8cf694b9 100644 --- a/tag/coursetagslib.php +++ b/tag/coursetagslib.php @@ -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; //]]> '; - require_js('blocks/tags/coursetags.js'); + $PAGE->requires->js('blocks/tags/coursetags.js'); return $str; } diff --git a/tag/edit.php b/tag/edit.php index e940ec830a..e9cad2e20a 100644 --- a/tag/edit.php +++ b/tag/edit.php @@ -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(); diff --git a/theme/lines/meta.php b/theme/lines/meta.php index b94d59a767..762d879f1d 100755 --- a/theme/lines/meta.php +++ b/theme/lines/meta.php @@ -1,4 +1,6 @@ - +requires->yui_lib('animation')->in_head(); ?>