diff options
Diffstat (limited to 'app/javascript/mastodon/is_mobile.js')
-rw-r--r-- | app/javascript/mastodon/is_mobile.js | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/app/javascript/mastodon/is_mobile.js b/app/javascript/mastodon/is_mobile.js index 2926eb4b1..3c8ec1545 100644 --- a/app/javascript/mastodon/is_mobile.js +++ b/app/javascript/mastodon/is_mobile.js @@ -1,10 +1,19 @@ +// @ts-check + import { supportsPassiveEvents } from 'detect-passive-events'; import { forceSingleColumn } from 'mastodon/initial_state'; const LAYOUT_BREAKPOINT = 630; +/** + * @param {number} width + * @returns {boolean} + */ export const isMobile = width => width <= LAYOUT_BREAKPOINT; +/** + * @returns {string} + */ export const layoutFromWindow = () => { if (isMobile(window.innerWidth)) { return 'mobile'; @@ -17,11 +26,13 @@ export const layoutFromWindow = () => { const iOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream; +const listenerOptions = supportsPassiveEvents ? { passive: true } : false; + let userTouching = false; -let listenerOptions = supportsPassiveEvents ? { passive: true } : false; const touchListener = () => { userTouching = true; + window.removeEventListener('touchstart', touchListener, listenerOptions); }; |