Skip to content

Instantly share code, notes, and snippets.

@amcdnl
Created October 19, 2018 12:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amcdnl/16953c28beb4dd0d94f556699f755473 to your computer and use it in GitHub Desktop.
Save amcdnl/16953c28beb4dd0d94f556699f755473 to your computer and use it in GitHub Desktop.
nativeElement.addEventListener('focus', focusListener, true);
nativeElement.addEventListener('blur', blurListener, true);
document.addEventListener('keydown', documentKeydownListener, true);
document.addEventListener('mousedown', documentMousedownListener, true);
document.addEventListener('touchstart', documentTouchstartListener, true);
window.addEventListener('focus', windowFocusListener);
let documentKeydownListener = () => {
this._lastTouchTarget = null;
this._setOriginForCurrentEventQueue('keyboard');
};
let documentMousedownListener = () => {
if (!this._lastTouchTarget) {
this._setOriginForCurrentEventQueue('mouse');
}
};
let documentTouchstartListener = (event: TouchEvent) => {
if (this._touchTimeoutId != null) {
clearTimeout(this._touchTimeoutId);
}
this._lastTouchTarget = event.target;
this._touchTimeoutId = setTimeout(() => this._lastTouchTarget = null, TOUCH_BUFFER_MS);
};
let windowFocusListener = () => {
this._windowFocused = true;
this._windowFocusTimeoutId = setTimeout(() => this._windowFocused = false);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment