From c966c8a27b48d816575e887d61d8350706f8b0ad Mon Sep 17 00:00:00 2001 From: tjhunt Date: Thu, 23 Jul 2009 05:55:03 +0000 Subject: [PATCH] ajaxlib MDL-19077 required_js_code::now, for those cases when you really want inline JS, and you may be building HTML before print_header Both quiz and lesson need this. --- lib/ajax/ajaxlib.php | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/lib/ajax/ajaxlib.php b/lib/ajax/ajaxlib.php index 2d6be33b3a..6e85b521fc 100644 --- a/lib/ajax/ajaxlib.php +++ b/lib/ajax/ajaxlib.php @@ -889,17 +889,28 @@ abstract class required_js_code extends requirement_base { * echo $PAGE->requires->js(...)->asap(); * * - * @return string The HTML required to include this JavaScript file. The caller + * @return string The HTML for the script tag. The caller * is responsible for outputting this HTML promptly. */ public function asap() { - if ($this->is_done()) { - return; - } - if (!$this->manager->is_head_done()) { + if ($this->manager->is_head_done()) { + return $this->now(); + } else { $this->in_head(); return ''; } + } + + /** + * Return the required JavaScript immediately, so it can be included in some + * HTML that is being built. + * @return string The HTML for the script tag. The caller + * is responsible for making sure it is output. + */ + public function now() { + if ($this->is_done()) { + return ''; + } $js = $this->get_js_code(); $output = ajax_generate_script_tag($js); $this->mark_done(); -- 2.39.5