From 25ae37c6b6d82f5ebd6e00edb0fa87a9e3cf41d4 Mon Sep 17 00:00:00 2001 From: ffont Date: Mon, 22 Jan 2024 12:51:22 +0100 Subject: [PATCH] Improve viewport handling in mobile --- .../static/bw-frontend/src/utils/browser.js | 18 ++++++++++++++++-- templates/base.html | 16 ---------------- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/freesound/static/bw-frontend/src/utils/browser.js b/freesound/static/bw-frontend/src/utils/browser.js index fe26fdda2..a7a49afe6 100644 --- a/freesound/static/bw-frontend/src/utils/browser.js +++ b/freesound/static/bw-frontend/src/utils/browser.js @@ -2,8 +2,8 @@ import { UAParser } from 'ua-parser-js'; const { browser, cpu, device } = UAParser(navigator.userAgent); -const isIPad = () => { - return device.model === 'iPad'; +const isPhone = () => { + return device.type === 'mobile'; } const isSafari = () => { @@ -18,3 +18,17 @@ export const isDesktopMacOSWithSafari = () => { return isSafari() && !isTouchEnabledDevice(); } +function update_viewport_width_if_needed(){ + const minWdth = isPhone() ? 1000: 600; + if (window.innerWidth < minWdth) { + document.querySelector('meta[name="viewport"]').setAttribute('content', 'width=0, initial-scale=0.8'); + } else { + document.querySelector('meta[name="viewport"]').setAttribute('content', 'width=0'); + } +} + +update_viewport_width_if_needed(); + +window.addEventListener("resize", function (event){ + update_viewport_width_if_needed(); +}); \ No newline at end of file diff --git a/templates/base.html b/templates/base.html index 337de35eb..f8242ff05 100644 --- a/templates/base.html +++ b/templates/base.html @@ -6,22 +6,6 @@ - Freesound{% if request.resolver_match.url_name != "front-page" %} - {% block title %}{% endblock %}{% endif %}