From 4e30ae95eaf52a7f427bdf020d118f40e00ab291 Mon Sep 17 00:00:00 2001 From: Zach Berwaldt Date: Mon, 9 Oct 2023 13:41:04 -0400 Subject: add some homemade svg, wpartials, and darkmode --- assets/js/fullscreen.js | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) (limited to 'assets/js/fullscreen.js') diff --git a/assets/js/fullscreen.js b/assets/js/fullscreen.js index e191854..e3cc342 100644 --- a/assets/js/fullscreen.js +++ b/assets/js/fullscreen.js @@ -1,15 +1,27 @@ -// get with web apis #fullscren element and on click toggle fullscreen +// page const fullscreen = document.getElementById('fullscreen'); +const fullscreenIcon = document.getElementById('fullscreen-icon'); +const smallscreenIcon = document.getElementById('smallscreen-icon'); const elem = document.documentElement; -fullscreen.addEventListener('click', () => { + +// Functions + +function toggleFullscreen(event) { + // check if the event is a keydown event or a click event + if (event.type === 'keydown') { + // check if the key pressed is '/' key + if (event.key !== '/') return; + } if (document.fullscreenElement) { closeFullscreen(); } else { openFullscreen(); } -}); +} function openFullscreen() { + smallscreenIcon.classList.toggle('hide'); + fullscreenIcon.classList.toggle('hide'); if (elem.requestFullscreen) { elem.requestFullscreen(); } else if (elem.webkitRequestFullscreen) { /* Safari */ @@ -20,6 +32,8 @@ function openFullscreen() { } function closeFullscreen() { + smallscreenIcon.classList.toggle('hide'); + fullscreenIcon.classList.toggle('hide'); if (document.exitFullscreen) { document.exitFullscreen(); } else if (document.webkitExitFullscreen) { /* Safari */ @@ -27,4 +41,9 @@ function closeFullscreen() { } else if (document.msExitFullscreen) { /* IE11 */ document.msExitFullscreen(); } -} \ No newline at end of file +} + +// Listeners + +fullscreen.addEventListener('click', toggleFullscreen); +document.addEventListener('keydown', toggleFullscreen); \ No newline at end of file -- cgit v1.1