Commit 060a9b4b authored by Martyn Smith's avatar Martyn Smith Committed by Martyn Smith
Browse files

Fixed theme stuff in js

parent 63297942
......@@ -203,7 +203,7 @@ var attached = new TableRenderer(
'attachedfiles',
'attachedfiles.json.php',
[
function (r) { return TD(null, IMG({'src':config.themeurl + 'images/' + r.artefacttype + '.gif',
function (r) { return TD(null, IMG({'src':get_themeurl('images/' + r.artefacttype + '.gif'),
'alt':r.artefacttype})); },
'title',
'description',
......@@ -255,7 +255,7 @@ function attachtopost(data) {
appendChildNodes(attached.tbody,
TR({'id':rowid},
map(partial(TD,null),
[IMG({'src':config.themeurl+'images/'+data.artefacttype+'.gif',
[IMG({'src':get_themeurl('images/'+data.artefacttype+'.gif'),
'alt':data.artefacttype}),
data.title, data.description,
INPUT({'type':'button', 'class':'button',
......@@ -609,6 +609,7 @@ EOF;
// Override the default Mahara tinyMCE.init(); Add an image button and
// the execcommand_callback.
$content_css = json_encode(theme_get_url('style/tinymce.css'));
$tinymceinit = <<<EOF
<script type="text/javascript">
tinyMCE.init({
......@@ -622,7 +623,7 @@ tinyMCE.init({
theme_advanced_buttons3 : "fontselect,separator,fontsizeselect,separator,formatselect",
theme_advanced_toolbar_location : "top",
theme_advanced_toolbar_align : "center",
content_css : config.themeurl + 'style/tinymce.css',
content_css : {$content_css},
execcommand_callback : "blogpostExecCommandHandler"
});
</script>
......
......@@ -129,7 +129,7 @@ postlist.rowfunction = function(d, n, gd) {
var filerows = [TR(null, TD({'colSpan':3}, {$enc_files}))];
for (var i = 0; i < d.files.length; i++) {
filerows.push(TR({'class':'r'+((i+1)%2)},
TD(null, IMG({'src':config.themeurl + d.files[i].artefacttype + '.gif'})),
TD(null, IMG({'src':get_themeurl(d.files[i].artefacttype + '.gif')})),
TD(null, A({'href':config.wwwroot+'artefact/file/download.php?file='+d.files[i].file},
d.files[i].title)),
TD(null, d.files[i].description)));
......
......@@ -227,7 +227,7 @@ function FileBrowser(element, source, statevars, changedircallback, actionname,
}
this.icon = function (type) {
return IMG({'src':config.themeurl+'images/'+type+'.gif'});
return IMG({'src':get_themeurl('images/'+type+'.gif')});
}
this.formatname = function(r) {
......@@ -441,7 +441,7 @@ function FileUploader(element, uploadscript, statevars, foldername, folderid, up
// Display upload status
insertSiblingNodesBefore(self.form,
DIV({'id':'uploadstatusline'+self.nextupload},
IMG({'src':config.themeurl+'loading.gif'}), ' ',
IMG({'src':get_themeurl('loading.gif')}), ' ',
get_string('uploadingfiletofolder',localname,self.foldername)));
self.nextupload += 1;
return true;
......@@ -457,7 +457,7 @@ function FileUploader(element, uploadscript, statevars, foldername, folderid, up
quotaUpdate(data.quotaused, data.quota);
replaceChildNodes($('uploadstatusline'+data.uploadnumber),
IMG({'src':config.themeurl+image}), ' ',
IMG({'src':get_themeurl(image)}), ' ',
data.message, ' ',
A({'style': 'cursor: pointer;',
'onclick':'removeElement(this.parentNode)'},'[X]'));
......
......@@ -83,6 +83,17 @@ class PluginArtefactFile extends PluginArtefact {
return strnatcasecmp($a->text, $b->text);
}
public static function themepaths($type) {
static $themepaths = array(
'file' => array(
'images/file.gif',
'images/folder.gif',
'images/image.gif',
),
);
return $themepaths[$type];
}
public static function jsstrings($type) {
static $jsstrings = array(
'file' => array(
......
......@@ -14,6 +14,17 @@ function get_string(s) {
return str;
}
// Expects an image/css path to fetch url for (requires config.theme[] to be
// set)
function get_themeurl(s) {
// log('get_themeurl(' + s + ')');
if (!config || !config.theme || !config.theme[s]) {
logError('Location of ' + s + ' is unknown, ensure config.theme is set correctly');
}
return config.theme[s];
}
function globalErrorHandler(data) {
if (data.returnCode == 3) {
// Logged out!
......@@ -73,7 +84,7 @@ function formGlobalError(form, data) {
// Message related functions
function makeMessage(message, type) {
var a = A({'href': ''}, IMG({'src': config.themeurl + 'images/icon_close.gif', 'alt': '[X]'}));
var a = A({'href': ''}, IMG({'src': get_themeurl('images/icon_close.gif'), 'alt': '[X]'}));
connect(a, 'onclick', function(e) {
removeElement(a.parentNode.parentNode);
e.stop();
......
......@@ -57,6 +57,8 @@ function &smarty($javascript = array(), $headers = array(), $pagestrings = array
require_once(get_config('libroot') . 'smarty/Smarty.class.php');
$wwwroot = get_config('wwwroot');
$theme_list = array();
if (function_exists('pieform_get_headdata')) {
$headers = array_merge($headers, pieform_get_headdata());
......@@ -74,6 +76,7 @@ function &smarty($javascript = array(), $headers = array(), $pagestrings = array
if (isset($extraconfig['tinymceinit'])) {
$headers[] = $extraconfig['tinymceinit'];
} else {
$content_css = json_encode(theme_get_url('style/tinymce.css'));
$headers[] = <<<EOF
<script type="text/javascript">
tinyMCE.init({
......@@ -87,7 +90,7 @@ tinyMCE.init({
theme_advanced_buttons3 : "fontselect,separator,fontsizeselect,separator,formatselect",
theme_advanced_toolbar_location : "top",
theme_advanced_toolbar_align : "center",
content_css : config.themeurl + 'style/tinymce.css'
content_css : {$content_css}
});
</script>
......@@ -113,6 +116,7 @@ EOF;
}
$jsstrings = jsstrings();
$themepaths = themepaths();
foreach ($javascript as $jsfile) {
// For now, if there's no path in the js file, assume it's in
......@@ -128,6 +132,11 @@ EOF;
}
}
}
if (isset($themepaths[$jsfile])) {
foreach ($themepaths[$jsfile] as $themepath) {
$theme_list[$themepath] = theme_get_url($themepath);
}
}
}
else {
// A .js file with a fully specified path
......@@ -147,6 +156,13 @@ EOF;
}
}
}
if (is_callable(array($pluginclass, 'themepaths'))) {
$name = substr($bits[3], 0, strpos($bits[3], '.js'));
$tmpthemepaths = call_static_method($pluginclass, 'themepaths', $name);
foreach ($tmpthemepaths as $themepath) {
$theme_list[$themepath] = theme_get_url($themepath);
}
}
}
}
}
......@@ -159,6 +175,9 @@ EOF;
$strings[$tag] = get_raw_string($tag, $section);
}
}
foreach ($themepaths['mahara'] as $themepath) {
$theme_list[$themepath] = theme_get_url($themepath);
}
$stringjs = '<script type="text/javascript">';
$stringjs .= 'var strings = ' . json_encode($strings) . ';';
......@@ -180,6 +199,7 @@ EOF;
$smarty->assign('THEMEURL', get_config('themeurl'));
$smarty->assign('STYLESHEETLIST', array_reverse(theme_get_url('style/style.css', null, true)));
$smarty->assign('WWWROOT', $wwwroot);
$smarty->assign('THEMELIST', json_encode($theme_list));
if (defined('TITLE')) {
$smarty->assign('PAGETITLE', TITLE . ' - ' . get_config('sitename'));
......@@ -254,6 +274,16 @@ function jsstrings() {
);
}
function themepaths() {
return array(
'mahara' => array(
'images/icon_close.gif',
'loading.gif',
'success.gif',
),
);
}
/**
* Takes an array of string identifiers and returns an array of the
* corresponding strings, quoted for use in inline javascript here
......
......@@ -4,7 +4,7 @@
<title>{$PAGETITLE|escape}</title>
<script type="text/javascript">
var config = {literal}{{/literal}
'themeurl': '{$THEMEURL}',
'theme': {$THEMELIST},
'wwwroot': '{$WWWROOT}'
{literal}}{/literal};
</script>
......
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