72 lines
1.3 KiB
JavaScript
72 lines
1.3 KiB
JavaScript
|
String.prototype.capitalize = function() {
|
||
|
return this
|
||
|
.toLowerCase()
|
||
|
.replace(
|
||
|
/(^|\s)([a-z])/g,
|
||
|
function(m,p1,p2) { return p1+p2.toUpperCase(); }
|
||
|
);
|
||
|
}
|
||
|
|
||
|
angular.module("FICApp")
|
||
|
.filter("capitalize", function() {
|
||
|
return function(input) {
|
||
|
return input.capitalize();
|
||
|
}
|
||
|
})
|
||
|
.filter("rankTitle", function() {
|
||
|
var itms = {
|
||
|
"rank": "Rang",
|
||
|
"name": "Équipe",
|
||
|
"score": "Score",
|
||
|
};
|
||
|
return function(input) {
|
||
|
if (itms[input] != undefined) {
|
||
|
return itms[input];
|
||
|
} else {
|
||
|
return input;
|
||
|
}
|
||
|
}
|
||
|
})
|
||
|
.filter("time", function() {
|
||
|
return function(input) {
|
||
|
if (input == undefined) {
|
||
|
return "--";
|
||
|
} else if (input >= 10) {
|
||
|
return input;
|
||
|
} else {
|
||
|
return "0" + input;
|
||
|
}
|
||
|
}
|
||
|
})
|
||
|
.filter("since", function() {
|
||
|
return function(passed) {
|
||
|
if (passed < 120000) {
|
||
|
return "Il y a " + Math.floor(passed/1000) + " secondes";
|
||
|
} else {
|
||
|
return "Il y a " + Math.floor(passed/60000) + " minutes";
|
||
|
}
|
||
|
}
|
||
|
})
|
||
|
.filter("size", function() {
|
||
|
var units = [
|
||
|
"o",
|
||
|
"kio",
|
||
|
"Mio",
|
||
|
"Gio",
|
||
|
"Tio",
|
||
|
"Pio",
|
||
|
"Eio",
|
||
|
"Zio",
|
||
|
"Yio",
|
||
|
]
|
||
|
return function(input) {
|
||
|
var res = input;
|
||
|
var unit = 0;
|
||
|
while (res > 1024) {
|
||
|
unit += 1;
|
||
|
res = res / 1024;
|
||
|
}
|
||
|
return (Math.round(res * 100) / 100) + " " + units[unit];
|
||
|
}
|
||
|
})
|