From 38aafea249c9a8eb68f3419e4269ab8fd55b70e6 Mon Sep 17 00:00:00 2001 From: Petr Skoda Date: Sun, 20 Dec 2009 21:50:46 +0000 Subject: [PATCH] MDL-21124 towards full JS support in themes --- lib/outputlib.php | 36 ++++++++++++++++++++++++++++++++++-- lib/outputrenderers.php | 4 ++++ theme/javascripts.php | 26 ++++++++++++++++++++++++++ theme/standard/config.php | 2 ++ 4 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 theme/javascripts.php diff --git a/lib/outputlib.php b/lib/outputlib.php index ab91fc8d9a..6e4227f696 100644 --- a/lib/outputlib.php +++ b/lib/outputlib.php @@ -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 & 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 & 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 diff --git a/lib/outputrenderers.php b/lib/outputrenderers.php index fe6aa4a1cc..2888722082 100644 --- a/lib/outputrenderers.php +++ b/lib/outputrenderers.php @@ -365,6 +365,10 @@ class core_renderer extends renderer_base { $output .= '' . "\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 index 0000000000..f8baab2c5e --- /dev/null +++ b/theme/javascripts.php @@ -0,0 +1,26 @@ +. + +/** + * 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 diff --git a/theme/standard/config.php b/theme/standard/config.php index 0b723f5a74..8f083061aa 100644 --- a/theme/standard/config.php +++ b/theme/standard/config.php @@ -148,3 +148,5 @@ $THEME->layouts = array( ), ); +/** List of javascript files that need to included on each page */ +$THEME->javascripts = array(); -- 2.39.5