Skip to content

Commit

Permalink
docs: fix reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoscaceres committed Aug 3, 2023
1 parent e3e0378 commit bf143c1
Showing 1 changed file with 23 additions and 17 deletions.
40 changes: 23 additions & 17 deletions demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -129,32 +129,38 @@ <h1>Screen Orientation Lock API Demo</h1>
}

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);

Expand Down

0 comments on commit bf143c1

Please sign in to comment.