Archives for September 2006

Client-side query term highlighting demo using jQuery

Yesterday, the subject of “static vs. dynamic websites” came up and an example of “something that requires dynamic page assembly” was search query term highlighting. In other words, using the HTTP Referer header (yes, it’s misspelled but that’s how it is in the spec) header and parsing it and if it’s a click-through from a search engine results page (SERP), using the search terms to highlight occurrences of them in the page.

I argued that while you could do this server-side, that this wasn’t necessary; it could be done client-side, too. In modern browsers, the “referer” (sic) information is available through JavaScript in the document.referrer (spelled correctly) variable. (NB: If you’re looking for document.referer, you’ll get frustrated. It’s actually spelled correctly in JS.)

As my suggestion to use JS and DHTML on the client-side wasn’t getting across, I decided to implement a quick proof-of-concept demo using jQuery, a fantastic JavaScript library that’s light on bytes but heavy on the features. Here’s a link to the demo:

Client-side query term highlighting demo using jQuery

Here’s the few lines of CSS and JS that makes it work:

</p> <style type="text/css"> .qterm { color: #444; background-color: #ee9; font-weight: bold; } a span.qterm { color: #00f; text-decoration: underline; } a:hover span.qterm { color: #666; } </style> <p><script language="JavaScript"> $(document).ready(function() { if (!document.referrer) return; var matches = document.referrer.match(/[?&]q=([^&]*)/); if (!matches) return; var terms = unescape(matches[1].replace(/\+/g, ' ')); var re = new RegExp().compile('(' + terms + ')', 'i'); $("body *").each(function() { if ($(this).children().size() > 0) return; if ($(this).is("xmp, pre")) return; var html = $(this).html(); var newhtml = html.replace(re, '<span class="qterm">$1</span>'); $(this).html(newhtml); }); }); </script></p> <p>

It is really that simple. Now you see why I love jQuery.

Tags:
,
,
,
,
,

del.icio.us/dossy links since September 4, 2006 at 09:25 AM

del.icio.us/dossy (RSS) links since September 4, 2006 at 09:25 AM:

Rockin’ out my guitar at Sunday school

Today marks the start of me playing guitar with the children in Sunday school at my church. My guitar-fu is weak, but the only way to get better is to practice, right?

The idea is that the kids have been singing songs in Sunday school a capella, but it’s more fun to sing along to an instrument, right? So, I volunteered to play along on my guitar. Today, I played “Hallelu, Hallelujah!” and the kids sang! I think I played it a little too fast … and the voices of the 20-odd kids really drowned out my unamplified acoustic guitar, anyway. But, it was still lots of fun and I’m looking forward to doing it again next week.

Tags:
,
,

Tcl’2006, or why I don’t travel to conferences much

The annual Tcl conference, Tcl’2006, is going to be held in Naperville, IL, this year, during the week of October 9-11. At a bare minimum, if I only go for the technical sessions, the registration is $395 (with the $100 early-bird discount that ends October 1st) and covers October 11-13. Airfare from Newark (EWR) to O’Hare (ORD) on Continental, according to Travelocity.com, would be $173.60 round-trip, if I fly out the evening of October 10th and return the evening of October 13th (Flights 1193/1174). Hotel rooms at $99/night for those 3 nights will run me $297 plus taxes.

Not including meals and other incidental expenses (transportation to and from the airport, etc.), we’re talking close to $900 to attend. That’s a lot of money to be spending out of my own pocket. Given the attendees and speakers, it’d be worth it, but on top of existing expenses, it’ll be hard to come up with the money.

I guess I have a few weeks to try and scare up some consulting work to pay for it.

Tags:
,

del.icio.us/dossy links since August 28, 2006 at 09:00 AM

del.icio.us/dossy (RSS) links since August 28, 2006 at 09:00 AM: