From bf143c1bbf5b836f298073d08769098ec5348812 Mon Sep 17 00:00:00 2001 From: Marcos Caceres Date: Fri, 4 Aug 2023 09:12:50 +1000 Subject: [PATCH] docs: fix reporting --- demo/index.html | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/demo/index.html b/demo/index.html index c51dca1..a3a5639 100644 --- a/demo/index.html +++ b/demo/index.html @@ -129,32 +129,38 @@

Screen Orientation Lock API Demo

} function isSupported() { - switch (true) { - case !screen.orientation?.lock: - logError("Screen Orientation API is not supported in this browser."); - return false; - case !document.documentElement.requestFullscreen: - logError( - "the Fullscreen API, which is required, is unavailable in this browser." - ); - return false; + if (!screen.orientation) { + logError("screen.orientation not available."); + return false; + } + if (!screen.orientation?.lock) { + logError("Orientation locking is not supported in this browser."); + return false; + } + if (!document.documentElement?.requestFullscreen) { + logError( + "the Fullscreen API, which is required, is unavailable in this browser." + ); + return false; } - return true; } function init() { - isSupported(); - document.body.classList.remove("not-supported"); - selector.disabled = false; - - const orientationQuery = window.matchMedia("(orientation: landscape)"); + if (isSupported()) { + document.body.classList.remove("not-supported"); + selector.disabled = false; + } const handleOrientationChange = () => { log(`Orientation changed to "${screen.orientation?.type}".`, "event"); renderUpdate(); - } + }; - orientationQuery.addEventListener("change", handleOrientationChange); + // use a media query to detect orientation change + if (!screen.orientation) { + const orientationQuery = window.matchMedia("(orientation: landscape)"); + orientationQuery.addEventListener("change", handleOrientationChange); + } screen.orientation?.addEventListener("change", handleOrientationChange);