*/
protected $YUI_config;
+ /**
+ * @var array $yuicssmodules
+ */
+ protected $yuicssmodules = array();
+
/**
* @var array Some config vars exposed in JS, please no secret stuff there
*/
'moodle');
$page->requires->yui_module('moodle-core-blocks', 'M.core_blocks.init_dragdrop', array($params), null, true);
}
+
+ // Include the YUI CSS Modules.
+ $page->requires->set_yuicssmodules($page->theme->yuicssmodules);
}
/**
$this->jsinitcode[] = $jscode;
}
+ /**
+ * Set the CSS Modules to be included from YUI.
+ *
+ * @param array $modules The list of YUI CSS Modules to include.
+ */
+ public function set_yuicssmodules(array $modules = array()) {
+ $this->yuicssmodules = $modules;
+ }
+
/**
* Ensure that the specified JavaScript function is called from an inline script
* from page footer.
}
/**
- * Returns basic YUI3 JS loading code.
- * YUI3 is using autoloading of both CSS and JS code.
- *
- * Major benefit of this compared to standard js/csss loader is much improved
- * caching, better browser cache utilisation, much fewer http requests.
+ * Returns basic YUI3 CSS code.
*
- * @param moodle_page $page
* @return string
*/
- protected function get_yui3lib_headcode($page) {
+ protected function get_yui3lib_headcss() {
global $CFG;
+ $yuiformat = '-min';
+ if ($this->yui3loader->filter === 'RAW') {
+ $yuiformat = '';
+ }
+
$code = '';
+ if ($this->yui3loader->combine) {
+ if (!empty($this->yuicssmodules)) {
+ $modules = array();
+ foreach ($this->yuicssmodules as $module) {
+ $modules[] = "$CFG->yui3version/$module/$module-min.css";
+ }
+ $code .= '<link rel="stylesheet" type="text/css" href="'.$this->yui3loader->comboBase.implode('&', $modules).'" />';
+ }
+ $code .= '<link rel="stylesheet" type="text/css" href="'.$this->yui3loader->local_comboBase.'rollup/'.$CFG->yui3version.'/yui-moodlesimple' . $yuiformat . '.css" />';
+
+ } else {
+ if (!empty($this->yuicssmodules)) {
+ foreach ($this->yuicssmodules as $module) {
+ $code .= '<link rel="stylesheet" type="text/css" href="'.$this->yui3loader->base.$module.'/'.$module.'-min.css" />';
+ }
+ }
+ $code .= '<link rel="stylesheet" type="text/css" href="'.$this->yui3loader->local_comboBase.'rollup/'.$CFG->yui3version.'/yui-moodlesimple' . $yuiformat . '.css" />';
+ }
+
+ if ($this->yui3loader->filter === 'RAW') {
+ $code = str_replace('-min.css', '.css', $code);
+ } else if ($this->yui3loader->filter === 'DEBUG') {
+ $code = str_replace('-min.css', '.css', $code);
+ }
+ return $code;
+ }
+
+ /**
+ * Returns basic YUI3 JS loading code.
+ *
+ * @return string
+ */
+ protected function get_yui3lib_headcode() {
+ global $CFG;
$jsrev = $this->get_jsrev();
);
if ($this->yui3loader->combine) {
- if (!empty($page->theme->yuicssmodules)) {
- $modules = array();
- foreach ($page->theme->yuicssmodules as $module) {
- $modules[] = "$CFG->yui3version/$module/$module-min.css";
- }
- $code .= '<link rel="stylesheet" type="text/css" href="'.$this->yui3loader->comboBase.implode('&', $modules).'" />';
- }
- $code .= '<link rel="stylesheet" type="text/css" href="'.$this->yui3loader->local_comboBase.'rollup/'.$CFG->yui3version.'/yui-moodlesimple' . $yuiformat . '.css" />';
- $code .= '<script type="text/javascript" src="'.$this->yui3loader->local_comboBase
- . implode('&', $baserollups) . '"></script>';
-
+ return '<script type="text/javascript" src="' .
+ $this->yui3loader->local_comboBase .
+ implode('&', $baserollups) .
+ '"></script>';
} else {
- if (!empty($page->theme->yuicssmodules)) {
- foreach ($page->theme->yuicssmodules as $module) {
- $code .= '<link rel="stylesheet" type="text/css" href="'.$this->yui3loader->base.$module.'/'.$module.'-min.css" />';
- }
- }
- $code .= '<link rel="stylesheet" type="text/css" href="'.$this->yui3loader->local_comboBase.'rollup/'.$CFG->yui3version.'/yui-moodlesimple' . $yuiformat . '.css" />';
+ $code = '';
foreach ($baserollups as $rollup) {
$code .= '<script type="text/javascript" src="'.$this->yui3loader->local_comboBase.$rollup.'"></script>';
}
+ return $code;
}
- if ($this->yui3loader->filter === 'RAW') {
- $code = str_replace('-min.css', '.css', $code);
- } else if ($this->yui3loader->filter === 'DEBUG') {
- $code = str_replace('-min.css', '.css', $code);
- }
- return $code;
}
/**
// It is suitable only for things like mod/data which accepts CSS from teachers.
$attributes = array('rel'=>'stylesheet', 'type'=>'text/css');
+ // Add the YUI code first. We want this to be overridden by any Moodle CSS.
+ $code = $this->get_yui3lib_headcss();
+
// This line of code may look funny but it is currently required in order
// to avoid MASSIVE display issues in Internet Explorer.
// As of IE8 + YUI3.1.1 the reference stylesheet (firstthemesheet) gets
// ignored whenever another resource is added until such time as a redraw
// is forced, usually by moving the mouse over the affected element.
- $code = html_writer::tag('script', '/** Required in order to fix style inclusion problems in IE with YUI **/', array('id'=>'firstthemesheet', 'type'=>'text/css'));
+ $code .= html_writer::tag('script', '/** Required in order to fix style inclusion problems in IE with YUI **/', array('id'=>'firstthemesheet', 'type'=>'text/css'));
$urls = $this->cssthemeurls + $this->cssurls;
foreach ($urls as $url) {
$output = '';
+ // Add all standard CSS for this page.
+ $output .= $this->get_css_code();
+
// Set up the M namespace.
$js = "var M = {}; M.yui = {};\n";
$output .= html_writer::script($js);
- // YUI3 JS and CSS need to be loaded in the header but after the YUI_config has been created.
- // They should be cached well by the browser.
- $output .= $this->get_yui3lib_headcode($page);
-
- // Add hacked jQuery support, it is not intended for standard Moodle distribution!
- $output .= $this->get_jquery_headcode();
-
- // Now theme CSS + custom CSS in this specific order.
- $output .= $this->get_css_code();
-
- // Link our main JS file, all core stuff should be there.
- $output .= html_writer::script('', $this->js_fix_url('/lib/javascript-static.js'));
-
// Add variables.
if ($this->jsinitvariables['head']) {
$js = '';
$output .= html_writer::script($js);
}
- // All the other linked things from HEAD - there should be as few as possible.
- if ($this->jsincludes['head']) {
- foreach ($this->jsincludes['head'] as $url) {
- $output .= html_writer::script('', $url);
- }
- }
-
// Mark head sending done, it is not possible to anything there.
$this->headdone = true;
}
$output = html_writer::tag('div', $links, array('class'=>'skiplinks')) . "\n";
+ // YUI3 JS needs to be loaded early in the body. It should be cached well by the browser.
+ $output .= $this->get_yui3lib_headcode();
+
+ // Add hacked jQuery support, it is not intended for standard Moodle distribution!
+ $output .= $this->get_jquery_headcode();
+
+ // Link our main JS file, all core stuff should be there.
+ $output .= html_writer::script('', $this->js_fix_url('/lib/javascript-static.js'));
+
+ // All the other linked things from HEAD - there should be as few as possible.
+ if ($this->jsincludes['head']) {
+ foreach ($this->jsincludes['head'] as $url) {
+ $output .= html_writer::script('', $url);
+ }
+ }
+
// Then the clever trick for hiding of things not needed when JS works.
$output .= html_writer::script("document.body.className += ' jsenabled';") . "\n";
$this->topofbodydone = true;