Skip to content

Commit 0406fac

Browse files
committed
fixed resetWith method in countdown
1 parent 10cbe1b commit 0406fac

6 files changed

Lines changed: 60 additions & 55 deletions

File tree

__html__/countdown.html

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,38 +11,30 @@
1111
<body class="m4-cloak">
1212
<div class="container">
1313
<h1 class="text-center">Countdown test page</h1>
14-
14+
<div class="d-flex flex-center gap-4">
15+
<button onclick="reset(1)">Reset 1</button>
16+
<button onclick="reset(2)">Reset 2</button>
17+
</div>
1518
<div class="example">
1619
<div class="row">
17-
<div data-role="countdown" data-hours="90" data-animate="slide" data-font-size="96"></div>
18-
<div class="cell-md-4">
19-
<div data-role="countdown" data-hours="90" data-animate="slide" style="font-size: 32px;"></div>
20-
</div>
21-
<div class="cell-md-4">
22-
<div data-role="countdown" data-hours="90" data-animate="fade" style="font-size: 32px;"></div>
23-
</div>
24-
<div class="cell-md-4">
25-
<div data-role="countdown" data-hours="90" data-animate="zoom" style="font-size: 32px;" lang="ua"></div>
26-
</div>
27-
</div>
28-
29-
<hr>
30-
<div>
31-
<div id="cd1" data-role="countdown" data-date="12/18/2026"></div>
32-
<div data-role="countdown" data-date="12/19/2026" class="countdownItems"></div>
33-
<div data-role="countdown" data-date="12/20/2026" class="countdownItems"></div>
34-
<div data-role="countdown" data-date="2026/05/05" class="countdownItems"></div>
20+
<div id="cd1" data-role="countdown" data-animate="slide" data-font-size="96"></div>
3521
</div>
3622
</div>
3723

3824
</div>
3925

4026
<script src="../lib/metro.js"></script>
4127
<script>
42-
setTimeout(()=>{
28+
function reset(v){
4329
const cd = Metro.getPlugin("#cd1", "countdown")
44-
cd.resetWith("07/15/2026 20:00")
45-
}, 1000)
30+
if (v === 1) {
31+
cd.resetWith("2025/05/15");
32+
} else {
33+
cd.resetWith({
34+
days: 2,
35+
});
36+
}
37+
}
4638
</script>
4739
</body>
4840
</html>

lib/metro.all.js

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
╚═╝ ╚═╝╚══════╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═════╝ ╚═╝
99

1010
* Metro UI v5.1.3 Components Library (https://metroui.org.ua)
11-
* Build: 12.05.2025, 14:08:29
11+
* Build: 13.05.2025, 20:39:22
1212
* Copyright 2012-2025 by Serhii Pimenov
1313
* Licensed under MIT
1414
*/
@@ -11314,7 +11314,7 @@
1131411314
(($6) => {
1131511315
"use strict";
1131611316
globalThis["__version__"] = "5.1.3";
11317-
globalThis["__build_time__"] = "12.05.2025, 14:08:29";
11317+
globalThis["__build_time__"] = "13.05.2025, 20:39:22";
1131811318
const meta_init = $6.meta("metro:init").attr("content");
1131911319
const meta_cloak = $6.meta("metro:cloak").attr("content");
1132011320
const meta_cloak_duration = $6.meta("metro:cloak_duration").attr("content");
@@ -11515,7 +11515,7 @@
1151511515
const normalizeComponentName = (name2) => typeof name2 !== "string" ? void 0 : name2.replace(/-/g, "").toLowerCase();
1151611516
const Metro2 = {
1151711517
version: "5.1.3",
11518-
build_time: "12.05.2025, 14:08:29",
11518+
build_time: "13.05.2025, 20:39:22",
1151911519
buildNumber: 0,
1152011520
isTouchable: isTouch3,
1152111521
fullScreenEnabled: document.fullscreenEnabled,
@@ -23265,17 +23265,21 @@
2326523265
resetWith: function(val) {
2326623266
const element2 = this.element;
2326723267
const o2 = this.options;
23268+
const keys = ["days", "hours", "minutes", "seconds"];
23269+
this.stop();
2326823270
if (typeof val === "string") {
2326923271
element2.attr("data-date", val);
23272+
for (const key of keys) {
23273+
o2[key] = 0;
23274+
}
2327023275
o2.date = val;
2327123276
} else if (typeof val === "object") {
23272-
const keys = ["days", "hours", "minutes", "seconds"];
23273-
$6.each(keys, (i3, v5) => {
23274-
if (Metro2.utils.isValue(val[v5])) {
23275-
element2.attr(`data-${v5}`, val[v5]);
23276-
o2[v5] = val[v5];
23277-
}
23278-
});
23277+
o2.date = null;
23278+
for (const key of keys) {
23279+
const newVal = val[key] !== void 0 ? val[key] : 0;
23280+
element2.attr(`data-${key}`, newVal);
23281+
o2[key] = newVal;
23282+
}
2327923283
}
2328023284
this.reset();
2328123285
},

lib/metro.all.js.map

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/metro.js

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
╚═╝ ╚═╝╚══════╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═════╝ ╚═╝
99

1010
* Metro UI v5.1.3 Components Library (https://metroui.org.ua)
11-
* Build: 12.05.2025, 14:08:29
11+
* Build: 13.05.2025, 20:39:22
1212
* Copyright 2012-2025 by Serhii Pimenov
1313
* Licensed under MIT
1414
*/
@@ -11314,7 +11314,7 @@
1131411314
(($6) => {
1131511315
"use strict";
1131611316
globalThis["__version__"] = "5.1.3";
11317-
globalThis["__build_time__"] = "12.05.2025, 14:08:29";
11317+
globalThis["__build_time__"] = "13.05.2025, 20:39:22";
1131811318
const meta_init = $6.meta("metro:init").attr("content");
1131911319
const meta_cloak = $6.meta("metro:cloak").attr("content");
1132011320
const meta_cloak_duration = $6.meta("metro:cloak_duration").attr("content");
@@ -11515,7 +11515,7 @@
1151511515
const normalizeComponentName = (name2) => typeof name2 !== "string" ? void 0 : name2.replace(/-/g, "").toLowerCase();
1151611516
const Metro2 = {
1151711517
version: "5.1.3",
11518-
build_time: "12.05.2025, 14:08:29",
11518+
build_time: "13.05.2025, 20:39:22",
1151911519
buildNumber: 0,
1152011520
isTouchable: isTouch3,
1152111521
fullScreenEnabled: document.fullscreenEnabled,
@@ -23265,17 +23265,21 @@
2326523265
resetWith: function(val) {
2326623266
const element2 = this.element;
2326723267
const o2 = this.options;
23268+
const keys = ["days", "hours", "minutes", "seconds"];
23269+
this.stop();
2326823270
if (typeof val === "string") {
2326923271
element2.attr("data-date", val);
23272+
for (const key of keys) {
23273+
o2[key] = 0;
23274+
}
2327023275
o2.date = val;
2327123276
} else if (typeof val === "object") {
23272-
const keys = ["days", "hours", "minutes", "seconds"];
23273-
$6.each(keys, (i3, v5) => {
23274-
if (Metro2.utils.isValue(val[v5])) {
23275-
element2.attr(`data-${v5}`, val[v5]);
23276-
o2[v5] = val[v5];
23277-
}
23278-
});
23277+
o2.date = null;
23278+
for (const key of keys) {
23279+
const newVal = val[key] !== void 0 ? val[key] : 0;
23280+
element2.attr(`data-${key}`, newVal);
23281+
o2[key] = newVal;
23282+
}
2327923283
}
2328023284
this.reset();
2328123285
},

lib/metro.js.map

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

source/components/countdown/countdown.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -534,18 +534,23 @@
534534
resetWith: function (val) {
535535
const element = this.element;
536536
const o = this.options;
537+
const keys = ["days", "hours", "minutes", "seconds"];
538+
539+
this.stop();
537540

538541
if (typeof val === "string") {
539542
element.attr("data-date", val);
543+
for (const key of keys) {
544+
o[key] = 0;
545+
}
540546
o.date = val;
541547
} else if (typeof val === "object") {
542-
const keys = ["days", "hours", "minutes", "seconds"];
543-
$.each(keys, (i, v) => {
544-
if (Metro.utils.isValue(val[v])) {
545-
element.attr(`data-${v}`, val[v]);
546-
o[v] = val[v];
547-
}
548-
});
548+
o.date = null;
549+
for (const key of keys) {
550+
const newVal = val[key] !== undefined ? val[key] : 0;
551+
element.attr(`data-${key}`, newVal);
552+
o[key] = newVal;
553+
}
549554
}
550555

551556
this.reset();

0 commit comments

Comments
 (0)