2020-06-27 03:06:51 +02:00
|
|
|
import {UIElement} from "./UIElement";
|
2020-07-21 02:55:28 +02:00
|
|
|
import Translations from "./i18n/Translations";
|
2020-07-31 01:45:54 +02:00
|
|
|
import {State} from "../State";
|
2020-09-03 16:44:48 +02:00
|
|
|
import Combine from "./Base/Combine";
|
2020-06-27 03:06:51 +02:00
|
|
|
|
2020-07-21 02:55:28 +02:00
|
|
|
/**
|
|
|
|
* Handles the full screen popup on mobile
|
|
|
|
*/
|
2020-09-03 16:44:48 +02:00
|
|
|
export class FullScreenMessageBox extends UIElement {
|
2020-07-31 01:45:54 +02:00
|
|
|
|
2020-09-03 16:44:48 +02:00
|
|
|
private _uielement: UIElement;
|
|
|
|
private returnToTheMap: UIElement;
|
2020-06-27 03:06:51 +02:00
|
|
|
|
2020-07-31 01:45:54 +02:00
|
|
|
constructor(onClear: (() => void)) {
|
2020-09-03 16:44:48 +02:00
|
|
|
super(undefined);
|
|
|
|
|
2020-07-31 01:45:54 +02:00
|
|
|
const self = this;
|
2020-09-03 16:44:48 +02:00
|
|
|
|
|
|
|
State.state.fullScreenMessage.addCallback(uielement => {
|
|
|
|
return self._uielement = uielement?.SetClass("messagesboxmobile-scroll")?.Activate();
|
2020-07-31 01:45:54 +02:00
|
|
|
});
|
2020-09-03 16:44:48 +02:00
|
|
|
this._uielement = State.state.fullScreenMessage.data;
|
|
|
|
this.ListenTo(State.state.fullScreenMessage);
|
|
|
|
this.HideOnEmpty(true);
|
|
|
|
|
|
|
|
State.state.fullScreenMessage.addCallback(latestData => {
|
|
|
|
if (latestData === undefined) {
|
|
|
|
location.hash = "";
|
|
|
|
} else {
|
|
|
|
location.hash = "#element";
|
|
|
|
}
|
|
|
|
this.Update();
|
|
|
|
})
|
2020-06-27 03:06:51 +02:00
|
|
|
|
2020-07-25 18:00:08 +02:00
|
|
|
if (window !== undefined) {
|
|
|
|
window.onhashchange = function () {
|
|
|
|
if (location.hash === "") {
|
|
|
|
// No more element: back to the map!
|
2020-09-05 01:40:43 +02:00
|
|
|
self._uielement?.setData(undefined);
|
2020-07-25 18:00:08 +02:00
|
|
|
onClear();
|
|
|
|
}
|
2020-06-29 03:12:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-03 16:44:48 +02:00
|
|
|
this.returnToTheMap = Translations.t.general.returnToTheMap.Clone()
|
|
|
|
.SetClass("to-the-map")
|
2020-07-21 00:07:04 +02:00
|
|
|
.onClick(() => {
|
2020-09-03 16:44:48 +02:00
|
|
|
console.log("Returning...")
|
|
|
|
State.state.fullScreenMessage.setData(undefined);
|
2020-07-21 00:07:04 +02:00
|
|
|
onClear();
|
2020-09-03 16:44:48 +02:00
|
|
|
self.Update();
|
|
|
|
});
|
2020-06-29 03:12:44 +02:00
|
|
|
|
2020-06-27 03:06:51 +02:00
|
|
|
}
|
|
|
|
|
2020-06-29 03:12:44 +02:00
|
|
|
|
2020-09-03 16:44:48 +02:00
|
|
|
InnerRender(): string {
|
|
|
|
if (this._uielement === undefined) {
|
|
|
|
return "";
|
2020-06-27 03:06:51 +02:00
|
|
|
}
|
2020-09-05 01:40:43 +02:00
|
|
|
return new Combine([this._uielement, this.returnToTheMap]).Render();
|
2020-06-27 03:06:51 +02:00
|
|
|
}
|
|
|
|
|
2020-09-03 16:44:48 +02:00
|
|
|
|
2020-06-27 03:06:51 +02:00
|
|
|
}
|