Campaign for removing all hard-coded styles from php files

Campaign for removing all hard-coded styles from php files

by Joseph Rézeau -
Number of replies: 1
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

Hello,

I thought that since the introduction of the new themes system in Moodle 1.5 no hard-coded formatting should subsist anywhere in any of Moodle's php files. In fact, there is still a fair amount of <font>, <bold> etc. tags hard-coded in the php files, which get in the way of proper theme css customizing.

I'll take as an example a few lines from moodle/theme/index.php which have been recently fixed to now read like this:

if (isset($THEME->sheets)) {
echo '<p style="font-size:1.5em;font-weight:bold;">'.$theme.'</p>';
} else {
echo '<p style="font-size:1.5em;font-style:bold;color:red;">'.$theme.' (Moodle 1.4)</p>';
}

If a default Moodle theme had the following styles:

.warning {color:#FF0000}
.largefont { font-size:large; /* OR font-size:110% OR font-size:1.2em *depending on your css font-size system/;}
em {font-style:italic}
strong {font-weight:bold}

then the lines from moodle/theme/index.php above could be replaced with:

if (isset($THEME->sheets)) {
echo '<p class="largerfont"><strong>'.$theme.'</strong></p>';
} else {
echo '<p class="warning largerfont">'.$theme.' (Moodle 1.4)<strong></p>';
}

with the result that the final output display would be able to be controlled from a theme's css file(s).

When I developed my own theme, there were scores of instances where I came across hard-coded style left-over in the php files, which IMHO should no longer be there.

Is there anyone in charge of cleaning up all these unwanted hard-coded styles in forthcoming version 1.6?

Thanks,

Joseph

Average of ratings: -
In reply to Joseph Rézeau

Re: Campaign for removing all hard-coded styles from php files

by David Scotson -

I agree Joseph, but I'd go further and suggest that styles should, whenever possible, be attached to tags with semantic meaning.

To continue your example the P class could be replaced with a H1/2/3 tag since the title of the theme also acts as a suitable header. Then there would be no need to specify another font size.

I'd also suggest CSS validation as a good way to spot typos and thinkos like font-style: bold