Rob Larsen

Archive for the 'tips-and-tricks' Category

Two Columns of Variable But Equal Height Using Simple CSS and a Couple of DIVs

If, like me, you cut your web development teeth during while CSS was still in its infancy, you likely put together a lot of sites that featured two (or more) columns decorated with bgcolors or background images that flowed together in lockstep, always retaining equivalent height. It was pretty standard and basically came along free with tables for layout.

Then? Along came CSS, the separation of style and content (don't forget behavior!) and the two columns living in perfect harmony became a casualty of the war against crufty code.

Which brings us to this post. (more…)

I just realized- JavaScript is my Perl

Twice this morning I did massive, repetitive, string manipulations with JavaScript.

One took a list of files, turned it into an array and then looped through creating .htaccess entries.

The other took an HTML table output by Excel and turned it into a Definition List. I then used FireBug to copy the innerHTML of the body and pasted it into a new document, ready to be manipulated in the application I'm building (with JavaScript of course :) ) If you're curious, here's the code for that one:

<script type="text/javascript">
window.onload = function() {
    var trs = document.getElementsByTagName("TR");
    var newString ="<dl>";

    for (i=0;i<trs.length;i++){
        var tds=trs[i].getElementsByTagName("TD");
        newString +="<dt id='"+tds[1].innerHTML+"'>"+tds[4].innerHTML+"</dt>";
        newString +="<dd>"+tds[5].innerHTML+"</dd>";
    }
    newString +="</dl>"
    document.body.innerHTML=newString;
    }
</script>

Anyway, I've done this sort of thing before and I realized that I'm using JavaScript for the sort of administrative scripting that other people would use Perl or Python for.

No, there's nothing more to this post than that.

:)

I just wanted to point it out since it struck me as interesting.

Does anyone else out there use JS for this sort of thing?

Or am I a complete weirdo?

Now Serving: Freshly Compressed Javascript

I finally got around to compressing this site's JavaScript file last night. I used /packer/ because I know that it supports conditional compilation. I'm a fan of conditional compilation.

It was funny because there were a couple of lines missing semi-colons that I must have looked at a thousand times before last night and just never noticed that they were nekkid like that. JSLint helped me out a lot with making sure the file was ready for packing.

Anyway, between gzipping and compressing it my JS file screams out to the browser at a tidy 2.67 KB (down from an unadulterated 9.41 KB.) There are probably functions in some libraries larger than that…

Go small or go home!

JSON Feeds For Fun and Profit Part 3- wherein Eval() kind of bums me out

(and several months later I finish my little JSON series…)

So far my exploration of JSON has been a fun-filled walk in the park. Moonbeams and rainbows. All that.

This last post on the subject is slightly less cool as I get into one of the least attractive components of the whole JSON thing- the use of eval() to transform a text response into a proper JavaScript object. The use of eval() is one of the reasons I originally was a little shy about using JSON. Why? eval() is slow and I try to stay away from slow if at all possible. That and the idea of eval()-ing code from some third party makes me wary.
(more…)

Belt and Suspenders- Flash Embed With SWFObject and Conditional Comments

If you're using Flash and you want the best possible coverage (meaning it works with users who don't have JS turned on) while still using something like SWFObject where possible to get around the "click here to activate and use this control" ActiveX message in Internet Explorer, then take a look at the ridiculous pattern below.

Warning- not for the squeamish…
(more…)