coding / codeine
True story - A couple months ago, after another long night at work, I got pulled over by the CHP doing 75 on the freeway. “You’re up pretty late,” he said. “What were you doing tonight?”
“Coding,” I replied, as I handed him my license and registration.
He looked startled for a second. “Coding?”
“Yeah, coding.” Another pause. “I’m a computer programmer.” I began to wiggle my fingers for him, like I was typing a giant imaginary keyboard. My parents would make the same motion bragging to their friends that their son played the piano - Oh, our son has played for thirteen years! He’s like Mozart, they would say. Commence finger wiggling.
Oh. The policeman rolled his eyes as he walked back to the patrol car to relay my information. “Coding.” It was only after I drove off with a warning that I realized that the policeman didn’t think I was coding, but I was on codeine.
I’ve been doing a lot more coding lately, both in and out of work. You still won’t see write a lot about technical matters on this weblog, though. I figure that while I’m… hmm… adequate at programming, I have no right to write about it - there are thousands of other techie geeks, writing about standards and code practices and detailed how-to articles that everyone else can read and learn from. Me, I’m good at writing about how the lady at Chaat Cafe can’t get my name right.
That being said, I’ve been playing around with both PHP and DOM-based Javascript a bit more lately. The tool tips on the right hand side, for example - if you’re using Firefox, you’ll notice that the catty mouseover comments I wrote for each link had previously cut off after a certain amount of characters. I could have gone into my mini-blog weblog templates and changed the structure of how I wanted things to display, but that would have seemed like a giant overhaul. Could I do something where all I had to do was to insert a JS file and the title descriptions would automatically display? Turns out I could, thanks to the Document Object Model.
It helped that I had some old code to work from. A year ago I had written up this half-assed article on Help Tips. The plan was to show everyone how r0×0r I was at web development during my Yahoo! interview, with mixed success. After a little bit of tweaking, the code I use to enable tool tips is here.
The onload=init statement means that the init function kicks in once the document loads, and does two things: dynamically creates an empty tool tip, and collects all the a tags in the mini-blog section, where the id is set to textcontent1. The elements are stored into objTag, where mouse handlers are applied depending on whether you’ve hovered over the link or not. (It should be said that I had some help on positioning the tool tip from a similar project at WebFX. Why recreate the wheel, right?)
It shouldn’t be that difficult to implement on your pages either, provided that you have a little bit of experience with DOM. All you’d have to do is make sure that objTags is pulling the correct links and make sure you a CSS id of tooltip exists and you should be alright.
(My next post will be zanier, I promise)
13 Comments