Number formatting function for download counter

refs #5652

- safari doesn't support the nice toLocaleString function
- this adds a manual, cross-browser way of adding commas in the right places to long number strings
This commit is contained in:
Hannah Wolfe 2015-08-25 14:48:02 +01:00
parent eb1365c4f0
commit 36e0a6b74c

View File

@ -27,7 +27,14 @@ var DownloadCountPoller = Ember.Object.extend({
var self = this;
ajax(this.get('url')).then(function (data) {
self.set('count', data.count.toLocaleString());
var count = data.count.toString(),
pattern = /(-?\d+)(\d{3})/;
while (pattern.test(count)) {
count = count.replace(pattern, '$1,$2');
}
self.set('count', count);
}).catch(function () {
self.set('count', 'many, many');
});