/* Add stylesheet to page */ var presStyle = document.createElement('link'); presStyle.type = 'text/css'; presStyle.rel = 'stylesheet'; presStyle.href = '/presentation.css'; document.head.appendChild(presStyle); /* Print button */ const printBtn = document.getElementById('printBtn'); printBtn.addEventListener('click', function() { window.print(); }); /* Next and previous buttons */ const prevSlideBtn = document.getElementById('prevSlideBtn'); const nextSlideBtn = document.getElementById('nextSlideBtn'); const slides = document.getElementsByClassName('slide'); var slideIndex = 0; // Shows the "slideIndex + mod" numbered slide function showSlide(mod) { slides[slideIndex].classList.remove('absolute-slide'); slideIndex = (slides.length + slideIndex + mod) % slides.length; slides[slideIndex].classList.add('absolute-slide'); } prevSlideBtn.addEventListener('click', function() { showSlide(-1); }); nextSlideBtn.addEventListener('click', function() { showSlide(+1); }); /* Present button */ const presentCont = document.getElementById('presentCont'); const presentBtn = document.getElementById('presentBtn'); const articleBtn = document.getElementById('articleBtn'); var presenting = false; var pageY = 0; var pageX = 0; presentBtn.addEventListener('click', function() { // Hide the whole page document.body.classList.toggle('invisible'); document.body.classList.toggle('no-overflow'); // Fix background color document.body.classList.toggle('body-bg-color'); // Show the slide controller presentCont.classList.toggle('absolute-cont'); prevSlideBtn.classList.toggle('nodisplay'); nextSlideBtn.classList.toggle('nodisplay'); articleBtn.classList.toggle('nodisplay'); printBtn.classList.toggle('nodisplay'); // Show the first slide slides[slideIndex].classList.toggle('absolute-slide'); // Alignment of presentation to screen if (presenting) { window.scrollTo(pageX, pageY); } else { pageY = window.scrollY; pageX = window.scrollX; window.scrollTo(0, 0); } presenting = !presenting; }); /* Show as article button */ articleBtn.addEventListener('click', function() { printBtn.classList.toggle('nodisplay'); presentBtn.classList.toggle('nodisplay'); // Toggle presentation.css document.styleSheets.item(3).disabled = !document.styleSheets.item(3).disabled; }); /* Keyboard controls */ document.addEventListener('keydown', function (e) { switch (e.code) { // Previous slide case 'Backspace': case 'PageUp': case 'ArrowLeft': case 'ArrowUp': showSlide(-1); break; // Next slide case 'Space': case 'Enter': case 'PageDown': case 'ArrowRight': case 'ArrowDown': showSlide(+1); break; // Start (toggle) presenting case 'KeyP': case 'KeyT': presentBtn.click(); break; // Exit presentation case 'Escape': if (presenting) presentBtn.click(); break; // Go to first slide case 'Home': if (presenting) showSlide(-slideIndex); break; // Go to last slide case 'End': if (presenting) showSlide(-slideIndex -1); break; } });