mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
tab focusing
This commit is contained in:
34
src/util/focus.js
Normal file
34
src/util/focus.js
Normal 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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user