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..181fbe16
--- /dev/null
+++ b/static/js/filters/formatbase1000.js
@@ -0,0 +1,86 @@
+/*
+ * 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 on input.
+ Decimal accuracy is taken care of automatically but override is avaible.
+ Using: Number | formatBase1000[:'base-unit'][:'desired-precision']
+ */
+ return [function() {
+ var defaultPrecisionUnder1 = 2;
+ var defaultPrecisionFrom1AndUnder10 = 2;
+ var defaultPrecisionFrom10AndUnder100 = 1;
+ var defaultPrecisionFrom100AndOver = 0;
+ return function(num, unit, precision) {
+ num = Number(num);
+ precision = Number(precision);
+ var getNumber = function(precision) {
+ var dot = num.toString().search(/\./);
+ if (dot === -1) {
+ precision += num.toString().length;
+ } else {
+ precision += dot;
+ }
+ // toPrecision supports range 1 - 21
+ if (precision > 21) {
+ precision = 21;
+ }
+ return num.toPrecision(precision);
+ };
+ var getPrecision = function() {
+ if (!isNaN(precision)) {
+ return precision;
+ }
+ if (num >= 100) {
+ return defaultPrecisionFrom100AndOver;
+ } else if (num < 100 && num >= 10) {
+ return defaultPrecisionFrom10AndUnder100;
+ } else if (num < 10 && num >= 1){
+ return defaultPrecisionFrom1AndUnder10;
+ } else {
+ return defaultPrecisionUnder1;
+ }
+ };
+ if (!unit) {
+ return getNumber(getPrecision());
+ }
+ // kilo
+ if (num >= 1000) {
+ num /= 1000;
+ return getNumber(getPrecision()) + 'k' + unit;
+ // centi
+ } else if (num < 1 && num >= 0.01) {
+ num *= 100;
+ return getNumber(getPrecision()) + 'c' + unit;
+ // milli
+ } else if (num < 0.01) {
+ num *= 1000;
+ return getNumber(getPrecision()) + 'm' + unit;
+ // base
+ } else {
+ return getNumber(getPrecision()) + 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 @@
\ No newline at end of file
+
+