Short-Sighted Programming

×

This post was originally published in 2008
It may contain stale & outdated information. Or it may have grown more awesome with age, like the author.

Today a customer informed me that Slider wasn’t working properly on his webpage. They gave me the URL to the problem page, and for a page with a working (properly) version of Slider.

Initially I was perplexed, but it dawned on me that the code for parsing out the cell numbers can only parse single-digit numbers.

A classic case of short-sighted programming.

See the cells’ class attribute was put together like this:

cell + the cell’s number + unique ID.

Examples:

cell2page0

cell9page102

cell10page0

Code for parsing out the cell’s number:

1
parseInt(jQuery(peeker).attr("class").substring(4,5))

Notice that it only gets one character.

To work correctly, two things needed to be changed.

First, I had to change the way the cells’ class attribute is put together:

cell + unique ID + the cell’s number

Second, the javascript for parsing out the number:

1
parseInt(jQuery(peeker).attr("class").substring(("cell" + length of cell + unique ID),(length of class attribute)))

The updated plugin is available here: Slider 0.95b

I’m confident that I’ve fixed the problem, but if I haven’t don’t hesitate to let me know!

Incidentally, the customer’s website is extremely well done, go and check it out!

John Charlton Webdesign

No comments | Trackback