new precision option to limit number of counters shown

This commit is contained in:
Ralf Becker 2021-01-29 20:34:28 +02:00
parent bb5157d338
commit 2af199f725
2 changed files with 45 additions and 0 deletions

View File

@ -112,6 +112,20 @@ var et2_countdown = /** @class */ (function (_super) {
}
}
}
if (this.options.precision) {
var units = ['days', 'hours', 'minutes', 'seconds'];
for (var u = 0; u < 4; ++u) {
if (values[units[u]]) {
for (var n = u + this.options.precision; n < 4; n++) {
this[units[n]].hide();
}
break;
}
else {
this[units[u]].hide();
}
}
}
return distance;
};
et2_countdown.prototype._getIndicator = function (_v) {
@ -136,6 +150,12 @@ var et2_countdown = /** @class */ (function (_super) {
default: true,
description: "Only displays none empty values."
},
precision: {
name: "how many counters to show",
type: "integer",
default: 0,
description: "Limit number of counters, eg. 2 does not show minutes and seconds, if days are displayed"
},
alarm: {
name: "alarm",
type: "any",

View File

@ -47,6 +47,12 @@ export class et2_countdown extends et2_valueWidget {
default: true,
description: "Only displays none empty values."
},
precision: {
name: "how many counters to show",
type: "integer",
default: 0, // =all
description: "Limit number of counters, eg. 2 does not show minutes and seconds, if days are displayed"
},
alarm: {
name: "alarm",
type: "any",
@ -146,6 +152,25 @@ export class et2_countdown extends et2_valueWidget {
}
}
}
if (this.options.precision)
{
const units = ['days','hours','minutes','seconds'];
for (let u=0; u < 4; ++u)
{
if (values[units[u]])
{
for(let n=u+this.options.precision; n < 4; n++)
{
this[units[n]].hide();
}
break;
}
else
{
this[units[u]].hide();
}
}
}
return distance;
}