latest changes before manual submissions redesign
This commit is contained in:
@@ -11,11 +11,15 @@
|
||||
const captureDirectionButton = document.querySelector("#manual-capture-direction");
|
||||
const directionStatus = document.querySelector("#manual-direction-status");
|
||||
const directionPanel = document.querySelector("#manual-direction-panel");
|
||||
const compass = document.querySelector("#manual-compass");
|
||||
const compassRose = document.querySelector("#manual-compass-rose");
|
||||
const compassHeading = document.querySelector("#manual-compass-heading");
|
||||
const isMobileDevice = /Android|iPhone|iPad|iPod|IEMobile|Opera Mini/.test(navigator.userAgent)
|
||||
|| (navigator.userAgent.includes("Macintosh") && navigator.maxTouchPoints > 1);
|
||||
if (isMobileDevice) directionPanel.hidden = false;
|
||||
let orientationListener;
|
||||
let compassUnavailableTimeout;
|
||||
let compassRotation = null;
|
||||
const burstListener = createBurstListener();
|
||||
|
||||
const isUsableNumber = (value) => Number.isFinite(value);
|
||||
@@ -27,6 +31,27 @@
|
||||
window.clearTimeout(compassUnavailableTimeout);
|
||||
orientationListener = null;
|
||||
compassUnavailableTimeout = null;
|
||||
compass.hidden = true;
|
||||
compassRotation = null;
|
||||
};
|
||||
|
||||
const updateCompass = (heading) => {
|
||||
const targetRotation = -heading;
|
||||
if (compassRotation === null) {
|
||||
compassRotation = targetRotation;
|
||||
compassRose.style.transition = "none";
|
||||
compassRose.style.transform = `rotate(${compassRotation}deg)`;
|
||||
// Restore the short rotation animation after the initial reading.
|
||||
compassRose.offsetWidth;
|
||||
compassRose.style.transition = "";
|
||||
} else {
|
||||
const change = ((targetRotation - compassRotation + 540) % 360) - 180;
|
||||
compassRotation += change;
|
||||
compassRose.style.transform = `rotate(${compassRotation}deg)`;
|
||||
}
|
||||
compassHeading.textContent = `${displayDegrees(heading)}° · ${cardinalDirection(heading)}`;
|
||||
compass.setAttribute("aria-label", `${t.compassDirection || "Compass direction"} ${displayDegrees(heading)}° ${cardinalDirection(heading)}`);
|
||||
compass.hidden = false;
|
||||
};
|
||||
|
||||
const showCapturedDirection = (heading, accuracy) => {
|
||||
@@ -53,6 +78,7 @@
|
||||
directionDegrees.value = heading;
|
||||
directionAccuracy.value = accuracy === null ? "" : accuracy;
|
||||
showCapturedDirection(heading, accuracy);
|
||||
updateCompass(heading);
|
||||
window.clearTimeout(compassUnavailableTimeout);
|
||||
};
|
||||
window.addEventListener("deviceorientation", orientationListener);
|
||||
|
||||
Reference in New Issue
Block a user