Commit 9963cb28 authored by wildfirecode13's avatar wildfirecode13

1

parent 4d20b0ad
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div id="root"></div>
<script src="teddi.umd.js"></script>
<script>
const timer = new teddi.Countdown( 86400 * 2 +3600*1 + 60*1 +1, 'ddhhmmss',1000);
timer.on('update', (data) => {
const {dd,hh,mm,ss} = data;
document.getElementById('root').innerHTML = `${dd}:${hh}:${mm}:${ss}`;
// document.getElementById('root').innerHTML = `${hh}:${mm}:${ss}`;
// document.getElementById('root').innerHTML = `${mm}:${ss}`;
}, this);
timer.start();
</script>
</body>
</html>
\ No newline at end of file
......@@ -393,46 +393,66 @@
}
var Countdown = /** @class */ (function (_super) {
tslib_1.__extends(Countdown, _super);
function Countdown(text, seconds, format, delay) {
function Countdown(repeatCount, format, delay) {
var _this = _super.call(this) || this;
_this._running = false;
_this._text = text;
_this._seconds = seconds;
_this._repeatCount = repeatCount;
_this._format = format;
_this._counter = 0;
_this._delay = delay || 1000;
return _this;
}
Countdown.prototype.getCountdown = function () {
if (this._format == "ddhhmmss")
return this.getDDHHMMSS();
if (this._format == "hhmmss")
return this.getHHMMSS();
if (this._format == "mmss")
return this.getMMSS();
};
Countdown.prototype.getDDHHMMSS = function () {
var left = this._repeatCount - this._counter;
var days = Math.floor(left / 86400);
var dayMod = left % 86400;
var hours = Math.floor(dayMod / 3600);
var hoursMod = dayMod % 3600;
var minutes = Math.floor(hoursMod / 60);
var seconds = hoursMod % 60;
return {
dd: getTimeNum(days),
hh: getTimeNum(hours),
mm: getTimeNum(minutes),
ss: getTimeNum(seconds)
};
};
Countdown.prototype.getHHMMSS = function () {
var left = this._seconds - this._counter;
var left = this._repeatCount - this._counter;
var hours = Math.floor(left / 3600);
var minutes = Math.floor((left % 3600) / 60);
var seconds = left - hours * 3600 - minutes * 60;
return getTimeNum(hours) + ":" + getTimeNum(minutes) + ":" + getTimeNum(seconds);
return {
hh: getTimeNum(hours),
mm: getTimeNum(minutes),
ss: getTimeNum(seconds)
};
};
Countdown.prototype.getMMSS = function () {
var left = this._seconds - this._counter;
var left = this._repeatCount - this._counter;
var minutes = Math.floor(left / 60);
var seconds = left % 60;
return getTimeNum(minutes) + ":" + getTimeNum(seconds);
};
Countdown.prototype.getText = function () {
return this._text.replace("{0}", this.getCountdown());
return {
mm: getTimeNum(minutes),
ss: getTimeNum(seconds)
};
};
Countdown.prototype.start = function () {
var _this = this;
this._running = true;
this.emit("update", this.getText());
this.emit("update", this.getCountdown());
this._timer = setInterval(function () {
_this._counter++;
_this.emit("update", _this.getText());
if (_this._counter == _this._seconds) {
_this.emit("update", _this.getCountdown());
if (_this._counter == _this._repeatCount) {
_this.stop();
}
}, this._delay);
......@@ -445,7 +465,7 @@
Countdown.prototype.reset = function ($seconds) {
clearInterval(this._timer);
this._counter = 0;
this._seconds = $seconds;
this._repeatCount = $seconds;
};
Object.defineProperty(Countdown.prototype, "running", {
// set seconds(val: number) {
......
import { EventEmitter } from "../event";
export declare class Countdown extends EventEmitter<any> {
private _timer;
private _text;
private _seconds;
private _repeatCount;
private _format;
private _counter;
private _delay;
private _running;
constructor(text: any, seconds: any, format: any, delay: any);
constructor(repeatCount: any, format: any, delay: any);
private getCountdown;
private getDDHHMMSS;
private getHHMMSS;
private getMMSS;
private getText;
start(): void;
private stop;
reset($seconds: number): void;
......
......@@ -20,46 +20,66 @@ function getTimeNum(n) {
}
var Countdown = /** @class */ (function (_super) {
__extends(Countdown, _super);
function Countdown(text, seconds, format, delay) {
function Countdown(repeatCount, format, delay) {
var _this = _super.call(this) || this;
_this._running = false;
_this._text = text;
_this._seconds = seconds;
_this._repeatCount = repeatCount;
_this._format = format;
_this._counter = 0;
_this._delay = delay || 1000;
return _this;
}
Countdown.prototype.getCountdown = function () {
if (this._format == "ddhhmmss")
return this.getDDHHMMSS();
if (this._format == "hhmmss")
return this.getHHMMSS();
if (this._format == "mmss")
return this.getMMSS();
};
Countdown.prototype.getDDHHMMSS = function () {
var left = this._repeatCount - this._counter;
var days = Math.floor(left / 86400);
var dayMod = left % 86400;
var hours = Math.floor(dayMod / 3600);
var hoursMod = dayMod % 3600;
var minutes = Math.floor(hoursMod / 60);
var seconds = hoursMod % 60;
return {
dd: getTimeNum(days),
hh: getTimeNum(hours),
mm: getTimeNum(minutes),
ss: getTimeNum(seconds)
};
};
Countdown.prototype.getHHMMSS = function () {
var left = this._seconds - this._counter;
var left = this._repeatCount - this._counter;
var hours = Math.floor(left / 3600);
var minutes = Math.floor((left % 3600) / 60);
var seconds = left - hours * 3600 - minutes * 60;
return getTimeNum(hours) + ":" + getTimeNum(minutes) + ":" + getTimeNum(seconds);
return {
hh: getTimeNum(hours),
mm: getTimeNum(minutes),
ss: getTimeNum(seconds)
};
};
Countdown.prototype.getMMSS = function () {
var left = this._seconds - this._counter;
var left = this._repeatCount - this._counter;
var minutes = Math.floor(left / 60);
var seconds = left % 60;
return getTimeNum(minutes) + ":" + getTimeNum(seconds);
};
Countdown.prototype.getText = function () {
return this._text.replace("{0}", this.getCountdown());
return {
mm: getTimeNum(minutes),
ss: getTimeNum(seconds)
};
};
Countdown.prototype.start = function () {
var _this = this;
this._running = true;
this.emit("update", this.getText());
this.emit("update", this.getCountdown());
this._timer = setInterval(function () {
_this._counter++;
_this.emit("update", _this.getText());
if (_this._counter == _this._seconds) {
_this.emit("update", _this.getCountdown());
if (_this._counter == _this._repeatCount) {
_this.stop();
}
}, this._delay);
......@@ -72,7 +92,7 @@ var Countdown = /** @class */ (function (_super) {
Countdown.prototype.reset = function ($seconds) {
clearInterval(this._timer);
this._counter = 0;
this._seconds = $seconds;
this._repeatCount = $seconds;
};
Object.defineProperty(Countdown.prototype, "running", {
// set seconds(val: number) {
......
......@@ -6,52 +6,70 @@ function getTimeNum(n: any) {
export class Countdown extends EventEmitter<any> {
private _timer: any;
private _text: any;
private _seconds: any;
private _repeatCount: any;
private _format: any;
private _counter: any;
private _delay: any;
private _running = false;
constructor(text: any, seconds: any, format: any, delay: any) {
constructor(repeatCount: any, format: any, delay: any) {
super();
this._text = text;
this._seconds = seconds;
this._repeatCount = repeatCount;
this._format = format;
this._counter = 0;
this._delay = delay || 1000;
}
private getCountdown() {
if (this._format == "ddhhmmss") return this.getDDHHMMSS();
if (this._format == "hhmmss") return this.getHHMMSS();
if (this._format == "mmss") return this.getMMSS();
}
private getDDHHMMSS() {
const left = this._repeatCount - this._counter;
const days = Math.floor(left / 86400);
const dayMod = left % 86400;
const hours = Math.floor(dayMod / 3600);
const hoursMod = dayMod % 3600;
const minutes = Math.floor(hoursMod / 60);
const seconds = hoursMod % 60;
return {
dd: getTimeNum(days),
hh: getTimeNum(hours),
mm: getTimeNum(minutes),
ss: getTimeNum(seconds)
}
}
private getHHMMSS() {
const left = this._seconds - this._counter;
const left = this._repeatCount - this._counter;
const hours = Math.floor(left / 3600);
const minutes = Math.floor((left % 3600) / 60);
const seconds = left - hours * 3600 - minutes * 60;
return `${getTimeNum(hours)}:${getTimeNum(minutes)}:${getTimeNum(seconds)}`;
return {
hh: getTimeNum(hours),
mm: getTimeNum(minutes),
ss: getTimeNum(seconds)
}
}
private getMMSS() {
const left = this._seconds - this._counter;
const left = this._repeatCount - this._counter;
const minutes = Math.floor(left / 60);
const seconds = left % 60;
return `${getTimeNum(minutes)}:${getTimeNum(seconds)}`;
}
private getText() {
return this._text.replace("{0}", this.getCountdown());
return {
mm: getTimeNum(minutes),
ss: getTimeNum(seconds)
}
}
start() {
this._running = true;
this.emit("update", this.getText());
this.emit("update", this.getCountdown());
this._timer = setInterval(() => {
this._counter++;
this.emit("update", this.getText());
if (this._counter == this._seconds) {
this.emit("update", this.getCountdown());
if (this._counter == this._repeatCount) {
this.stop();
}
}, this._delay);
......@@ -66,7 +84,7 @@ export class Countdown extends EventEmitter<any> {
reset($seconds: number) {
clearInterval(this._timer);
this._counter = 0;
this._seconds = $seconds;
this._repeatCount = $seconds;
}
// set seconds(val: number) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment