Tuesday, February 8, 2011

Encountering the Whitespace Incident

Last week, I encountered an interesting issue while coding something at work.

Essentially, there's some JavaScript hard-coded on one page that's triggered with the page content handled with the CMS. What that piece of code does is essentially running through an inline list of years and changing the CSS code of the links inside the list items (and tables below) depending on what was done using a for loop (from start_year to end_year). You can see this here.

Originally, the start and end values for the loop were hard-coded as constants. This worked well until I had to add 2011 to the list. The list is part of the page content, which can be modified with the CMS, but the JavaScript is not. Changing the constant every year is simply not practical.

I decided to make the JavaScript smarter.