MDL-21242 moving yui2 skin away from theme CSS, this improves browser caching and finally we may load skin from the internet too

This commit is contained in:
Petr Skoda 2010-01-05 17:29:43 +00:00
parent 73b62703ab
commit c724f835ca
4 changed files with 27 additions and 24 deletions

View File

@ -118,7 +118,7 @@ class page_requirements_manager {
* @param moodle_page $page
* @param core_renderer $output
*/
function setup_core_javascript(moodle_page $page, core_renderer $output) {
protected function setup_core_javascript(moodle_page $page, core_renderer $output) {
global $CFG;
// JavaScript should always work with $CFG->httpswwwroot rather than $CFG->wwwroot.
@ -498,6 +498,9 @@ class page_requirements_manager {
* 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.
*
* @return string
*/
protected function get_yui3lib_headcode() {
@ -511,15 +514,30 @@ class page_requirements_manager {
/**
* Returns basic YUI2 JS loading code.
* It can be called manually at any time.
* If called manually the result needs to be output using echo().
*
* Major benefit of this compared to standard js loader is much improved
* caching, better browser cache utilisation, much fewer http requests.
*
* All YUI2 CSS is loaded automatically.
*
* @return string JS embedding code
*/
public function get_yui2lib_code() {
// All YUI2 CSS is loaded automatically
global $CFG;
if ($this->headdone) {
$code = $this->yui2loader->script_embed();
} else {
$code = $this->yui2loader->script();
if ($this->yui2loader->combine) {
$skinurl = $this->yui2loader->comboBase . $CFG->yui2version . '/build/assets/skins/sam/skin.css';
} else {
$skinurl = $this->yui2loader->base . 'assets/skins/sam/skin.css';
}
// please note this is a temporary hack until we fully migrate to later YUI3 that has all the widgets
// we can not use moodle_url because the url fomrat for combo loader is "a bit" non-standard
$code .= "\n".'<link rel="stylesheet" type="text/css" href="'.$skinurl.'" />'."\n";
}
$code = str_replace('&amp;', '&', $code);
$code = str_replace('&', '&amp;', $code);

View File

@ -580,7 +580,6 @@ class theme_config {
$rev = theme_get_revision();
$urls = array();
//TODO: MDL-21242 add here link to full YUI2 skin.css - get the url from the $page->requires instance
if ($rev > -1) {
$params = array('theme'=>$this->name,'rev'=>$rev);
@ -616,19 +615,17 @@ class theme_config {
file_put_contents($candidatesheet, serialize($css));
}
$url = $CFG->httpswwwroot.'/theme/styles_debug.php';
$urls = array();
$urls[] = new moodle_url($url, array('theme'=>$this->name,'type'=>'yui2'));
$baseurl = $CFG->httpswwwroot.'/theme/styles_debug.php';
foreach ($css['plugins'] as $plugin=>$unused) {
$urls[] = new moodle_url($url, array('theme'=>$this->name,'type'=>'plugin', 'subtype'=>$plugin));
$urls[] = new moodle_url($baseurl, array('theme'=>$this->name,'type'=>'plugin', 'subtype'=>$plugin));
}
foreach ($css['parents'] as $parent=>$sheets) {
foreach ($sheets as $sheet=>$unused2) {
$urls[] = new moodle_url($url, array('theme'=>$this->name,'type'=>'parent', 'subtype'=>$parent, 'sheet'=>$sheet));
$urls[] = new moodle_url($$baseurl, array('theme'=>$this->name,'type'=>'parent', 'subtype'=>$parent, 'sheet'=>$sheet));
}
}
foreach ($css['theme'] as $sheet=>$unused) {
$urls[] = new moodle_url($url, array('sheet'=>$sheet, 'theme'=>$this->name, 'type'=>'theme')); // sheet first in order to make long urls easier to read
$urls[] = new moodle_url($baseurl, array('sheet'=>$sheet, 'theme'=>$this->name, 'type'=>'theme')); // sheet first in order to make long urls easier to read
}
}
@ -642,15 +639,7 @@ class theme_config {
public function css_content() {
global $CFG;
$css = array('yui2'=>array(), 'plugins'=>array(), 'parents'=>array(), 'theme'=>array());
// legacy YUI2 stylesheets, YUI3 stylesheets are loaded on the fly
$yui2_sheets = "\n\n/*** Standard YUI2 sheets ***/\n\n";
$yui2_sheets .= file_get_contents("$CFG->libdir/yui/$CFG->yui2version/build/assets/skins/sam/skin.css");
//TODO: MDL-21242 move this YUI2 CSS hack to css_urls(), the page requirements manager should return the correct yui_combo.php?2.x.x/build/skinks/sam/skin.css
// search for all images in yui2 CSS and serve them through the yui_image.php script
$css['yui2'][] = preg_replace('/([a-z-]+)\.(png|gif)/', 'yui_image.php?file='.$CFG->yui2version.'/$1.$2', $yui2_sheets);
$css = array('plugins'=>array(), 'parents'=>array(), 'theme'=>array());
// get all plugin sheets
$excludes = null;

View File

@ -32,7 +32,7 @@ $themename = min_optional_param('theme', 'standard', 'SAFEDIR');
$type = min_optional_param('type', 'all', 'SAFEDIR');
$rev = min_optional_param('rev', 0, 'INT');
if (!in_array($type, array('all', 'ie', 'editor', 'yui2', 'plugins', 'parents', 'theme'))) {
if (!in_array($type, array('all', 'ie', 'editor', 'plugins', 'parents', 'theme'))) {
header('HTTP/1.0 404 not found');
die('Theme was not found, sorry.');
}
@ -116,7 +116,6 @@ function send_ie_css($themename, $rev) {
$css = <<<EOF
/** Unfortunately IE6/7 does not support more than 4096 selectors in one CSS file, which means we have to use some ugly hacks :-( **/
@import url(styles.php?theme=$themename&rev=$rev&type=yui2);
@import url(styles.php?theme=$themename&rev=$rev&type=plugins);
@import url(styles.php?theme=$themename&rev=$rev&type=parents);
@import url(styles.php?theme=$themename&rev=$rev&type=theme);

View File

@ -56,10 +56,7 @@ if (!$css = file_get_contents($candidatesheet)) {
$css = unserialize($css);
if ($type === 'yui2') {
send_uncached_css(reset($css['yui2']));
} else if ($type === 'plugin') {
if ($type === 'plugin') {
if (isset($css['plugins'][$subtype])) {
send_uncached_css($css['plugins'][$subtype]);
}