Created
July 14, 2017 12:25
-
-
Save callumacrae/55f3af8ecea40def03db26d11ae56605 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { keymap } from './keypress-promise'; | |
// import CrapEventEmitter from './crap-event-emitter'; | |
const page = { | |
id: 'page', | |
speech: 'voiceover-demo, web content', | |
children: [ | |
{ | |
id: 'main-heading', | |
speech: 'heading level 1, Example page', | |
}, | |
{ | |
id: 'first-paragraph', | |
speech: 'This is the first paragraph', | |
}, | |
{ | |
id: 'second paragraph', | |
speech: 'This is another paragraph', | |
}, | |
], | |
}; | |
const speak = (text) => { | |
speechSynthesis.cancel(); | |
speechSynthesis.speak(new SpeechSynthesisUtterance(text)); | |
}; | |
const position = []; | |
function getCurrent() { | |
return position.reduce((current, childIndex) => current.children[childIndex], page); | |
} | |
document.addEventListener('keydown', (e) => { | |
if (e.shiftKey && e.keyCode === keymap.DOWN) { | |
const parent = getCurrent(); | |
position.push(0); | |
const current = getCurrent(); | |
speak(`In ${parent.speech}, ${current.speech}`); | |
} | |
if (e.keyCode === keymap.RIGHT) { | |
position[position.length - 1]++; | |
speak(getCurrent().speech); | |
} | |
if (e.keyCode === keymap.LEFT) { | |
position[position.length - 1]--; | |
speak(getCurrent().speech); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment