Commit 65f3c09e authored by Yuliya Bozhko's avatar Yuliya Bozhko Committed by Yuliya Bozhko
Browse files

Added CSS support for page blocks (Bug #1273931)



For each block on page added check for themed css in the same way as for plugins.
Also added dynamic CSS including for new blocks in page editor.
See bug descrition for details and usage example.

Change-Id: I7cbe407b7f6811a116301ddac2c0392cbf90b121
Signed-off-by: default avatarValerii Kuznetsov <valerii.kuznetsov@totaralms.com>
Signed-off-by: default avatarYuliya Bozhko <yuliya.bozhko@totaralms.com>
parent 9b961958
......@@ -78,6 +78,8 @@ $blocktype_js = $view->get_all_blocktype_javascript();
$javascript = array_merge($javascript, $blocktype_js['jsfiles']);
$inlinejs = "addLoadEvent( function() {\n" . join("\n", $blocktype_js['initjs']) . "\n});";
$headers = array_merge($headers, $view->get_all_blocktype_css());
$smarty = smarty(
$javascript,
$headers,
......
......@@ -36,6 +36,7 @@ if ($USER->is_logged_in()) {
$javascript = array_merge($javascript, $blocktype_js['jsfiles']);
$inlinejs = "addLoadEvent( function() {\n" . join("\n", $blocktype_js['initjs']) . "\n});";
$stylesheets = array('<link rel="stylesheet" type="text/css" href="' . get_config('wwwroot') . 'theme/views.css?v=' . get_config('release'). '">');
$stylesheets = array_merge($stylesheets, $view->get_all_blocktype_css());
$smarty = smarty(
$javascript,
$stylesheets,
......
......@@ -541,6 +541,7 @@
sendjsonrequest(config['wwwroot'] + 'view/blocks.json.php', pd, 'POST', function(data) {
var div = $('<div>').html(data.data.display.html);
var blockinstance = div.find('div.blockinstance');
addBlockCss(data.css);
// Make configure button clickable, but disabled as blocks are rendered in configure mode by default
var configureButton = blockinstance.find('input.configurebutton');
if (configureButton) {
......@@ -558,6 +559,14 @@
});
}
function addBlockCss(csslist) {
$(csslist).each(function(ind, css) {
if ($('head link[href="'+$(css).attr('href')+'"]').length == 0) {
$('head').prepend($(css));
}
});
}
function showColumnBackgrounds() {
$('.row .column-content').each(function() {
$(this).addClass('block-drop-on', 100);
......
......@@ -2259,6 +2259,36 @@ class View {
);
}
/**
* Returns a list of required css files.
*/
public function get_all_blocktype_css() {
global $THEME;
$cssfiles = array();
$view_data = $this->get_row_datastructure();
foreach ($view_data as $row_data) {
foreach ($row_data as $column) {
foreach ($column['blockinstances'] as $blockinstance) {
$pluginname = $blockinstance->get('blocktype');
if (!safe_require_plugin('blocktype', $pluginname)) {
continue;
}
$artefactdir = '';
if ($blockinstance->get('artefactplugin') != '') {
$artefactdir = 'artefact/' . $blockinstance->get('artefactplugin') . '/';
}
$hrefs = $THEME->get_url('style/style.css', true, $artefactdir . 'blocktype/' . $pluginname);
$hrefs = array_reverse($hrefs);
foreach ($hrefs as $href) {
$cssfiles[] = '<link rel="stylesheet" type="text/css" href="' . $href . '?v=' . get_config('release'). '">';
}
}
}
}
return array_unique($cssfiles);
}
/**
* Returns the full path of a blocktype javascript file if it is internal
*/
......
......@@ -104,6 +104,7 @@ if ($viewtheme && $THEME->basename != $viewtheme) {
$THEME = new Theme($viewtheme);
}
$stylesheets = array('<link rel="stylesheet" type="text/css" href="' . get_config('wwwroot') . 'theme/views.css?v=' . get_config('release'). '">');
$stylesheets = array_merge($stylesheets, $view->get_all_blocktype_css());
$name = display_name($user);
define('TITLE', $name);
......
......@@ -28,6 +28,7 @@ if ($view->is_submitted()) {
if ($change) {
try {
$returndata = $view->process_changes();
$returndata['css'] = $view->get_all_blocktype_css();
json_reply(false, $returndata);
}
catch (Exception $e) {
......
......@@ -125,6 +125,7 @@ foreach (array_reverse($THEME->get_url('style/style.css', true, 'artefact/file')
$stylesheets[] = '<link rel="stylesheet" type="text/css" href="' . $sheet . '?v=' . get_config('release'). '">';
}
$stylesheets[] = '<link rel="stylesheet" type="text/css" href="' . get_config('wwwroot') . 'js/jquery/jquery-ui/css/ui-lightness/jquery-ui-1.8.19.custom.css?v=' . get_config('release'). '">';
$stylesheets = array_merge($stylesheets, $view->get_all_blocktype_css());
// Tell the user to change the view theme if the current one is no
// longer available to them.
if ($viewtheme && !isset($allowedthemes[$viewtheme])) {
......
......@@ -190,7 +190,7 @@ if ($viewtheme && $THEME->basename != $viewtheme) {
$THEME = new Theme($viewtheme);
}
$headers = array('<link rel="stylesheet" type="text/css" href="' . get_config('wwwroot') . 'theme/views.css?v=' . get_config('release'). '">');
$headers = array_merge($headers, $view->get_all_blocktype_css());
// Set up skin, if the page has one
$viewskin = $view->get('skin');
if ($viewskin && get_config('skins') && can_use_skins($owner) && (!isset($THEME->skins) || $THEME->skins !== false)) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment