keyBindings = {
let currentSlide = -1;
let showNotes = () => {};
function gotoSlide(i) {
const slides = document.querySelectorAll('.observablehq .slide');
currentSlide = Math.min(Math.max(i, 0), slides.length - 1);
slides[currentSlide].scrollIntoView();
showNotes(slides[currentSlide]);
}
function keyUp(event) {
switch (event.key) {
case 'ArrowUp':
case 'ArrowLeft':
gotoSlide(currentSlide - 1);
break;
case 'ArrowDown':
case 'ArrowRight':
gotoSlide(currentSlide + 1);
break;
}
}
document.removeEventListener('keyup', keyUp);
document.addEventListener('keyup', keyUp);
const button = html`<button>Notes</button>`;
button.onclick = () => {
const notes = open("about:blank", "notes", "width=600,height=400").document.body;
showNotes = slide => {
notes.innerHTML = "";
const cell = slide.parentNode;
const siblings = Array.from(document.querySelectorAll('.observablehq'));
for (const sibling of siblings.slice(siblings.indexOf(cell))) {
if (sibling.querySelector('.notes')) {
notes.innerHTML = sibling.innerHTML;
break;
}
}
}
}
const wrapper = html`<div>${button}</div>`
wrapper.value = { gotoSlide: gotoSlide }
return wrapper;
}