Becoming a JavaScript Programmer

The more I played with JavaScript, the more I found that it would allow me to do. A lot of my previous web designs relied on manual coding, since I wasn't able to automatically assume JavaScript would be available. Having raised the bar for this site, I found all sorts of ways to avoid repetitive coding.

JavaScript is all over the place here. In the journal text, it's used for generating page titles, showing the numbers that signify how many "chunks" are in each day and which one is currently being displayed, setting the optimal horizontal size for the page, adding the links to restore the frameset or move on to the next chunk or day, and actually restoring the contents of the frameset to the same place. Elsewhere, it loads a day chosen from the drop-down menu of days, automatically loads the thumbnails for that day, and determines whether the enlarged photos are displayed in the main journal frame or in a separate window. Preceding all of that, JavaScript kicks in from the very beginning to determine whether the reader is using a browser capable of displaying the site (at least, as far as I can tell), and to offer the alternative (text-only) via <noframes> and <noscript> tags if not. It also draws the frameset itself, allowing me to manipulate it according to the user's taste.

It was that ability to cater to multiple tastes that made me take advantage of more display-oriented features. For example, I liked having the thumbnails displayed across the bottom of the screen (something about a horizontally-scrolling frame for that purpose seems kinda hip to me), but Erin preferred it to be along the right side. Since the frameset was built dynamically, all it took was switching a couple of lines, and adding a pair of <nobr> tags to the horizontal one. I couldn't decide for myself whether I liked having the photos enlarged in the main frame, or in a separate window - the latter making it much easier to read and view at the same time. Again, the only real difference was the target setting for the link, so I gave the user a choice.

Prior to this undertaking, I don't think I'd ever written more than about six lines of JavaScript, since most tricks could be performed by reusable code, found in one of the many open-source JavaScript repositories on the 'net. But by the time I was done here, I had produced over 300 lines of JavaScript. While that's not really a lot by any coder's standard, it was so custom-tailored for my site that none of it came from reusable or publicly-available code. As a result, I learned far more about JavaScript than I ever could have through mere cutting-and-pasting.

(continued)

Copyright © 2000
Last updated: 12 Jan 2000 14:49:33