Skip to content

Commit 520fafd

Browse files
committed
polish
1 parent 98d3c3d commit 520fafd

3 files changed

Lines changed: 78 additions & 14 deletions

File tree

content/assets/download.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ tags:
1414
---
1515

1616

17-
{{< timer/timer title="Free Download" link="https://drive.google.com/file/d/1-H0WfBZl9RfKma0orW-Rud5XDl0JNZaX/view?usp=sharings" timer="true" >}}
17+
{{< timer/timer title="Free Download" link="https://drive.google.com/file/d/1-H0WfBZl9RfKma0orW-Rud5XDl0JNZaX/view?usp=sharings" timer="true" showbutton="false" >}}
1818

1919

2020

content/blog/blender/snake-3d-model-tutorial-blender-asset.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ POWERHOUSE A16 BIONIC CHIP — The superfast chip powers advanced features like
3030

3131
### Free 3D Model 🧊
3232

33-
{{< timer/timer title="Free Download" link="/assets/download/" >}}
33+
{{< timer/timer title="Free Download" link="/assets/download/" >}}
3434

3535

3636

layouts/shortcodes/timer/timer.html

Lines changed: 76 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,34 @@
1-
{{ $title := .Get "title" }} {{ $link := .Get "link" }} {{ $timer := .Get
2-
"timer" | default "false" }} {{ if eq $timer "true" }}
3-
<button class="timer-btn" data-link="{{ $link }}">{{ $title }}</button>
4-
<span class="timer-label"></span>
1+
{{ $title := .Get "title" }}
2+
{{ $link := .Get "link" }}
3+
{{ $timer := .Get "timer" | default "false" }}
4+
{{ $showbutton := .Get "showbutton" | default "true" }}
5+
6+
{{ if eq $timer "true" }}
7+
<div class="timer-container">
8+
{{/* {{ if eq $showbutton "true" }}
9+
<button class="timer-btn" data-link="{{ $link }}">{{ $title }}</button>
10+
{{ end }} */}}
11+
<span class="timer-label"></span>
12+
<progress class="timer-progress" value="0" max="20"></progress>
13+
</div>
14+
15+
{{ else if eq $showbutton "true" }}
16+
<a href="{{ $link }}" class="timer-btn">
17+
{{ $title }}
18+
</a>
19+
{{ end }}
20+
521
<script>
6-
(function () {
22+
(function link_timer() {
723
var btns = document.querySelectorAll(".timer-btn");
824
btns.forEach(function (btn) {
925
if (btn.dataset.timerAttached) return;
1026
btn.dataset.timerAttached = "true";
11-
btn.addEventListener("click", function () {
27+
btn.addEventListener("click", function timer() {
1228
if (btn.disabled) return;
1329
btn.disabled = true;
1430
var label = btn.nextElementSibling;
15-
var countdown = 30;
31+
var countdown = 20;
1632
label.textContent = " Downloading in " + countdown + "sec ...";
1733
var timer = setInterval(function () {
1834
countdown--;
@@ -25,17 +41,34 @@
2541
});
2642
});
2743
})();
44+
45+
window.addEventListener("load", function () {
46+
var btn = document.querySelector(".timer-btn");
47+
var label = document.querySelector(".timer-label");
48+
var progress = document.querySelector(".timer-progress");
49+
var link = "{{ $link }}";
50+
var countdown = 20;
51+
label.textContent = " Redirecting in " + countdown + "s...";
52+
progress.value = 0;
53+
var timer = setInterval(function () {
54+
countdown--;
55+
label.textContent = " Redirecting in " + countdown + "s...";
56+
progress.value = 20 - countdown;
57+
if (countdown <= 0) {
58+
clearInterval(timer);
59+
window.location.href = link;
60+
}
61+
}, 1000);
62+
});
2863
</script>
29-
{{ else }}
30-
<a href="{{ $link }}" class="timer-btn"> {{ $title }} </a>
31-
{{ end }}
64+
3265

3366
<style>
3467
.timer-btn {
3568
margin-top: 1.5rem;
3669
display: block;
3770
padding: 0.5em 1.2em;
38-
background: #007bff;
71+
background: #d45039;
3972
color: #fff;
4073
border-radius: 4px;
4174
border: none;
@@ -58,9 +91,32 @@
5891
text-align: center;
5992
}
6093

94+
.timer-progress {
95+
width: 100%;
96+
height: 1em;
97+
border-radius: 6px;
98+
appearance: none;
99+
background-color: #e0e0e0;
100+
overflow: hidden;
101+
}
102+
.timer-progress::-webkit-progress-bar {
103+
background-color: #e0e0e0;
104+
border-radius: 6px;
105+
}
106+
.timer-progress::-webkit-progress-value {
107+
background-color: #d45039;
108+
border-radius: 6px;
109+
transition: width 0.2s;
110+
}
111+
.timer-progress::-moz-progress-bar {
112+
background-color: #d45039;
113+
border-radius: 6px;
114+
transition: width 0.2s;
115+
}
116+
61117
html:is(.dark) {
62118
.timer-btn {
63-
background: #3399ff;
119+
background: #d45039;
64120
color: #eee;
65121
border: none;
66122
}
@@ -71,5 +127,13 @@
71127
.timer-label {
72128
color: #ccc;
73129
}
130+
.timer-progress,
131+
.timer-progress::-webkit-progress-bar {
132+
background-color: #222;
133+
}
134+
.timer-progress::-webkit-progress-value,
135+
.timer-progress::-moz-progress-bar {
136+
background-color: #d45039;
137+
}
74138
}
75139
</style>

0 commit comments

Comments
 (0)