surelyyourenotserious.com
Event Function Stacking in JavaScript

<disclaimer>I don’t usually post the intricacies of my work here, but this one was just too cool to keep to myself. Those of you who are not steeped in JavaScript, DOM, and XHTML can stop reading here and come back later for your normal dose of humor and/or world news.</disclaimer>

I’ve been struggling for a while now with a problem in IE. On my company’s website, we use the DOM and JavaScript perform a lot of CSS trickery. IE doesn’t support some of the CSS pseudo classes we use to decorate our forms and to create our drop-down navigation. The best way I’ve found to get these pseudo classes to work in IE is the suckerfish library. You can read more about how suckerfish accomplishes this at the son of suckerfish site. They explain it much better than I could here.

Suckerfish has been wonderful and we’ve used it all over our site. However, I ran into a snag. We’re adding a search form to the top of our page template, where real estate is premium. In order to save space, I created a small icon-like button to submit the form rather than using a bigger “Search” button.

Now, to be a good and accessible site, we need to explicitly label the form somehow so the user doesn’t have to infer what it’s for. My idea (admittedly stolen) was to have the default value of the field be "Search...". When the user clicks into the field, an onfocus event removes the default value, and if the user doesn’t give us a search term, the onblur event puts the default value back. Pretty straight forward, right? Wrong.

Suckerfish has this one drawback: It overwrites any preexisting event. When my suckerfish script added an onfocus event to my search box (to change the CSS style) it overwrote my clever text value swap. I needed a way for suckerfish to stack events instead of blindly assigning the event listener to a new function.

Another bit of code we use (to created rounded boxes) utilized Scott Andrew’s addEvent method. I tried switching suckerfish to use this, but the outcome was the same. The inline event functions were overwritten.

My good friend and colleague, Randy Peterman, sent me a link to a potential fix. Simon Wilson’s addLoadEvent method seemed to do exactly what I was looking for. And sure enough, I was able to stack my events by slightly modifying his window.onload logic to take the element object and the event type as arguments. Cloogy, yes. Uses eval method, yes. But worked, apparently, at least in testing. It wasn’t until I added my code to change the value of this that this method failed.

It took a me a while to really understand what Simon’s method was doing. It involves JavaScript Closures and, what I best understand as the scope of nested function objects. When using Simon’s closure method, the this object reference gets lost as the nesting of functions unwinds. So when I tried to nest…

if( this.value == 'search...')

…I found out that this was undefined. The complicated solution was just too complicated. I needed to dumb it down.

So I did just that: Make it elementary. Rather than storing function objects within function objects and nesting closures, I just needed to strip out the meat of the functions and tack them together. Sounds pretty sophomoric, but it solved my problem.

See a sample here.

/* Retains any existing event listener, rather than overwritting it. Trint Ladd */
function stackEvent( obj, eventType, func )
{
	var oldEvent = eval( "obj." + eventType );
	var oldInnerSource = "";
	var newInnerSource = func.toString()
	newInnerSource = newInnerSource.substring( newInnerSource.indexOf( "{" ) + 1, newInnerSource.lastIndexOf( "}" ) );

	if( typeof oldEvent == "function" )
	{
		oldInnerSource = oldEvent.toString()
		oldInnerSource = oldInnerSource.substring( oldInnerSource.indexOf( "{" ) + 1, oldInnerSource.lastIndexOf( "}" ) );
	}
	eval( "obj." + eventType + " = function(){ " + oldInnerSource + newInnerSource + " }" );
}

/* suckerfish focus on textboxes */
sfFocusInput = function( elements )
{
	for( var i=0; i < elements.length; i++ )
	{
		if( elements[i].tagName == "INPUT" && ( elements[i].type != "text" && elements[i].type != "password" ) )
		{
			// Don't apply this to other input types (buttons, radios, etc.)
			continue;
		}

		stackEvent( elements[i], "onfocus", function()
			{
				this.value += "1";
			}
		);
		stackEvent( elements[i], "onfocus", function()
			{
				this.value += "2";
			}
		);
		stackEvent( elements[i], "onfocus", function()
			{
				this.value += "3";
			}
		);
	}
}

/* suckerfish method can be found at http://www.htmldog.com/articles/suckerfish/ */
suckerfish(sfFocusInput, "INPUT");
Georgia Man Gets Hot Pocket from iPod

Don’t ya just love HotPockets? Those tasty little pastries, hard as granite on the outside and hot enough to melt your teeth on the inside? MmMmm.

This story is not about that kind of HotPocket. It’s about an actual hot pocket. Flaming hot.

According to this story from an Atlanta TV station, Danny Williams’ two-year-old iPod Nano could easily have got him arrested under suspicion of terrorism. Danny works in an airport and while at work, the Nano in his pocket burst into flames. Thankfully, the TSA didn’t notice his smokin’ hot pants and he had a brochure in his pocket that protected him from the flames.

Apple has promised to replace Williams’ iPod if he sends it in, presumable so they can study it, but when the TV station tried to contact them, Apple wouldn’t talk.

Moore predicts end of Moore’s Law

For you geek theorists out there, this is huge.

Gordon Moore, co-founder of Intel, postulated back in 1965 that the speed and capacity of computer technology would double every two years. This is Moore’s Law and, with very little variation, it has held true for over four decades. The exponential increase in process speeds and storage capacity hug the theoretical graph.

So where we are in the shadow of 2010 and Moore was asked if there is a barrier at the end of the graph. He said yes! Watch the video and hear it for yourself.

The computer on which you are reading this contains a processor in which millions of tiny electrical switches are crammed onto a 2 inch wide piece of silicon and copper. There has to be insulation around these switches. (Think of the plastic coating on your hair dryer’s electric cord that keeps you from zapping yourself.) In current technology, that insulation is as little as five molecules thick. That’s insane.

What Moore says is that you can’t make the insulation any thinner without things starting to short out. According to Moore, we are 10 to 15 years away from reaching the physical limitations of electrical shrinkage.

Does that mean that we can’t go any faster? Well, they used to say you can’t go faster than the speed of sound, and for a propeller driven play, that’s probably true. So, let’s say you can’t get more than 5 gigahertz of process speed out of a single copper/silicon chip. That may be true. But that doesn’t mean we’ll never see a 10 gigahertz computer, or a 100 gigahertz computer for that matter. It just won’t work the same way that processors work today.

Still, it’s a pretty amazing time to be a geek!

Computerous Repairum!

I ordered some Microsoft certification training materials from Amazon last week. I’m not a frequent Amazon customer by any means, but they had a great deal on some stuff I needed.

Today, I received some requisite unsolicited marketing from the big A. Based on my purchase and some deep, dark, magical algorithm, I was offered these books in which I might be interested.

Apparently, Amazon thinks that the kind of people who read Microsoft training manuals are also interested in Harry Potter. I find that an offensive generalization! Those anti-geekite bigots!

Or… maybe… those Potter fans know some magic spell that can help me pass my certification test! Hey!!

As if I’m not busy enough…

…Now I’m twittering. Good grief, what’s the matter with me.

For those of you who aren’t addicted to everything web allow me to explain. Twitter is kind of like a micro blog. It’s used to keep the people closest to you even more up-to-dater than a normal blog. Each “tweet” (that’s what you call a Twitter post, if you’re cool like that) can only be up to 140 characters long. You have just enough room to say what your currently doing or mention something funny from your last meeting or post a link to something worth sharing. You can even tweet from your cell phone with SMS or from a chat client.

Twitter is also cool because, using their web site, you can respond back to other people’s tweets and you can set up a list of folks whose tweets you want to follow. You can even have Twitter send you alerts via IM or on your phone when someone in particular has tweeted (I’m sure there’s a better past tense for “tweet”, but I could think of anything that didn’t sound vulgar).

The main reason I signed up is because a lot of the big names in web design and standards are on there and I can follow them and (maybe) do a better job of staying on top of my industry. As you may have noticed, my side bar links have been updated to reflect the fact that I’m trying to keep up with those guys’ blogs too.

As a handy-dandy side benefit, Twitter has a blog plug-in that allows me to display my last few tweets here as well (as you can see to the right).

Now the big question is, will I actually use it, or will Twitter just be one more thing that ends up stuck in the corner with cobwebs on it because I’m just “too busy”? Only time will tell.

New Toy, Old Story

Treo 700wxA couple weeks ago, I got a new cell phone. Not just any new cell phone, but the cell phone over which I have been drooling for the last two or three years. A coworker got a new phone and was ready to part ways with his Treo 700wx. I picked it up at a great price with all the goodies and extras to go with it.

With the Windows Mobile OS on the phone, I’m able to sync it with my computer for contacts, calendar, etc. All of which is way cool. Plus, since Sprint was nice enough to transfer all the data from my old phone, I’m finally able to access the pictures that have long been trapped there.

That brings me to the “Old Story” part. Remember waaay back in March of 2006 when I busted my arm? Well, I finally have the picture that I took, while sitting on the curb, of my road-rashed elbow, mere minutes after the event (long before any swelling or bruising showed up). I took the picture so I could see what was going on over there, since at that time, I couldn’t twist my arm enough to see the damage. I thought I’d share this bit of history with you.

My boo boo

If you’re curious about the shirt I’m wearing, I did the artwork and you can have one for yourself. Just check out Dave’s CafePress page.

An Ode to a White Board

No, I’m not going to sing, so put away the ear plugs. What I am going to do is shower praises on my white board. I don’t mean to sound sacrilegious or idolatrous, but I really do love my white board. I am very blessed to work for a company that pampers its employees and one of my peak perks is my giant, erasable friend.

I’ve always been fond of white boards. It’s like being allowed to color on the walls without getting in trouble. I can write funny little quips, draw silly faces, or even write out long lists of tasks I am putting of whilst I doodle and joke on my white board.

In the last twelve months in particular, I have kept a ridiculously large “to-do” list on my white board. It grows and shrinks as new bugs are found and squashed. But as yet, I’ve not been anywhere near an empty white board. I’m not bragging. Far from it. I would love to have some sense of closure on this web site project, despite the job security I often joke about.

At the end of last year, in the midst of several months of 80-hour weeks, Tammy stopped by the office for dinner and snapped these pictures of me and my white board. This is when the web site was about half way finished and, as you can see just below the WBQotW, the release date was about to be pushed back yet again.

My White Board

Isn’t it beautiful? Boy am I blessed! (And fat. *sigh* 80-hour weeks don’t leave much time for exercise. Lucky for me those days are over and I’ve lost… umm… well… about 3 pounds.)

I have determined that there’s not any sensitive information on my board in these pictures, so I uploaded a full sized image for your entertainment. This is what an e-commerce web site looks like on the inside. Pretty messy, huh? Good thing guys like me can stretch a pretty user interface over the top of the chaos.

Movie Review: THX1138

THX1138For my readers with lower than average GQ, allow me to explain the significance of this movie. George Lucas (the guy that created Star Wars) did a short film in college called THX1138. Later, after he achieved some professional fame (but before he started filming Star Wars), he stretched it into a full length movie. The real significance to a geek like me is that THX1138 influenced much of Lucas’ later work. He hid* “1138” throughout the Star Wars movies. Also, “THX” is the name Lucas gave to the surround sound system his team developed. These days it’s pretty ubiquitous with theater surround sound.

Shock StickI was pretty excited to find THX on Netflix. Here was a chance to see into the past; to see into the mind that created Star Wars; to see where Star Wars was born. I watched the DVD extras first (cuz I’m geek like that) and most of it talked about the experimental nature of the sound effects. Some of the sound effects were recognizable from Star Wars (the squawky nature of the ship-to-ship radio). Others were created with techniques that were similar, but less mature than when Star Wars was filmed (The light saber sound grew out of the sound effect for “shock sticks”, futuristic tasers).

Now, enough about the geekness. How was the movie? Well, to put it gently, it sucked. It sucked hard. It feels exactly like a film school short stretched to feature length. There’s about 15 minutes worth of story and about 60 minutes worth of brooding, 1984, Brave New World, thought police, big brother, ooh-scary-too-perfect-future. Blah blah blah. There was absolutely nothing creative about it. The acting was sub-par considering the talent (Robert Duvall, for crying out loud!). The effects and cinematography had that funky, 70’s, experimental feel, but it wasn’t enough to carry the horrid script.

The longer Lucas has dragged out the Star Wars franchise, the more I’ve come to realize that he’s really not that creative. Star Wars will always be a classic, but it’s turning Lucas into a one-hit-wonder in my mind. Yeah, you had a great idea, but come on, man. It’s been over 30 years since that idea struck. How about trying something new? I know, I know. Indiana Jones, American Graffiti, whatever. Lucas has been riding the Skywalker wave too long and it’s ruined my opinion of him.

As for THX, unless you are a hard-core, Star Wars geek, don’t bother. One grin for you, Mr. Lucas.

* “Hid” may not be the best term here. 1138 is plastered all over the Star Wars movies.

Look out Ebert! Here I come!

I still don’t have a DVR, but this week, I got one step deeper into entertainment geekdom. I signed up for Netflix. I’ve now reviewed over a hundred movies (just a star rating, no write up) and my queue is up to 50 DVDs (most of those are TV shows, my “poor man’s DVR”). I just learned this morning about the “Friend” feature. Now we can all be Netflix friends and share our ratings and queues! Wheee! (Just don’t ask to borrow any of my clothes. That can ruin a friendship!)


Friend me!

Disclaimer: Keep in mind that Tammy and I are using the same account. “The Sound of Music” is not my favorite all-time movie, but it is hers. Don’t want you to think anything weird about me. I’m learning how to set up separate profiles, but I haven’t got it all straightened out yet.

Bubble Bobble Tiol and Troulbe.

FireFox Spell CheckI just want to say that FireFox 2.0 rox my sox off. The best feature by far is the built in spell checker. It works much like we’ve come to expect from MS Word with little red lines and right-click to get possible correct spellings. No more copying my blog post into Word to spell check it before posting.

Which brings us to this week’s white board quip:

Do witches run spell checkers?

I’ll never forget the time I insulted a witch and she turned me into a noot. (I got better.)

© Copyright 2004-2005, Light-Spark Design
Powered By WordPress