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