Skip to content

Commit 4de80db

Browse files
committed
Countdown 2.0
1 parent fbaea74 commit 4de80db

10 files changed

Lines changed: 221 additions & 112 deletions

File tree

_config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ exclude:
3131
- node_modules
3232

3333
plugins:
34-
- jekyll-minifier
34+
- jekyll-minifier
3535

3636
jekyll-minifier:
3737
uglifier_args:

_layouts/countdown.html

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
layout: default
3+
---
4+
5+
<main class="main-countdown">
6+
<section class="countdown {{ page.action }}">
7+
<time class="end-date" datetime="{{ page.datetime }}">
8+
<div class="days">
9+
<div class="count days-count"></div>
10+
<h2 class="label"></h2>
11+
</div>
12+
<div class="hours">
13+
<div class="count hours-count"></div>
14+
<h2 class="label"></h2>
15+
</div>
16+
<div class="minutes">
17+
<div class="count minutes-count"></div>
18+
<h2 class="label"></h2>
19+
</div>
20+
<div class="seconds">
21+
<div class="count seconds-count"></div>
22+
<h2 class="label"></h2>
23+
</div>
24+
</time>
25+
<span class="message {{ page.action }}"></span>
26+
</section>
27+
</main>
28+
{{ page.content }}
29+
<script>
30+
const claudiaAction = "{{ page.action }}";
31+
</script>
32+
<script src="{{ '/js/claudia.js' | prepend: site.baseurl }}"></script>

_sass/_claudia.scss

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,20 @@
99
.countdown {
1010
@include flexbox;
1111
@include flex(1);
12+
@include flex-direction(column);
1213
@include align-items(center);
1314
@include justify-content(center);
1415
font-size: 2.5rem;
15-
flex-direction: column;
16+
padding: 2rem 0;
17+
18+
&.returning {
19+
.seconds-count {
20+
color: $return-color;
21+
}
22+
.message {
23+
color: $return-color;
24+
}
25+
}
1626
}
1727

1828
.end-date {

_sass/_mixins.scss

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,33 @@
5050
flex: $flex;
5151
}
5252

53+
@mixin flex-direction($direction: row) {
54+
@if $direction == row-reverse {
55+
-webkit-box-direction: reverse;
56+
-webkit-box-orient: horizontal;
57+
-moz-box-direction: reverse;
58+
-moz-box-orient: horizontal;
59+
} @else if $direction == column {
60+
-webkit-box-direction: normal;
61+
-webkit-box-orient: vertical;
62+
-moz-box-direction: normal;
63+
-moz-box-orient: vertical;
64+
} @else if $direction == column-reverse {
65+
-webkit-box-direction: reverse;
66+
-webkit-box-orient: vertical;
67+
-moz-box-direction: reverse;
68+
-moz-box-orient: vertical;
69+
} @else {
70+
-webkit-box-direction: normal;
71+
-webkit-box-orient: horizontal;
72+
-moz-box-direction: normal;
73+
-moz-box-orient: horizontal;
74+
}
75+
-webkit-flex-direction: $direction;
76+
-ms-flex-direction: $direction;
77+
flex-direction: $direction;
78+
}
79+
5380
@mixin align-items($align) {
5481
-webkit-box-align: $align;
5582
-webkit-flex-align: $align;

claudia/claudia.js

Lines changed: 0 additions & 84 deletions
This file was deleted.

claudia/index.html

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,8 @@
11
---
2-
layout: default
2+
layout: countdown
33
title: Bye Claudia!
4+
action: leaving
5+
datetime: Tue Jul 5 2016 00:00:00 PDT
46
og_description: Claudia's leaving soon! :c
57
og_image_url: https://danielliu.me/claudia/countdown.png
68
---
7-
8-
<main class="main-countdown">
9-
<section class="countdown">
10-
<time class="end-date" datetime="Tue Jul 5 2016 00:00:00 PDT">
11-
<div class="days">
12-
<div class="count days-count"></div>
13-
<h2 class="label"></h2>
14-
</div>
15-
<div class="hours">
16-
<div class="count hours-count"></div>
17-
<h2 class="label"></h2>
18-
</div>
19-
<div class="minutes">
20-
<div class="count minutes-count"></div>
21-
<h2 class="label"></h2>
22-
</div>
23-
<div class="seconds">
24-
<div class="count seconds-count"></div>
25-
<h2 class="label"></h2>
26-
</div>
27-
</time>
28-
<span class="message"></span>
29-
</section>
30-
</main>
31-
<script src="claudia.js"></script>

claudia2.0/countdown.png

27.8 KB
Loading

claudia2.0/index.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
layout: countdown
3+
title: Welcome back Claudia!
4+
action: returning
5+
datetime: Mon Dec 26 2022 18:55:00 PDT
6+
og_description: "Claudia's coming back soon! c:"
7+
og_image_url: https://danielliu.me/claudia2.0/countdown.png
8+
---

css/main.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ $spacing-unit: 30px;
1616
$text-color: #333;
1717
$background-color: #ffffff;
1818
$brand-color: #80cbc4;
19+
$return-color: #eb9486;
1920

2021
$grey: #828282;
2122
$grey-lighten-1: lighten($grey, 10%);

js/claudia.js

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
const setMessage = (countdown, msg) => {
2+
const message = countdown.querySelector(".message");
3+
message.textContent = msg;
4+
};
5+
6+
const getRemainingTime = (time) => {
7+
const days = parseInt(time / (60 * 60 * 24), 10);
8+
const hours = parseInt((time / (60 * 60)) % 24, 10);
9+
const minutes = parseInt((time / 60) % 60, 10);
10+
const seconds = parseInt(time % 60, 10);
11+
12+
return [days, hours, minutes, seconds];
13+
};
14+
15+
const updateCounters = (countdown, remaining) => {
16+
const labels = countdown.querySelectorAll(".label");
17+
const counters = countdown.querySelectorAll(".count");
18+
const units = ["day", "hour", "minute", "second"];
19+
20+
for (let i = 0; i < counters.length; i += 1) {
21+
const el = counters[i];
22+
const count = remaining[i];
23+
const label = labels[i];
24+
const unit = units[i];
25+
26+
// Zero-pad values below 10
27+
el.textContent = count < 10 ? `0${count}` : count;
28+
label.textContent = count === 1 ? unit : `${unit}s`;
29+
}
30+
};
31+
32+
const embedVid = (container, beforeElement, youtube) => {
33+
const videoFrameContainer = document.createElement("div");
34+
const embed = document.createElement("iframe");
35+
const w = window.innerWidth;
36+
const attrs = {
37+
src: youtube,
38+
frameborder: 0,
39+
allowfullscreen: "",
40+
};
41+
42+
attrs.width = w < 400 ? w : 400;
43+
attrs.height = (attrs.width * 3) / 4;
44+
Object.entries(attrs).map(([key, val]) => embed.setAttribute(key, val));
45+
46+
videoFrameContainer.setAttribute("class", "vid-container");
47+
videoFrameContainer.appendChild(embed);
48+
49+
container.insertBefore(videoFrameContainer, beforeElement);
50+
};
51+
52+
const generateQueryString = (query) => {
53+
const queryString = new URLSearchParams(query);
54+
return queryString.toString();
55+
};
56+
57+
const claudiaCountdown = () => {
58+
const container = document.querySelector(".countdown");
59+
const time = document.querySelector(".countdown time");
60+
const date = new Date(time.getAttribute("datetime"));
61+
62+
const youtubeOptions = {
63+
autoplay: 0,
64+
color: "white",
65+
controls: 1,
66+
};
67+
const leavingYoutubeOptions = {
68+
...youtubeOptions,
69+
end: 60,
70+
};
71+
const returningYoutubeOptions = {
72+
...youtubeOptions,
73+
start: 35,
74+
};
75+
const extras = {
76+
leaving: {
77+
youtubeLink: `https://www.youtube.com/embed/s0SUEMGZU04?${generateQueryString(
78+
leavingYoutubeOptions
79+
)}`,
80+
messageBefore: "until Claudia leaves :(",
81+
messageAfter: "since Claudia left :(",
82+
messageDone: "that Claudia was gone, but now she's back! 🎊",
83+
},
84+
returning: {
85+
youtubeLink: `https://www.youtube.com/embed/vNey0PR46F4?${generateQueryString(
86+
returningYoutubeOptions
87+
)}`,
88+
messageBefore: "until Claudia returns... ⏳",
89+
messageAfter: "since Claudia came back! 🎉🎉",
90+
date: new Date("Mon Dec 26 2022 18:55:26 PDT"),
91+
},
92+
};
93+
94+
// eslint-disable-next-line no-undef -- from page variable set within layout
95+
const action = claudiaAction;
96+
const data = extras[action];
97+
98+
if (action === "leaving") {
99+
const tdeltaSeconds = parseInt((date - extras.returning.date) / 1000, 10);
100+
const secondsToDone = parseInt(
101+
(Date.now() - extras.returning.date) / 1000,
102+
10
103+
);
104+
const done = secondsToDone >= 0;
105+
if (done) {
106+
updateCounters(container, getRemainingTime(-tdeltaSeconds));
107+
setMessage(container, extras.leaving.messageDone);
108+
embedVid(container, time, extras.returning.youtubeLink);
109+
return;
110+
}
111+
}
112+
113+
// Calculate number of seconds
114+
const tdeltaSecondsOriginal = parseInt((date - Date.now()) / 1000, 10);
115+
const direction = tdeltaSecondsOriginal > 0 ? -1 : 1;
116+
const message =
117+
tdeltaSecondsOriginal > 0 ? data.messageBefore : data.messageAfter;
118+
let tdeltaSeconds =
119+
tdeltaSecondsOriginal > 0 ? tdeltaSecondsOriginal : -tdeltaSecondsOriginal;
120+
121+
updateCounters(container, getRemainingTime((tdeltaSeconds += direction)));
122+
setMessage(container, message);
123+
if (tdeltaSecondsOriginal <= 0) {
124+
embedVid(container, time, data.youtubeLink);
125+
}
126+
127+
const timer = setInterval(() => {
128+
updateCounters(container, getRemainingTime((tdeltaSeconds += direction)));
129+
// on page when countdown reaches end datetime
130+
if (tdeltaSeconds === 0) {
131+
clearInterval(timer);
132+
embedVid(container, time, data.youtubeLink);
133+
setMessage(container, data.messageAfter);
134+
}
135+
}, 1000);
136+
};
137+
138+
claudiaCountdown();

0 commit comments

Comments
 (0)