IonDen / ion.rangeSlider

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

Deprecating unnecessary currency formatting #460

Open valtido opened 7 years ago

valtido commented 7 years ago

I was wondering if it would be ok to remove some functionality (deprecating) and then use the following as pretty printing using native locale support.

in the prettify function on this file, we should replace: https://github.com/IonDen/ion.rangeSlider/blob/master/js/ion.rangeSlider.js#L1860,L1863

prettify: function (num) {
    var n = num.toString();
    return n.replace(/(\d{1,3}(?=(?:\d\d\d)+(?!\d)))/g, "$1" + this.options.prettify_separator);
},

with the following:

prettify : function(number){
    return new Number(number).toLocaleString(this.options.locale.lang, this.options.locale);
}

then we can use proper locale from the init call.

jQuery(".rangeSlider")
.ionRangeSlider({
   ...
   locale : {
        lang : "en-GB",
        style : "currency",
        minimumFractionDigits : 2, //decimal points 
        currency : "GBP"
    }
    ...
})

Using the following as a reference to use more functions https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString#Examples

I could push a pull request if you are happy with this.

This would mean that the following would render useless :) and code clean up / refactoring is required.

IonDen commented 7 years ago

Hi, the idea is great. I will think about it. The only one problem here - browser support.

Slider supports IE8+. toLocaleString is supported only by IE11+.

I will think about adding this feature to 3.x as an option.

valtido commented 7 years ago

A quick google search for a pollyfill, as a fallback https://github.com/willsp/polyfill-Number.toLocaleString-with-Locales just as an option :)