2021-02-04 03:17:17 +00:00
|
|
|
import {isIOS} from 'app/client/lib/browserInfo';
|
2021-01-21 19:12:24 +00:00
|
|
|
import {localStorageBoolObs} from 'app/client/lib/localStorageObs';
|
|
|
|
import {dom} from 'grainjs';
|
|
|
|
|
2021-02-25 16:11:59 +00:00
|
|
|
export const viewportEnabled = localStorageBoolObs('viewportEnabled', true);
|
2021-01-21 19:12:24 +00:00
|
|
|
|
|
|
|
export function toggleViewport() {
|
|
|
|
viewportEnabled.set(!viewportEnabled.get());
|
|
|
|
if (!viewportEnabled.get()) {
|
|
|
|
// Removing the meta tag doesn't cause mobile browsers to reload automatically.
|
|
|
|
location.reload();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export function addViewportTag() {
|
|
|
|
dom.update(document.head,
|
2021-02-04 03:17:17 +00:00
|
|
|
dom.maybe(viewportEnabled, () => {
|
|
|
|
// For the maximum-scale=1 advice, see https://stackoverflow.com/a/46254706/328565. On iOS,
|
|
|
|
// it prevents the auto-zoom when an input is focused, but does not prevent manual
|
|
|
|
// pinch-to-zoom. On Android, it's not needed, and would prevent manual zoom.
|
|
|
|
const viewportContent = "width=device-width,initial-scale=1.0" + (isIOS() ? ",maximum-scale=1" : "");
|
|
|
|
return dom('meta', {name: "viewport", content: viewportContent});
|
|
|
|
})
|
2021-01-21 19:12:24 +00:00
|
|
|
);
|
|
|
|
}
|