diff --git a/static/js/filters/filters.js b/static/js/filters/filters.js index b5f7a29e..24c1be30 100644 --- a/static/js/filters/filters.js +++ b/static/js/filters/filters.js @@ -25,14 +25,16 @@ define([ 'filters/buddyimagesrc', 'filters/displayconference', 'filters/displayuserid', - 'filters/displaynameforsession'], function(_, displayName, buddyImageSrc, displayConference, displayUserid, displayNameForSession) { + 'filters/displaynameforsession', + 'filters/formatbase1000'], function(_, displayName, buddyImageSrc, displayConference, displayUserid, displayNameForSession, formatBase1000) { var filters = { displayName: displayName, buddyImageSrc: buddyImageSrc, displayConference: displayConference, displayUserid: displayUserid, - displayNameForSession: displayNameForSession + displayNameForSession: displayNameForSession, + formatBase1000: formatBase1000 }; var initialize = function(angModule) { diff --git a/static/js/filters/formatbase1000.js b/static/js/filters/formatbase1000.js new file mode 100644 index 00000000..5623f4fd --- /dev/null +++ b/static/js/filters/formatbase1000.js @@ -0,0 +1,66 @@ +/* + * Spreed WebRTC. + * Copyright (C) 2013-2014 struktur AG + * + * This file is part of Spreed WebRTC. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ +define([], function() { + + // formatBase1000 + /* Purpose: format number/unit appropriately. + Appends k+base-unit, base-unit, c+base-unit, m+base-unit to value depending input. + when Number >= 1 and !base-unit: no decimal is used + when Number < 1: 2 places decimal accuracy + Using: Number | formatBase1000[:'base-unit'] + */ + return [function() { + var defaultPrecisionBaseAndOver = 0; + var defaultPrecisionUnderBase = 2; + return function(num, unit) { + num = Number(num); + var getNumber = function(precision) { + var dot = num.toString().search(/\./); + if (dot === -1) { + precision += num.toString().length; + } else { + precision += dot; + } + return num.toPrecision(precision); + }; + if (!unit) { + return getNumber(defaultPrecisionBaseAndOver); + } + // killo + if (num >= 1000) { + num /= 1000; + return getNumber(defaultPrecisionBaseAndOver) + 'k' + unit; + // centi + } else if (num < 1 && num >= 0.01) { + num *= 100; + return getNumber(defaultPrecisionUnderBase) + 'c' + unit; + // milli + } else if (num < 0.01) { + num *= 1000; + return getNumber(defaultPrecisionUnderBase) + 'm' + unit; + // base + } else { + return getNumber(defaultPrecisionBaseAndOver) + unit; + } + }; + }]; + +}); diff --git a/static/partials/geolocation.html b/static/partials/geolocation.html index f712ff9d..ec1334a1 100644 --- a/static/partials/geolocation.html +++ b/static/partials/geolocation.html @@ -1,3 +1,3 @@
-
{{info.latitude|number:6}}º {{info.longitude|number:6}}º ±{{info.accuracy|number:0}}m
-
\ No newline at end of file +
{{info.latitude|number:6}}º {{info.longitude|number:6}}º ±{{info.accuracy|formatBase1000:'m'}}
+