Chaosforge Forum

General => Forum => Topic started by: AStranger on March 06, 2012, 17:00

Title: Request to fix code/mortem tags in spoilers for Chrome/Safari
Post by: AStranger on March 06, 2012, 17:00
Currently if you place a mortem or code tag inside a spoiler tag the mortem/code tag gets set to a height of 20px in all webkit browsers (mainly Chrome and Safari). I've tracked the problem down this file: http://forum.chaosforge.org/Themes/Blackrainv2_20/scripts/theme.js?rc2 (http://forum.chaosforge.org/Themes/Blackrainv2_20/scripts/theme.js?rc2). The offending function is presented below:
Code: [Select]
// The purpose of this code is to fix the height of overflow: auto blocks, because some browsers can't figure it out for themselves.
function smf_codeBoxFix()
{
var codeFix = document.getElementsByTagName('code');
for (var i = codeFix.length - 1; i >= 0; i--)
{
if (is_webkit && codeFix[i].offsetHeight < 20)
codeFix[i].style.height = (codeFix[i].offsetHeight + 20) + 'px';

else if (is_ff && (codeFix[i].scrollWidth > codeFix[i].clientWidth || codeFix[i].clientWidth == 0))
codeFix[i].style.overflow = 'scroll';

else if ('currentStyle' in codeFix[i] && codeFix[i].currentStyle.overflow == 'auto' && (codeFix[i].currentStyle.height == '' || codeFix[i].currentStyle.height == 'auto') && (codeFix[i].scrollWidth > codeFix[i].clientWidth || codeFix[i].clientWidth == 0) && (codeFix[i].offsetHeight != 0))
codeFix[i].style.height = (codeFix[i].offsetHeight + 24) + 'px';
}
}

Now I'm not quite sure what problem the first if statement is trying to fix, but it is causing the problem that I'm referring to. It looks like the if statement is trying to ensure that the code block is at least 20px high, but I can't figure out a situation where that is needed. It would seem that removing the if statement would probably be the logical answer, but if it really is there for a reason then maybe it should be changed to something like this:
Code: [Select]
if (is_webkit && codeFix[i].offsetHeight < 20 && codeFix[i].parentNode.style.display != "none")
This change fixes the problem I'm talking about, but without knowing the purpose of the if statement I can't tell if it breaks anything. Webkit browsers seem to be pretty compliant, so I kinda doubt that this if statement is needed.
Title: Re: Request to fix code/mortem tags in spoilers for Chrome/Safari
Post by: AStranger on March 27, 2012, 19:58
Well until this get fixed I made a Chrome extension (more like a hack) that fixes the problem. Specifically it changes the onclick code of the spoiler tags to check for code blocks inside and remove the height value, then show or hide the div.
Title: Re: Request to fix code/mortem tags in spoilers for Chrome/Safari
Post by: Pricklyman on March 28, 2012, 01:07
Holy crap thank you.

Works like a treat.

Although to be honest, I'd much prefer a server-side fix... :P