IonDen / ion.rangeSlider

jQuery only range slider
http://ionden.com/a/plugins/ion.rangeSlider/en.html
MIT License
2.55k stars 505 forks source link

Callback for outputting readable value of slider #79

Closed titpetric closed 9 years ago

titpetric commented 10 years ago

I'm looking to make a slider which will be time based. I want to use time stamps (seconds, milliseconds) as the sliding values. The output doesn't fit the current conventions however. A callback which would convert the raw integer/float value to a readable output would be needed.

For example: Slider from 0 to 3600, want to print MM:SS values for this (01:12-45:30, 00:00 - 59:59). Slider from 1388530800 to 1391209200 (January 1st 2014 - February 1st 2014).

A callback would be needed for this. I'm not familiar enough with the plugin to suggest a "valid" way or name how to pass this callback to it however. Maybe "toReadable" : function(value) ...

Best, Tit

titpetric commented 10 years ago

Reading the code a bit, the change with the least impact would be to pass a function as the value of 'prettify', and then override the internal prettify callback, which is already used everywhere.

if (typeof settings.prettify === "function") {
        prettify = settings.prettify;
}

This would go somewhere around js/ion.rangeSlider.js#L306, I just tested it myself. If you want I can fork and push back the changes, if this way is good with you?

Best, Tit

IonDen commented 10 years ago

Hi, it is very good idea, but it will need much tests, so maybe in 2.0

titpetric commented 10 years ago

^^ so far it's been working for me.

image

prettify: function(val) {
        return moment().startOf('year').seconds(val).format("H:mm:ss.SS");
},
IonDen commented 10 years ago

Of course, but it is your patch))

gadlol commented 10 years ago

This should be included in 2.0 , after applying:

if (typeof settings.prettify === "function") {
        prettify = settings.prettify;
}

I could make it look like this:

screenshot from 2014-05-07 15 49 42

IonDen commented 10 years ago

I think i will include this.

IonDen commented 9 years ago

Hi, in 2.0 you can replace prettify function and work with dates.