mirror of
https://github.com/moodle/moodle.git
synced 2025-04-25 10:26:17 +02:00
MDL-21244 added new option for footer JS from themes as requested by Urs
This commit is contained in:
parent
b0ccfc5ce8
commit
04c0140811
@ -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 & 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);
|
||||
|
@ -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');
|
||||
|
@ -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();
|
@ -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');
|
||||
|
Loading…
x
Reference in New Issue
Block a user