jesucarr/jOdometer — pull request #2 by tig (2012-07-08 16:34:47+00:00)
Title: Added maxDigits support

Hi,

I added maxDigits support.

In order to read and understand your code, I ended up doing a bit of code formatting (consistent spaces instead of tabs, etc...). This, unfortunately, is probably going to make it harder for you to see what I actually changed. I hope this is not too painful for you :-). The key to what I did was

1) added `maxDigits` as a settings.
2) In the init code where you previously looped on integers.length, i now loop on `maxDigits` if it is not `0`. Line 94.
3) In `setNumbers` i also changed it to loop on `maxDigits` if it is not `0`. Line 113
4) in both cases I used the fact that `j` will go negative within the loop if `i > .length` to discern when we are on an "unused" digit.
5) "unusued" digits are hidden (`display:none;`) on line 116 until they have a value. See `$('.jodometer_integer_' + i, scope).show();` in `setNumbers`. on line 186.
6) To make the "appearing" digit look natural, I changed the `img` tag for "unused" digits to default to '0' when created (see line 119).

I also updated the sample with `counter7` that uses a larger png with transparency and a background image to illustrate how to make that work. You'll note that the numbers in this new png don't actually line up vertically...that is intentional to make it look a bit like a real mechanical odometer.

Hope you like it!