loopj / jquery-simple-slider

Unobtrusive numerical slider plugin for jQuery
194 stars 113 forks source link

Precision for output and integral tooltips for display #17

Open mkoistinen opened 11 years ago

mkoistinen commented 11 years ago

Firstly, I'm surprised this slider isn't more popular. I needed a cross-platform-capable slider for my project and looked all over. It seems my choices were: JQuery-UI (which I think is a bit heavy for a simple slider), an HTML polyfill (there are ZERO that actually work across all platforms that I could find, besides, not all projects use HTML5) or roll my own. This project is simple enough that it provided 90% of what I needed, thank you!

I see there are some pending touch-support commits, I would love to see these merged soon.

Anyway, these commits work together. First is just a removal of trailing whitespace (a pet-peeve of mine). Second is the addition of precision control for output values IF a step is defined. So, if your step is 0.01, the output will be fixed to 2 decimal places. It seems silly that this would be required, but thanks to the fuzziness of floating point numbers, it is. If no step is defined, the output is as it was: not fixed.

Finally, I've added support for an integral tooltip-style display of the output (which is one reason why the output precision was required).

mkoistinen commented 11 years ago

Oh, just to mention, to add the tooltip, just add tooltip: true to the settings object, or, use the attribute 'data-slider-tooltip=true' in the initial input as per the other options.