mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-19 03:32:21 +08:00
44 lines
1.0 KiB
JavaScript
44 lines
1.0 KiB
JavaScript
import {dom} from 'ionic2/util'
|
|
|
|
/* Focus Outline
|
|
* --------------------------------------------------
|
|
* When a keydown event happens, from a tab key, then the
|
|
* 'key-input' class is added to the body element so focusable
|
|
* elements have an outline. On a mousedown or touchstart
|
|
* event then the 'key-input' class is removed.
|
|
*/
|
|
|
|
|
|
let isKeyInputEnabled = false
|
|
|
|
function keyDown(ev) {
|
|
if (!isKeyInputEnabled && ev.keyCode == 9) {
|
|
isKeyInputEnabled = true
|
|
dom.raf(enableKeyInput)
|
|
}
|
|
}
|
|
|
|
|
|
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)
|
|
}
|
|
|
|
|
|
dom.ready().then(function() {
|
|
document.addEventListener('keydown', keyDown)
|
|
})
|