In the GoogleTV post, the video mentions (briefly) a Google service called Loco. I have decided, for fun, to make this service. Introducing Google Loco. I don’t make a dime from it and I redirect all search traffic to Google.com. Just a funny joke site to show your friends. 😉
- In Firefox: flips around the text you type in
- In all browsers: randomizes the colors
I will cover the text flipping in another post. This one will focus on event handling.
Event Handling Mini-Lesson
What the heck is event handling anyway? Well, that’s the “onclick” or “onmouseover” stuff you have probably encountered. It’s a term for telling the computer to handle and event when something happens. Thus,
First of all, I added an event handler that fires when the page loads. You see, in the old days, people used stuff like this:
But we’re in 2007 now. Things are done differently. The above command now can be redone using event handlers in the following syntax (see the actual site for the advanced, error proof syntax):
window.addEventListener(‘load’, initializeOnLoad, false) // syntax different for IE, see .js file
When the parentheses are removed it’s like saying “don’t execute me, I’m just the messenger.” My, that was a very clever pun…
Or in other words, initializeOnLoad() executes whatever is inside that function. InitializeOnLoad (no parentheses) refers to the contents, but doesn’t actually execute anything. This allows you to copy it around, modify it, reassign it, or whatever else you might do with a regular variable. In our case, we assigned it to the event handler for when the page loads.
The page itself uses a “loco” variable. You’ll notice there’s stuff like:
addEvent(document.getElementById(‘typed-box’), ‘keydown’, loco.locoEffects);
This, for example, would grab the element “typed-box”, and cause loco.locoEffect to fire whenever a key is pressed on it. If I had used “window” instead of “document.getElementById(‘typed-box’)”, the event would fire when a key is hit anywhere on the page.