Implement an alarm callback for countdown widget

This commit is contained in:
Hadi Nategh 2020-12-02 16:54:50 +01:00
parent 5d6965a2e9
commit d957ed41d0
2 changed files with 32 additions and 1 deletions

View File

@ -84,6 +84,9 @@ var et2_countdown = /** @class */ (function (_super) {
var distance = time.getTime() - now.getTime();
if (distance < 0)
return 0;
if (this.options.alarm > 0 && this.options.alarm == distance / 1000 && typeof this.onAlarm == 'function') {
this.onAlarm();
}
var values = {
days: Math.floor(distance / (1000 * 60 * 60 * 24)),
hours: Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)),
@ -136,6 +139,18 @@ var et2_countdown = /** @class */ (function (_super) {
type: "string",
default: true,
description: "Only displays none empty values."
},
alarm: {
name: "alarm",
type: "any",
default: "",
description: "Defines an alarm set before the countdown is finished, it should be in seconds"
},
onAlarm: {
name: "alarm callback",
type: "js",
default: "",
description: "Defines a callback to gets called at alarm - timer. This only will work if there's an alarm set."
}
};
return et2_countdown;

View File

@ -47,7 +47,20 @@ export class et2_countdown extends et2_baseWidget {
type: "string",
default: true,
description: "Only displays none empty values."
},
alarm: {
name: "alarm",
type: "any",
default: "",
description: "Defines an alarm set before the countdown is finished, it should be in seconds"
},
onAlarm: {
name: "alarm callback",
type: "js",
default: "",
description: "Defines a callback to gets called at alarm - timer. This only will work if there's an alarm set."
}
};
private time : et2_date;
@ -113,7 +126,10 @@ export class et2_countdown extends et2_baseWidget {
let distance = time.getTime() - now.getTime();
if (distance < 0) return 0;
if (this.options.alarm > 0 && this.options.alarm == distance/1000 && typeof this.onAlarm == 'function')
{
this.onAlarm();
}
let values = {
days: Math.floor(distance / (1000 * 60 * 60 * 24)),
hours: Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)),