mirror of
https://github.com/tobspr/shapez.io.git
synced 2025-12-13 18:21:51 +00:00
Remove some legacy browser support code
Includes prefixed document.hidden property with respective visibilitychanged event and redundant support for navigator.language / lack of navigator.languages check.
This commit is contained in:
parent
a3d82cc46a
commit
89ca498613
@ -36,22 +36,6 @@ import { SettingsState } from "./states/settings";
|
|||||||
|
|
||||||
const logger = createLogger("application");
|
const logger = createLogger("application");
|
||||||
|
|
||||||
// Set the name of the hidden property and the change event for visibility
|
|
||||||
let pageHiddenPropName, pageVisibilityEventName;
|
|
||||||
if (typeof document.hidden !== "undefined") {
|
|
||||||
// Opera 12.10 and Firefox 18 and later support
|
|
||||||
pageHiddenPropName = "hidden";
|
|
||||||
pageVisibilityEventName = "visibilitychange";
|
|
||||||
// @ts-ignore
|
|
||||||
} else if (typeof document.msHidden !== "undefined") {
|
|
||||||
pageHiddenPropName = "msHidden";
|
|
||||||
pageVisibilityEventName = "msvisibilitychange";
|
|
||||||
// @ts-ignore
|
|
||||||
} else if (typeof document.webkitHidden !== "undefined") {
|
|
||||||
pageHiddenPropName = "webkitHidden";
|
|
||||||
pageVisibilityEventName = "webkitvisibilitychange";
|
|
||||||
}
|
|
||||||
|
|
||||||
export class Application {
|
export class Application {
|
||||||
/**
|
/**
|
||||||
* Boots the application
|
* Boots the application
|
||||||
@ -176,7 +160,7 @@ export class Application {
|
|||||||
// Unload events
|
// Unload events
|
||||||
window.addEventListener("beforeunload", this.onBeforeUnload.bind(this), true);
|
window.addEventListener("beforeunload", this.onBeforeUnload.bind(this), true);
|
||||||
|
|
||||||
document.addEventListener(pageVisibilityEventName, this.handleVisibilityChange.bind(this), false);
|
document.addEventListener("visibilitychange", this.handleVisibilityChange.bind(this), false);
|
||||||
|
|
||||||
// Track touches so we can update the focus appropriately
|
// Track touches so we can update the focus appropriately
|
||||||
document.addEventListener("touchstart", this.updateFocusAfterUserInteraction.bind(this), true);
|
document.addEventListener("touchstart", this.updateFocusAfterUserInteraction.bind(this), true);
|
||||||
@ -217,7 +201,7 @@ export class Application {
|
|||||||
*/
|
*/
|
||||||
handleVisibilityChange(event) {
|
handleVisibilityChange(event) {
|
||||||
window.focus();
|
window.focus();
|
||||||
const pageVisible = !document[pageHiddenPropName];
|
const pageVisible = !document.hidden;
|
||||||
if (pageVisible !== this.pageVisible) {
|
if (pageVisible !== this.pageVisible) {
|
||||||
this.pageVisible = pageVisible;
|
this.pageVisible = pageVisible;
|
||||||
logger.log("Visibility changed:", this.pageVisible);
|
logger.log("Visibility changed:", this.pageVisible);
|
||||||
|
|||||||
@ -7,7 +7,7 @@ const logger = createLogger("translations");
|
|||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
import baseTranslations from "./built-temp/base-en.json";
|
import baseTranslations from "./built-temp/base-en.json";
|
||||||
|
|
||||||
export let T = baseTranslations;
|
export const T = baseTranslations;
|
||||||
|
|
||||||
if (G_IS_DEV && globalConfig.debug.testTranslations) {
|
if (G_IS_DEV && globalConfig.debug.testTranslations) {
|
||||||
// Replaces all translations by fake translations to see whats translated and what not
|
// Replaces all translations by fake translations to see whats translated and what not
|
||||||
@ -67,18 +67,11 @@ function mapLanguageCodeToId(languageKey) {
|
|||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
export function autoDetectLanguageId() {
|
export function autoDetectLanguageId() {
|
||||||
let languages = [];
|
const languages = navigator.languages;
|
||||||
if (navigator.languages) {
|
|
||||||
languages = navigator.languages.slice();
|
|
||||||
} else if (navigator.language) {
|
|
||||||
languages = [navigator.language];
|
|
||||||
} else {
|
|
||||||
logger.warn("Navigator has no languages prop");
|
|
||||||
}
|
|
||||||
|
|
||||||
for (let i = 0; i < languages.length; ++i) {
|
for (const language of languages) {
|
||||||
logger.log("Trying to find language target for", languages[i]);
|
logger.log("Trying to find language target for", language);
|
||||||
const trans = mapLanguageCodeToId(languages[i]);
|
const trans = mapLanguageCodeToId(language);
|
||||||
if (trans) {
|
if (trans) {
|
||||||
return trans;
|
return trans;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user