Posted by: atom, 2008 03.03
I know that this is not anything revolutionary or anything, but I found it very helpful when making this site, so I thought I would share.
By assigning the body element an ID, you can check it with Javascript, and then execute what you need to based on this condition, like so(wordpress example):
Some php, for the Wordpress template (in header.php):
code!
<?php
if(is_home()) //if we are at the wordpress "home"
$location = 'home';
elseif(is_single() || is_page()) // if it is a single post or page
$location = 'single';
elseif(is_some_strange_situation()) // a user function that test for something strange
$location = 'strange';
else // otherwise, nothing special
$location = 'default';
?>
<body id="<?php echo $location ?>">
Then some Javascript:
code!
<script type="text/javascript">
switch(document.body.id){
case 'home':
runAtHomeOnly();
break;
case 'single':
runOnSingleOnly();
break;
case 'strange':
runOnStrangeOnly();
default:
runOtherwise();
break;
}
runThisAlways();
function runAtHomeOnly(){
alert('You are home.');
}
function runOnSingleOnly(){
alert('You are on a single post or page.');
}
function runOnStrangeOnly(){
alert('You are somewhere strange.');
}
function runOtherwise(){
alert('You are not home, at a single post or page, and you are not somewhere strange.');
}
function runThisAlways(){
alert('I always run.');
}
</script>
The example is a little verbose I know, but wanted to make sure my point was gotten 
June 26th, 2008 at 7:24 pm
Wow - not only is Slickspeed a great test of the frameworks, it’s also a great test of browser javascript performance.
For me, on Firefox 3, Dojo is under 100ms for the entire test and is clearly the fastest. In IE (both 6 and 7), JQuery kicks butt.
I’m a Mootools fan myself but this test was an excellent eye-opener.
June 26th, 2008 at 7:26 pm
Oh yeah, my main point was that FF3 performance was a minimum of 3 times faster for all frameworks - amazing.
June 26th, 2008 at 8:02 pm
MooTools is running slowest because it no longer provides xpath support. The fact that it even manages to keep up is pretty amazing.
The reason xpath support was removed is because not all browsers support it, and the decision was made to keep it as neat and clean as possible.
You think FF3 is fast, you should check it out in th latest Safari, SquirrelFish whomps ass.
June 27th, 2008 at 8:07 am
You’re right, Safari was pretty good. The hands-down winner was Dojo on Opera 9.5 though. Dojo took only 32 ms to run the complete suite! That’s cooking with gas.