Feb
04
Posted on 04-02-2008
Categories: ajax, css, hack, javascript, validazione - Author: Mat on 04-02-2008

19/7/2008 UPDATE
The code isn’t valid anymore. Read the comments.

In Thickbox css code there are some hacks that doesn’t validate the code (only css, rather xhtml is valid).
Invalid code is javascript inline css document. So, I changed invalid code with a js function call. Take an example:

* html #TB_overlay { /* ie6 hack */
position: absolute;
/*height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + ‘px’); NOT VALID*/
height: expression(fixHeight(document.body.scrollHeight, document.body.offsetHeight)); //VALID
}* html #TB_window { /* ie6 hack */
position: absolute;
/* margin-top: expression(0 - parseInt(this.offsetHeight / 2) + (TBWindowMargin = document.documentElement && document.documentElement.scrollTop || document.body.scrollTop) + ‘px’); NOT VALID */
margin-top:expression(fixMarginTop(this.offsetHeight,document.documentElement,document.body.scrollTop)); //VALID
}

So substitute expression inline in css file with calls to fuctions externally defined, and load the following file whenever you’re using thickbox in your site:

expressions.js:

function fixHeight(scrollHeight, offsetHeight)
{
return (scrollHeight > offsetHeight ? scrollHeight : offsetHeight + ‘px’);
}
function fixMarginTop(offsetHeight,documentElement,scrollTop)
{
return (0 - parseInt(offsetHeight / 2) + (TBWindowMargin = documentElement && documentElement.scrollTop || scrollTop) + ‘px’);
}

To use Thickbox now you need these loadings:

<script src="/lib/thickbox/jquery.js" type="text/javascript"></script>
<script src="/lib/thickbox/thickbox.js" type="text/javascript"></script>
<script src="/lib/thickbox/expressions.js" type="text/javascript"></script>
<style type="text/css"> @import "/lib/thickbox/thickbox.css"; </style>

Download Thickbox 3.1 editated sources:
thickbox.css (editated)
expressions.js (added)


 

Comments

Pavel on 14 Marzo, 2008 at 04:35 #

Thanks a lot!!

I have spent 3 hours on it.
Moreover, in my case the original code returned incorrect document.body.scrollHeight. I do not know why. But after your patch it works perfect! Thank you again!


Jods on 31 Marzo, 2008 at 22:36 #

I don’t quite understand how you’re doing this. Things still aren’t validating correctly on the W3C CSS validator for me.


Mat on 1 Aprile, 2008 at 07:41 #

Hi Jods, maybe you didn’t patch it well, or you’re using another validator…what’s the site where you use it? And which validator do you use?


Yopie on 7 Aprile, 2008 at 20:53 #

Can you post the files in a zip? I do not understand


Leo on 16 Aprile, 2008 at 14:59 #

Looks like someone came up with an alternative:

Smoothbox is the Mootools conversion of Thickbox, a script running on JQuery.

Update 16/08/2007 : Now Smoothbox uses only 100% W3C Valid CSS :-) Opacity is now set with Javascript and not in CSS. An IE CSS hack has been updated to use * html instead of _attribute.

http://gueschla.com/labs/smoothbox/


Mat on 16 Aprile, 2008 at 15:24 #

Hi Leo, thanks for your advice; anyway I suggest to choose a library by considering features and the base framework you’re already using.


Phil on 16 Luglio, 2008 at 21:30 #

Rather than spend a bunch of time trying to fix the validation issue myself I did a Google search and immediately found your fix.

Unfortunately it seemed to only work about 50% as it cut the errors from 26 to 12.

Any idea why this might be?


Mat on 16 Luglio, 2008 at 22:40 #

Hi Phil, please post the url of your site and let’s see the reason.


Phil on 16 Luglio, 2008 at 22:46 #

Sorry about that…here you go.

http://redtrailenergyllc.com/index.php/gallery/


Mat on 17 Luglio, 2008 at 00:21 #

Damn! You’re right…I don’t know why some months ago validation was correct and now it’s not. Maybe they change validation rules (probably now are stricter) and I think there’s no way to fix them. Problems are for browser specific attributes, and we need them…so it can’t be valid at all.
Anyway I don’t think it’s a big problem, because they aren’t really errors, just they aren’t w3c valid.


contezero74 on 15 Dicembre, 2008 at 17:34 #

Dear all, I just released a WordPress plugin that fix Thickbox CSS validation problem. You can find it at the following url: http://www.contezero.net/sites/contezero/index.php/2008/12/14/thickbox-fix-plugin/

At the same page, you can download a .zip file with an alternative CSS file and a Javascript that you can use to fix the problem if you don’t use WordPress.

cheers


PCARTER! on 1 Febbraio, 2009 at 03:57 #

I had an interesting result.

Everthing was working well, but for some reason the the original unvalidated version was adjusting my CSS positioning in a slightly wrong way.

I searched and found this, and immediately it validated.

However, the image then loads with the center at the far bottom left corner.

Not sure why this happened.


GG on 2 Febbraio, 2010 at 10:27 #

Post a Comment
Name:
Email:
Website:
Comments: