]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-21124 full support for JS in theems finished
authorPetr Skoda <skodak@moodle.org>
Wed, 23 Dec 2009 17:18:46 +0000 (17:18 +0000)
committerPetr Skoda <skodak@moodle.org>
Wed, 23 Dec 2009 17:18:46 +0000 (17:18 +0000)
lib/outputlib.php
theme/base/config.php
theme/base/javascript/navigation.js [new file with mode: 0644]
theme/standard/config.php
theme/standard/javascript/navigation.js [new file with mode: 0644]

index 60dc445478afa50a8a31fae29a08ba32c7e99544..7b056cec7d9fc080ae37c1637ae6b8aa043bb036 100644 (file)
@@ -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) {
index d3a626e6accaba2ae6b5ae9ff55b692f57b65180..1631610ca8c58aa53f2bd2138a3d96981a328339 100644 (file)
@@ -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 (file)
index 0000000..e8b872f
--- /dev/null
@@ -0,0 +1 @@
+/* base: javascript needed for navbar manipulations */
index 8f083061aaba6c523ecfc1ff896058c8bda66c1b..bdeec55b6d62ee685e7a1f2e746ca88b77ba3c4b 100644 (file)
@@ -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 (file)
index 0000000..cbb9d78
--- /dev/null
@@ -0,0 +1 @@
+/* legacy standard: javascript needed for navbar manipulations */