]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-21244 added new option for footer JS from themes as requested by Urs
authorPetr Skoda <skodak@moodle.org>
Tue, 5 Jan 2010 23:22:16 +0000 (23:22 +0000)
committerPetr Skoda <skodak@moodle.org>
Tue, 5 Jan 2010 23:22:16 +0000 (23:22 +0000)
lib/outputlib.php
lib/outputrenderers.php
theme/base/config.php
theme/javascripts.php

index b0001cfe42fa180643f3e89ad9480747a873609a..ece920ab320d9bd7fcfddaa33f5396788691258b 100644 (file)
@@ -148,12 +148,20 @@ class theme_config {
 
     /**
      * The names of all the javascript files this theme that you would
-     * like included, in order. Give the names of the files without .js.
+     * like included from head, in order. Give the names of the files without .js.
      *
      * @var array
      */
     public $javascripts = array();
 
+    /**
+     * The names of all the javascript files this theme that you would
+     * like included from footer, in order. Give the names of the files without .js.
+     *
+     * @var array
+     */
+    public $javascripts_footer = array();
+    
     /**
      * The names of all the javascript files from parents that should be expcluded.
      * true value may be used to specify all parents or all themes from one parent.
@@ -731,23 +739,29 @@ class theme_config {
 
     /**
      * Get the javascript URL of this theme
-     * @param bool $encoded false means use & and true use &amp; in URLs
+     * @param bool $footer true measn footer url, false means head
      * @return moodle_url
      */
-    public function javascript_url() {
+    public function javascript_url($footer=false) {
         global $CFG;
 
         $rev = theme_get_revision();
 
         $params = array('theme'=>$this->name,'rev'=>$rev);
+        if ($footer) {
+            $params['type'] = 'footer';
+        }
         return new moodle_url($CFG->httpswwwroot.'/theme/javascripts.php', $params);
     }
 
     /**
      * Returns the content of the one huge javascript file merged from all theme javascript files.
+     * @param bool $footer true measn footer url, false means head
      * @return string
      */
-    public function javascript_content() {
+    public function javascript_content($footer=false) {
+        $type = $footer ? 'javascripts_footer' : 'javascripts';
+
         $js = array();
         // find out wanted parent javascripts
         $excludes = null;
@@ -767,13 +781,13 @@ class theme_config {
         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)) {
+                if (empty($parent_config->$type)) {
                     continue;
                 }
                 if (!empty($excludes[$parent]) and $excludes[$parent] === true) {
                     continue;
                 }
-                foreach ($parent_config->javascripts as $javascript) {
+                foreach ($parent_config->$type as $javascript) {
                     if (!empty($excludes[$parent]) and is_array($excludes[$parent])
                         and in_array($javascript, $excludes[$parent])) {
                         continue;
@@ -787,8 +801,8 @@ class theme_config {
         }
 
         // current theme javascripts
-        if (is_array($this->javascripts)) {
-            foreach ($this->javascripts as $javascript) {
+        if (is_array($this->$type)) {
+            foreach ($this->$type 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);
index b9ce2f6715adb38515d1727424a51e0b363a3301..3529d923f3e8265671ff4409245807ec4b435fdb 100644 (file)
@@ -394,10 +394,12 @@ class core_renderer extends renderer_base {
             $this->page->requires->css($url->out(), true);
         }
 
-        // Get the theme javascript
+        // Get the theme javascript head and footer
         $jsurl = $this->page->theme->javascript_url();
         $this->page->requires->js($jsurl->out(), true)->in_head();
-
+        $jsurl = $this->page->theme->javascript_url(true);
+        $this->page->requires->js($jsurl->out(), true);
+        
         // Perform a browser environment check for the flash version.  Should only run once per login session.
         if (isloggedin() && !empty($CFG->excludeoldflashclients) && empty($SESSION->flashversion)) {
             $this->page->requires->yui2_lib('event');
index 850ec80a4e791fd7950b5653cb6e9480789bbe39..4b0ef7ca73eb7796b3c826e2ee6132fa8da29c17 100644 (file)
@@ -151,3 +151,4 @@ $THEME->layouts = array(
 
 /** List of javascript files that need to included on each page */
 $THEME->javascripts = array('navigation');
+//$THEME->javascripts_footer = array();
\ No newline at end of file
index 33b7ff1117c617ab1caea5a81437a136cf025f5d..01f13aef2300abcff66c7d43a00d35a8f35261f0 100644 (file)
@@ -30,6 +30,14 @@ require('../config.php'); // this stops immediately at the beginning of lib/setu
 
 $themename = min_optional_param('theme', 'standard', 'SAFEDIR');
 $rev       = min_optional_param('rev', 0, 'INT');
+$type      = min_optional_param('type', 'header', 'RAW');
+
+if ($type !== 'header' and $type !== 'footer') {
+    header('HTTP/1.0 404 not found');
+    die('Theme was not found, sorry.');
+}
+
+$footer = ($type === 'footer');
 
 if (file_exists("$CFG->dirroot/theme/$themename/config.php")) {
     // exists
@@ -40,7 +48,7 @@ if (file_exists("$CFG->dirroot/theme/$themename/config.php")) {
     die('Theme was not found, sorry.');
 }
 
-$candidate = "$CFG->dataroot/cache/theme/$themename/javascript.js";
+$candidate = "$CFG->dataroot/cache/theme/$themename/javascript_$type.js";
 
 if ($rev > -1 and file_exists($candidate)) {
     if (!empty($_SERVER['HTTP_IF_NONE_MATCH'])) {
@@ -63,7 +71,7 @@ require("$CFG->dirroot/lib/setup.php");
 
 $theme = theme_config::load($themename);
 
-$js = $theme->javascript_content();
+$js = $theme->javascript_content($footer);
 if ($rev > -1) {
     check_dir_exists(dirname($candidate), true, true);
     $fp = fopen($candidate, 'w');