Implemented a javascript code style

This commit is contained in:
Stefan Zermatten
2015-04-22 12:44:25 +02:00
parent dce20375b5
commit fada0f5136
113 changed files with 1614 additions and 1650 deletions

View File

@@ -1,21 +1,27 @@
Template.registerHelper("valueString", function(value){
Template.registerHelper("valueString", function(value) {
var resultArray = [];
//sp
var gp = Math.floor(value);
if(gp > 0) resultArray.push(gp + "gp");
if (gp > 0) {
resultArray.push(gp + "gp");
}
//sp
var sp = Math.floor(10 * (value % 1));
if(sp > 0) resultArray.push(sp + "sp");
if (sp > 0) {
resultArray.push(sp + "sp");
}
//cp
var cp = 10 * ((value * 10) % 1);
cp = Math.round(cp * 1000) / 1000;
if(cp > 0) resultArray.push(cp + "cp");
if (cp > 0) {
resultArray.push(cp + "cp");
}
//build string with correct spacing
var result = "";
for(var i = 0; i < resultArray.length; i++){
for (var i = 0; i < resultArray.length; i++) {
//add a space between values
if(i !== 0){
if (i !== 0) {
result += " ";
}
result += resultArray[i];
@@ -23,24 +29,30 @@ Template.registerHelper("valueString", function(value){
return result;
});
Template.registerHelper("longValueString", function(value){
Template.registerHelper("longValueString", function(value) {
var resultArray = [];
//sp
var gp = Math.floor(value);
if(gp > 0) resultArray.push(gp + "gp");
if (gp > 0) {
resultArray.push(gp + "gp");
}
//sp
var sp = Math.floor(10 * (value % 1));
if(sp > 0 || resultArray.length) resultArray.push(sp + "sp");
if (sp > 0 || resultArray.length) {
resultArray.push(sp + "sp");
}
//cp
var cp = 10 * ((value * 10) % 1);
cp = Math.round(cp * 1000) / 1000;
if(cp > 0 || resultArray.length) resultArray.push(cp + "cp");
if (cp > 0 || resultArray.length) {
resultArray.push(cp + "cp");
}
//build string with correct spacing
var result = "";
for(var i = 0; i < resultArray.length; i++){
for (var i = 0; i < resultArray.length; i++) {
//add a space between values
if(i !== 0){
if (i !== 0) {
result += " ";
}
result += resultArray[i];