tab focusing

This commit is contained in:
Adam Bradley
2015-04-22 21:31:55 -05:00
parent 2bad5739aa
commit e4139fc738
15 changed files with 79 additions and 13 deletions

34
src/util/focus.js Normal file
View File

@@ -0,0 +1,34 @@
import {dom} from 'ionic2/util'
let isKeyInputEnabled = false
function keyDown() {
if (!isKeyInputEnabled) {
isKeyInputEnabled = true
dom.raf(enableKeyInput)
}
}
dom.ready().then(function() {
document.addEventListener('keydown', keyDown)
})
function enableKeyInput() {
document.body.classList[isKeyInputEnabled ? 'add' : 'remove']('key-input')
if (isKeyInputEnabled) {
document.addEventListener('mousedown', pointerDown)
document.addEventListener('touchstart', pointerDown)
} else {
document.removeEventListener('mousedown', pointerDown)
document.removeEventListener('touchstart', pointerDown)
}
}
function pointerDown() {
isKeyInputEnabled = false
dom.raf(enableKeyInput)
}