mapcomplete/UI/FullScreenMessageBoxHandler.ts

65 lines
1.6 KiB
TypeScript
Raw Normal View History

import {UIEventSource} from "./UIEventSource";
import {UIElement} from "./UIElement";
2020-06-29 03:12:44 +02:00
import {VariableUiElement} from "./Base/VariableUIElement";
import Translations from "./i18n/Translations";
import {State} from "../State";
/**
* Handles the full screen popup on mobile
*/
export class FullScreenMessageBoxHandler {
2020-07-21 00:07:04 +02:00
private _uielement: UIEventSource<UIElement>;
constructor(onClear: (() => void)) {
this._uielement = State.state.fullScreenMessage;
const self = this;
this._uielement.addCallback(function () {
self.update();
});
this.update();
2020-07-25 18:00:08 +02:00
if (window !== undefined) {
window.onhashchange = function () {
if (location.hash === "") {
// No more element: back to the map!
self._uielement.setData(undefined);
2020-07-25 18:00:08 +02:00
onClear();
}
2020-06-29 03:12:44 +02:00
}
}
Translations.t.general.returnToTheMap
2020-07-21 00:07:04 +02:00
.onClick(() => {
self._uielement.setData(undefined);
2020-07-21 00:07:04 +02:00
onClear();
})
2020-07-25 18:00:08 +02:00
.AttachTo("to-the-map");
2020-06-29 03:12:44 +02:00
}
2020-06-29 03:12:44 +02:00
update() {
const wrapper = document.getElementById("messagesboxmobilewrapper");
const gen = this._uielement.data;
if (gen === undefined) {
2020-06-29 03:12:44 +02:00
wrapper.classList.add("hidden")
if (location.hash !== "") {
location.hash = ""
}
return;
}
2020-06-29 03:12:44 +02:00
location.hash = "#element"
wrapper.classList.remove("hidden");
2020-07-21 00:07:04 +02:00
gen
?.HideOnEmpty(true)
?.AttachTo("messagesboxmobile")
?.Activate();
}
}