]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-21124 towards full JS support in themes
authorPetr Skoda <skodak@moodle.org>
Sun, 20 Dec 2009 21:50:46 +0000 (21:50 +0000)
committerPetr Skoda <skodak@moodle.org>
Sun, 20 Dec 2009 21:50:46 +0000 (21:50 +0000)
lib/outputlib.php
lib/outputrenderers.php
theme/javascripts.php [new file with mode: 0644]
theme/standard/config.php

index ab91fc8d9a34fa93d9e5adfbe3d55ad99ff02797..6e4227f696cbac49c13a28d2e08a87a7311a5feb 100644 (file)
@@ -146,6 +146,23 @@ class theme_config {
      */
     public $editor_sheets = array();
 
+    /**
+     * The names of all the javascript files this theme that you would
+     * like included, in order. Give the names of the files without .js.
+     *
+     * @var array
+     */
+    public $javascripts = 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.
+     * If no value specified value from parent theme used.
+     *
+     * @var array or arrays, true means all, null means use value from parent
+     */
+    public $parents_exclude_javascripts = null;
+
     /**
      * Which file to use for each page layout.
      *
@@ -364,7 +381,8 @@ class theme_config {
             $baseconfig = $config;
         }
 
-        $configurable = array('parents', 'sheets', 'parents_exclude_sheets', 'plugins_exclude_sheets', 'layouts', 'resource_mp3player_colors',
+        $configurable = array('parents', 'sheets', 'parents_exclude_sheets', 'plugins_exclude_sheets', 'javascripts',  
+                              'parents_exclude_javascripts', 'layouts', 'resource_mp3player_colors',
                               'filter_mediaplugin_colors', 'rendererfactory', 'csspostprocess', 'editor_sheets', 'rarrow', 'larrow');
 
         foreach ($config as $key=>$value) {
@@ -554,7 +572,7 @@ class theme_config {
     /**
      * Get the stylesheet URL of this theme
      * @param bool $encoded false means use & and true use &amp; in URLs
-     * @return string
+     * @return array of moodle_url
      */
     public function css_urls() {
         global $CFG;
@@ -589,6 +607,20 @@ class theme_config {
         }
     }
 
+    /**
+     * Get the javascript URL of this theme
+     * @param bool $encoded false means use & and true use &amp; in URLs
+     * @return moodle_url
+     */
+    public function javascript_url() {
+        global $CFG;
+
+        $rev = theme_get_revision();
+
+        $params = array('theme'=>$this->name,'rev'=>$rev);
+        return new moodle_url($CFG->httpswwwroot.'/theme/javascripts.php', $params);
+    }
+
     /**
      * Returns the content of the one huge CSS merged from all style sheets.
      * @return string
index fe6aa4a1cce3a828816118d8c07139712b0490c8..2888722082f9c36caddc59377664b484573f3844 100644 (file)
@@ -365,6 +365,10 @@ class core_renderer extends renderer_base {
             $output .= '<link rel="stylesheet" type="text/css" href="' . $url->out() . '" />' . "\n";
         }
 
+        // Get the theme javascript
+        $jsurl = $this->page->theme->javascript_url();
+        $this->page->requires->js($jsurl->out_raw(), true)->in_head();
+
         // 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')->in_head();
diff --git a/theme/javascripts.php b/theme/javascripts.php
new file mode 100644 (file)
index 0000000..f8baab2
--- /dev/null
@@ -0,0 +1,26 @@
+<?php
+
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * This file is responsible for serving the one huge CSS of each theme.
+ *
+ * @package   moodlecore
+ * @copyright 2009 Petr Skoda (skodak)  {@link http://skodak.org}
+ * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+//TODO
\ No newline at end of file
index 0b723f5a74711aa1cff7ef212b23840013ad6059..8f083061aaba6c523ecfc1ff896058c8bda66c1b 100644 (file)
@@ -148,3 +148,5 @@ $THEME->layouts = array(
     ),
 );
 
+/** List of javascript files that need to included on each page */
+$THEME->javascripts = array();