Skip to content

Commit

Permalink
Feature/april (#124)
Browse files Browse the repository at this point in the history
* style: πŸ’„ Add april style

* feat: 🎸 remember spotlight disable from localStorage

* feat: 🎸 Extract function and remove listener on body

* fix: πŸ› fix visibility on mobile

* feat: 🎸 Run feature on april fool's day only

* refactor: πŸ’‘ refactor to avoid else

* refactor: πŸ’‘ simplify code
  • Loading branch information
mattboll committed Mar 29, 2024
1 parent 61f0b25 commit b3b97b0
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 0 deletions.
7 changes: 7 additions & 0 deletions site/layouts/_default/baseof.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,12 @@
{{ with $script.js }}
<script src="{{ relURL . }}"></script>
{{ end }}
<script>
const d = new Date();
// Show April Fools' joke
if (d.getMonth() === 3 && d.getDate() === 1) {
$.getScript("/js/april.js");
}
</script>
</body>
</html>
30 changes: 30 additions & 0 deletions site/static/js/april.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

(async function($) {

$("body").append("<a href='#' id='disable-spotlight' class='btn dark'>DΓ©sactiver le mode sombre</a><div id='spotlight'></div>");

const spotlightEl = $("#spotlight");

function handleMouseMove(event) {
const {clientX, clientY} = event;

spotlightEl[0].style.background = `radial-gradient(circle at ${clientX}px ${clientY}px, #00000000 10px, #000000FF 100px)`;
}

$("body").on("mousemove", handleMouseMove);

$("#disable-spotlight").on("click", () => {
disableApril();
localStorage.setItem("disable-april", "true");
});

if (localStorage.getItem("disable-april") === "true") {
disableApril();
}

function disableApril() {
$("#spotlight")[0].style.display = "none";
$("#disable-spotlight")[0].style.display = "none";
$("body").off("mousemove", handleMouseMove);
}
})(jQuery);
26 changes: 26 additions & 0 deletions src/css/april.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@


#spotlight {
position: fixed;
background: black;
opacity: 1;
width: 100vw;
height: 100vh;
top: 0;
left: 0;
z-index: 1000;
pointer-events: none;
@media screen and (max-width: 1024px) {
display: none;
}
}

#disable-spotlight {
position: fixed;
z-index: 999;
right: 50px;
bottom: 20px;
@media screen and (max-width: 1024px) {
display: none;
}
}
1 change: 1 addition & 0 deletions src/css/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
@import 'swiper';
@import 'legals';
@import 'cloud';
@import 'april';

:root {
scroll-behavior: smooth;
Expand Down

0 comments on commit b3b97b0

Please sign in to comment.