Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
teddi
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
wildfirecode13
teddi
Commits
9963cb28
Commit
9963cb28
authored
Dec 09, 2020
by
wildfirecode13
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1
parent
4d20b0ad
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
118 additions
and
51 deletions
+118
-51
index.html
dist/index.html
+12
-2
teddi.umd.js
dist/teddi.umd.js
+34
-14
Countdown.d.ts
dist/time/Countdown.d.ts
+3
-4
Countdown.js
dist/time/Countdown.js
+34
-14
countdown.ts
src/time/countdown.ts
+35
-17
No files found.
dist/index.html
View file @
9963cb28
<!DOCTYPE html>
<!DOCTYPE html>
<html
lang=
"en"
>
<html
lang=
"en"
>
<head>
<head>
<meta
charset=
"UTF-8"
>
<meta
charset=
"UTF-8"
>
<meta
name=
"viewport"
content=
"width=device-width, initial-scale=1.0"
>
<meta
name=
"viewport"
content=
"width=device-width, initial-scale=1.0"
>
<title>
Document
</title>
<title>
Document
</title>
</head>
</head>
<body>
<body>
<div
id=
"root"
></div>
<script
src=
"teddi.umd.js"
></script>
<script
src=
"teddi.umd.js"
></script>
<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>
</script>
</body>
</body>
</html>
</html>
\ No newline at end of file
dist/teddi.umd.js
View file @
9963cb28
...
@@ -393,46 +393,66 @@
...
@@ -393,46 +393,66 @@
}
}
var
Countdown
=
/** @class */
(
function
(
_super
)
{
var
Countdown
=
/** @class */
(
function
(
_super
)
{
tslib_1
.
__extends
(
Countdown
,
_super
);
tslib_1
.
__extends
(
Countdown
,
_super
);
function
Countdown
(
text
,
seconds
,
format
,
delay
)
{
function
Countdown
(
repeatCount
,
format
,
delay
)
{
var
_this
=
_super
.
call
(
this
)
||
this
;
var
_this
=
_super
.
call
(
this
)
||
this
;
_this
.
_running
=
false
;
_this
.
_running
=
false
;
_this
.
_text
=
text
;
_this
.
_repeatCount
=
repeatCount
;
_this
.
_seconds
=
seconds
;
_this
.
_format
=
format
;
_this
.
_format
=
format
;
_this
.
_counter
=
0
;
_this
.
_counter
=
0
;
_this
.
_delay
=
delay
||
1000
;
_this
.
_delay
=
delay
||
1000
;
return
_this
;
return
_this
;
}
}
Countdown
.
prototype
.
getCountdown
=
function
()
{
Countdown
.
prototype
.
getCountdown
=
function
()
{
if
(
this
.
_format
==
"ddhhmmss"
)
return
this
.
getDDHHMMSS
();
if
(
this
.
_format
==
"hhmmss"
)
if
(
this
.
_format
==
"hhmmss"
)
return
this
.
getHHMMSS
();
return
this
.
getHHMMSS
();
if
(
this
.
_format
==
"mmss"
)
if
(
this
.
_format
==
"mmss"
)
return
this
.
getMMSS
();
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
()
{
Countdown
.
prototype
.
getHHMMSS
=
function
()
{
var
left
=
this
.
_
seconds
-
this
.
_counter
;
var
left
=
this
.
_
repeatCount
-
this
.
_counter
;
var
hours
=
Math
.
floor
(
left
/
3600
);
var
hours
=
Math
.
floor
(
left
/
3600
);
var
minutes
=
Math
.
floor
((
left
%
3600
)
/
60
);
var
minutes
=
Math
.
floor
((
left
%
3600
)
/
60
);
var
seconds
=
left
-
hours
*
3600
-
minutes
*
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
()
{
Countdown
.
prototype
.
getMMSS
=
function
()
{
var
left
=
this
.
_
seconds
-
this
.
_counter
;
var
left
=
this
.
_
repeatCount
-
this
.
_counter
;
var
minutes
=
Math
.
floor
(
left
/
60
);
var
minutes
=
Math
.
floor
(
left
/
60
);
var
seconds
=
left
%
60
;
var
seconds
=
left
%
60
;
return
getTimeNum
(
minutes
)
+
":"
+
getTimeNum
(
seconds
);
return
{
};
mm
:
getTimeNum
(
minutes
),
Countdown
.
prototype
.
getText
=
function
()
{
ss
:
getTimeNum
(
seconds
)
return
this
.
_text
.
replace
(
"{0}"
,
this
.
getCountdown
())
;
}
;
};
};
Countdown
.
prototype
.
start
=
function
()
{
Countdown
.
prototype
.
start
=
function
()
{
var
_this
=
this
;
var
_this
=
this
;
this
.
_running
=
true
;
this
.
_running
=
true
;
this
.
emit
(
"update"
,
this
.
get
Text
());
this
.
emit
(
"update"
,
this
.
get
Countdown
());
this
.
_timer
=
setInterval
(
function
()
{
this
.
_timer
=
setInterval
(
function
()
{
_this
.
_counter
++
;
_this
.
_counter
++
;
_this
.
emit
(
"update"
,
_this
.
get
Text
());
_this
.
emit
(
"update"
,
_this
.
get
Countdown
());
if
(
_this
.
_counter
==
_this
.
_
seconds
)
{
if
(
_this
.
_counter
==
_this
.
_
repeatCount
)
{
_this
.
stop
();
_this
.
stop
();
}
}
},
this
.
_delay
);
},
this
.
_delay
);
...
@@ -445,7 +465,7 @@
...
@@ -445,7 +465,7 @@
Countdown
.
prototype
.
reset
=
function
(
$seconds
)
{
Countdown
.
prototype
.
reset
=
function
(
$seconds
)
{
clearInterval
(
this
.
_timer
);
clearInterval
(
this
.
_timer
);
this
.
_counter
=
0
;
this
.
_counter
=
0
;
this
.
_
seconds
=
$seconds
;
this
.
_
repeatCount
=
$seconds
;
};
};
Object
.
defineProperty
(
Countdown
.
prototype
,
"running"
,
{
Object
.
defineProperty
(
Countdown
.
prototype
,
"running"
,
{
// set seconds(val: number) {
// set seconds(val: number) {
...
...
dist/time/Countdown.d.ts
View file @
9963cb28
import
{
EventEmitter
}
from
"../event"
;
import
{
EventEmitter
}
from
"../event"
;
export
declare
class
Countdown
extends
EventEmitter
<
any
>
{
export
declare
class
Countdown
extends
EventEmitter
<
any
>
{
private
_timer
;
private
_timer
;
private
_text
;
private
_repeatCount
;
private
_seconds
;
private
_format
;
private
_format
;
private
_counter
;
private
_counter
;
private
_delay
;
private
_delay
;
private
_running
;
private
_running
;
constructor
(
text
:
any
,
seconds
:
any
,
format
:
any
,
delay
:
any
);
constructor
(
repeatCount
:
any
,
format
:
any
,
delay
:
any
);
private
getCountdown
;
private
getCountdown
;
private
getDDHHMMSS
;
private
getHHMMSS
;
private
getHHMMSS
;
private
getMMSS
;
private
getMMSS
;
private
getText
;
start
():
void
;
start
():
void
;
private
stop
;
private
stop
;
reset
(
$seconds
:
number
):
void
;
reset
(
$seconds
:
number
):
void
;
...
...
dist/time/Countdown.js
View file @
9963cb28
...
@@ -20,46 +20,66 @@ function getTimeNum(n) {
...
@@ -20,46 +20,66 @@ function getTimeNum(n) {
}
}
var
Countdown
=
/** @class */
(
function
(
_super
)
{
var
Countdown
=
/** @class */
(
function
(
_super
)
{
__extends
(
Countdown
,
_super
);
__extends
(
Countdown
,
_super
);
function
Countdown
(
text
,
seconds
,
format
,
delay
)
{
function
Countdown
(
repeatCount
,
format
,
delay
)
{
var
_this
=
_super
.
call
(
this
)
||
this
;
var
_this
=
_super
.
call
(
this
)
||
this
;
_this
.
_running
=
false
;
_this
.
_running
=
false
;
_this
.
_text
=
text
;
_this
.
_repeatCount
=
repeatCount
;
_this
.
_seconds
=
seconds
;
_this
.
_format
=
format
;
_this
.
_format
=
format
;
_this
.
_counter
=
0
;
_this
.
_counter
=
0
;
_this
.
_delay
=
delay
||
1000
;
_this
.
_delay
=
delay
||
1000
;
return
_this
;
return
_this
;
}
}
Countdown
.
prototype
.
getCountdown
=
function
()
{
Countdown
.
prototype
.
getCountdown
=
function
()
{
if
(
this
.
_format
==
"ddhhmmss"
)
return
this
.
getDDHHMMSS
();
if
(
this
.
_format
==
"hhmmss"
)
if
(
this
.
_format
==
"hhmmss"
)
return
this
.
getHHMMSS
();
return
this
.
getHHMMSS
();
if
(
this
.
_format
==
"mmss"
)
if
(
this
.
_format
==
"mmss"
)
return
this
.
getMMSS
();
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
()
{
Countdown
.
prototype
.
getHHMMSS
=
function
()
{
var
left
=
this
.
_
seconds
-
this
.
_counter
;
var
left
=
this
.
_
repeatCount
-
this
.
_counter
;
var
hours
=
Math
.
floor
(
left
/
3600
);
var
hours
=
Math
.
floor
(
left
/
3600
);
var
minutes
=
Math
.
floor
((
left
%
3600
)
/
60
);
var
minutes
=
Math
.
floor
((
left
%
3600
)
/
60
);
var
seconds
=
left
-
hours
*
3600
-
minutes
*
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
()
{
Countdown
.
prototype
.
getMMSS
=
function
()
{
var
left
=
this
.
_
seconds
-
this
.
_counter
;
var
left
=
this
.
_
repeatCount
-
this
.
_counter
;
var
minutes
=
Math
.
floor
(
left
/
60
);
var
minutes
=
Math
.
floor
(
left
/
60
);
var
seconds
=
left
%
60
;
var
seconds
=
left
%
60
;
return
getTimeNum
(
minutes
)
+
":"
+
getTimeNum
(
seconds
);
return
{
};
mm
:
getTimeNum
(
minutes
),
Countdown
.
prototype
.
getText
=
function
()
{
ss
:
getTimeNum
(
seconds
)
return
this
.
_text
.
replace
(
"{0}"
,
this
.
getCountdown
())
;
}
;
};
};
Countdown
.
prototype
.
start
=
function
()
{
Countdown
.
prototype
.
start
=
function
()
{
var
_this
=
this
;
var
_this
=
this
;
this
.
_running
=
true
;
this
.
_running
=
true
;
this
.
emit
(
"update"
,
this
.
get
Text
());
this
.
emit
(
"update"
,
this
.
get
Countdown
());
this
.
_timer
=
setInterval
(
function
()
{
this
.
_timer
=
setInterval
(
function
()
{
_this
.
_counter
++
;
_this
.
_counter
++
;
_this
.
emit
(
"update"
,
_this
.
get
Text
());
_this
.
emit
(
"update"
,
_this
.
get
Countdown
());
if
(
_this
.
_counter
==
_this
.
_
seconds
)
{
if
(
_this
.
_counter
==
_this
.
_
repeatCount
)
{
_this
.
stop
();
_this
.
stop
();
}
}
},
this
.
_delay
);
},
this
.
_delay
);
...
@@ -72,7 +92,7 @@ var Countdown = /** @class */ (function (_super) {
...
@@ -72,7 +92,7 @@ var Countdown = /** @class */ (function (_super) {
Countdown
.
prototype
.
reset
=
function
(
$seconds
)
{
Countdown
.
prototype
.
reset
=
function
(
$seconds
)
{
clearInterval
(
this
.
_timer
);
clearInterval
(
this
.
_timer
);
this
.
_counter
=
0
;
this
.
_counter
=
0
;
this
.
_
seconds
=
$seconds
;
this
.
_
repeatCount
=
$seconds
;
};
};
Object
.
defineProperty
(
Countdown
.
prototype
,
"running"
,
{
Object
.
defineProperty
(
Countdown
.
prototype
,
"running"
,
{
// set seconds(val: number) {
// set seconds(val: number) {
...
...
src/time/countdown.ts
View file @
9963cb28
...
@@ -6,52 +6,70 @@ function getTimeNum(n: any) {
...
@@ -6,52 +6,70 @@ function getTimeNum(n: any) {
export
class
Countdown
extends
EventEmitter
<
any
>
{
export
class
Countdown
extends
EventEmitter
<
any
>
{
private
_timer
:
any
;
private
_timer
:
any
;
private
_text
:
any
;
private
_repeatCount
:
any
;
private
_seconds
:
any
;
private
_format
:
any
;
private
_format
:
any
;
private
_counter
:
any
;
private
_counter
:
any
;
private
_delay
:
any
;
private
_delay
:
any
;
private
_running
=
false
;
private
_running
=
false
;
constructor
(
text
:
any
,
seconds
:
any
,
format
:
any
,
delay
:
any
)
{
constructor
(
repeatCount
:
any
,
format
:
any
,
delay
:
any
)
{
super
();
super
();
this
.
_text
=
text
;
this
.
_repeatCount
=
repeatCount
;
this
.
_seconds
=
seconds
;
this
.
_format
=
format
;
this
.
_format
=
format
;
this
.
_counter
=
0
;
this
.
_counter
=
0
;
this
.
_delay
=
delay
||
1000
;
this
.
_delay
=
delay
||
1000
;
}
}
private
getCountdown
()
{
private
getCountdown
()
{
if
(
this
.
_format
==
"ddhhmmss"
)
return
this
.
getDDHHMMSS
();
if
(
this
.
_format
==
"hhmmss"
)
return
this
.
getHHMMSS
();
if
(
this
.
_format
==
"hhmmss"
)
return
this
.
getHHMMSS
();
if
(
this
.
_format
==
"mmss"
)
return
this
.
getMMSS
();
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
()
{
private
getHHMMSS
()
{
const
left
=
this
.
_
seconds
-
this
.
_counter
;
const
left
=
this
.
_
repeatCount
-
this
.
_counter
;
const
hours
=
Math
.
floor
(
left
/
3600
);
const
hours
=
Math
.
floor
(
left
/
3600
);
const
minutes
=
Math
.
floor
((
left
%
3600
)
/
60
);
const
minutes
=
Math
.
floor
((
left
%
3600
)
/
60
);
const
seconds
=
left
-
hours
*
3600
-
minutes
*
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
()
{
private
getMMSS
()
{
const
left
=
this
.
_
seconds
-
this
.
_counter
;
const
left
=
this
.
_
repeatCount
-
this
.
_counter
;
const
minutes
=
Math
.
floor
(
left
/
60
);
const
minutes
=
Math
.
floor
(
left
/
60
);
const
seconds
=
left
%
60
;
const
seconds
=
left
%
60
;
return
`
${
getTimeNum
(
minutes
)}
:
${
getTimeNum
(
seconds
)}
`
;
return
{
}
mm
:
getTimeNum
(
minutes
),
ss
:
getTimeNum
(
seconds
)
private
getText
()
{
}
return
this
.
_text
.
replace
(
"{0}"
,
this
.
getCountdown
());
}
}
start
()
{
start
()
{
this
.
_running
=
true
;
this
.
_running
=
true
;
this
.
emit
(
"update"
,
this
.
get
Text
());
this
.
emit
(
"update"
,
this
.
get
Countdown
());
this
.
_timer
=
setInterval
(()
=>
{
this
.
_timer
=
setInterval
(()
=>
{
this
.
_counter
++
;
this
.
_counter
++
;
this
.
emit
(
"update"
,
this
.
get
Text
());
this
.
emit
(
"update"
,
this
.
get
Countdown
());
if
(
this
.
_counter
==
this
.
_
seconds
)
{
if
(
this
.
_counter
==
this
.
_
repeatCount
)
{
this
.
stop
();
this
.
stop
();
}
}
},
this
.
_delay
);
},
this
.
_delay
);
...
@@ -66,7 +84,7 @@ export class Countdown extends EventEmitter<any> {
...
@@ -66,7 +84,7 @@ export class Countdown extends EventEmitter<any> {
reset
(
$seconds
:
number
)
{
reset
(
$seconds
:
number
)
{
clearInterval
(
this
.
_timer
);
clearInterval
(
this
.
_timer
);
this
.
_counter
=
0
;
this
.
_counter
=
0
;
this
.
_
seconds
=
$seconds
;
this
.
_
repeatCount
=
$seconds
;
}
}
// set seconds(val: number) {
// set seconds(val: number) {
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment