From 358c13cbbf5cb057b5afc5c65689a6152ecb74bd Mon Sep 17 00:00:00 2001 From: Petr Skoda Date: Wed, 23 Dec 2009 17:18:46 +0000 Subject: [PATCH] MDL-21124 full support for JS in theems finished --- lib/outputlib.php | 55 +++++++++++++++++++++++-- theme/base/config.php | 2 + theme/base/javascript/navigation.js | 1 + theme/standard/config.php | 3 +- theme/standard/javascript/navigation.js | 1 + 5 files changed, 57 insertions(+), 5 deletions(-) create mode 100644 theme/base/javascript/navigation.js create mode 100644 theme/standard/javascript/navigation.js diff --git a/lib/outputlib.php b/lib/outputlib.php index 60dc445478..7b056cec7d 100644 --- a/lib/outputlib.php +++ b/lib/outputlib.php @@ -708,7 +708,7 @@ class theme_config { } $sheetfile = "$parent_config->dir/style/$sheet.css"; if (is_readable($sheetfile)) { - $css['parents'][$parent][$sheet] = $this->post_process("/*** Parent theme $parent/$sheet ***/\n\n" . file_get_contents($sheetfile)); + $css['parents'][$parent][$sheet] = $this->post_process("/*** Parent theme $parent/style/$sheet.css ***/\n\n" . file_get_contents($sheetfile)); } } } @@ -719,7 +719,7 @@ class theme_config { foreach ($this->sheets as $sheet) { $sheetfile = "$this->dir/style/$sheet.css"; if (is_readable($sheetfile)) { - $css['theme'][$sheet] = $this->post_process("/*** This theme $sheet ***/\n\n" . file_get_contents($sheetfile)); + $css['theme'][$sheet] = $this->post_process("/*** This theme $this->name/style/$sheet ***/\n\n" . file_get_contents($sheetfile)); } } } @@ -747,8 +747,55 @@ class theme_config { * @return string */ public function javascript_content() { - //TODO: load contents of all theme JS files - return '/*not yet fully implemented*/'; + $js = array(); + // find out wanted parent javascripts + $excludes = null; + if (is_array($this->parents_exclude_javascripts) or $this->parents_exclude_javascripts === true) { + $excludes = $this->parents_exclude_javascripts; + } else { + foreach ($this->parent_configs as $parent_config) { // the immediate parent first, base last + if (!isset($parent_config->parents_exclude_javascripts)) { + continue; + } + if (is_array($parent_config->parents_exclude_javascripts) or $parent_config->parents_exclude_javascripts === true) { + $excludes = $parent_config->parents_exclude_javascripts; + break; + } + } + } + if ($excludes !== true) { + foreach (array_reverse($this->parent_configs) as $parent_config) { // base first, the immediate parent last + $parent = $parent_config->name; + if (empty($parent_config->javascripts)) { + continue; + } + if (!empty($excludes[$parent]) and $excludes[$parent] === true) { + continue; + } + foreach ($parent_config->javascripts as $javascript) { + if (!empty($excludes[$parent]) and is_array($excludes[$parent]) + and in_array($javascript, $excludes[$parent])) { + continue; + } + $javascriptfile = "$parent_config->dir/javascript/$javascript.js"; + if (is_readable($javascriptfile)) { + $js[] = "/*** Parent theme $parent/javascript/$javascript.js ***/\n\n" . file_get_contents($javascriptfile); + } + } + } + } + + // current theme javascripts + if (is_array($this->javascripts)) { + foreach ($this->javascripts as $javascript) { + $javascriptfile = "$this->dir/javascript/$javascript.js"; + if (is_readable($javascriptfile)) { + $js[] = "/*** This theme $this->name/javascript/$javascript.js ***/\n\n" . file_get_contents($javascriptfile); + } + } + } + + return implode("\n\n", $js); } protected function post_process($css) { diff --git a/theme/base/config.php b/theme/base/config.php index d3a626e6ac..1631610ca8 100644 --- a/theme/base/config.php +++ b/theme/base/config.php @@ -121,3 +121,5 @@ $THEME->layouts = array( ), ); +/** List of javascript files that need to included on each page */ +$THEME->javascripts = array('navigation'); diff --git a/theme/base/javascript/navigation.js b/theme/base/javascript/navigation.js new file mode 100644 index 0000000000..e8b872f056 --- /dev/null +++ b/theme/base/javascript/navigation.js @@ -0,0 +1 @@ +/* base: javascript needed for navbar manipulations */ diff --git a/theme/standard/config.php b/theme/standard/config.php index 8f083061aa..bdeec55b6d 100644 --- a/theme/standard/config.php +++ b/theme/standard/config.php @@ -149,4 +149,5 @@ $THEME->layouts = array( ); /** List of javascript files that need to included on each page */ -$THEME->javascripts = array(); +$THEME->javascripts = array('navigation'); + diff --git a/theme/standard/javascript/navigation.js b/theme/standard/javascript/navigation.js new file mode 100644 index 0000000000..cbb9d78247 --- /dev/null +++ b/theme/standard/javascript/navigation.js @@ -0,0 +1 @@ +/* legacy standard: javascript needed for navbar manipulations */ -- 2.39.5