Skip to content

Commit

Permalink
MDL-21124 full support for JS in theems finished
Browse files Browse the repository at this point in the history
  • Loading branch information
skodak committed Dec 23, 2009
1 parent 0ea95dd commit 358c13c
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 5 deletions.
55 changes: 51 additions & 4 deletions lib/outputlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ public function css_content() {
}
$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));
}
}
}
Expand All @@ -719,7 +719,7 @@ public function css_content() {
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));
}
}
}
Expand Down Expand Up @@ -747,8 +747,55 @@ public function javascript_url() {
* @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) {
Expand Down
2 changes: 2 additions & 0 deletions theme/base/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,5 @@
),
);

/** List of javascript files that need to included on each page */
$THEME->javascripts = array('navigation');
1 change: 1 addition & 0 deletions theme/base/javascript/navigation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* base: javascript needed for navbar manipulations */
3 changes: 2 additions & 1 deletion theme/standard/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,5 @@
);

/** List of javascript files that need to included on each page */
$THEME->javascripts = array();
$THEME->javascripts = array('navigation');

1 change: 1 addition & 0 deletions theme/standard/javascript/navigation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* legacy standard: javascript needed for navbar manipulations */

0 comments on commit 358c13c

Please sign in to comment.