2020-06-27 03:06:51 +02:00
|
|
|
/**
|
|
|
|
* Keeps 'messagebox' and 'messageboxmobile' in sync, shows a 'close' button on the latter one
|
|
|
|
*/
|
|
|
|
import {UIEventSource} from "./UIEventSource";
|
|
|
|
import {UIElement} from "./UIElement";
|
2020-06-29 03:12:44 +02:00
|
|
|
import {VariableUiElement} from "./Base/VariableUIElement";
|
2020-06-27 03:06:51 +02:00
|
|
|
|
|
|
|
export class MessageBoxHandler {
|
2020-07-21 00:07:04 +02:00
|
|
|
private _uielement: UIEventSource<UIElement>;
|
2020-06-27 03:06:51 +02:00
|
|
|
|
2020-07-21 00:07:04 +02:00
|
|
|
constructor(uielement: UIEventSource<UIElement>,
|
2020-06-27 03:06:51 +02:00
|
|
|
onClear: (() => void)) {
|
|
|
|
this._uielement = uielement;
|
|
|
|
this.listenTo(uielement);
|
|
|
|
this.update();
|
|
|
|
|
2020-06-29 03:12:44 +02:00
|
|
|
window.onhashchange = function () {
|
|
|
|
if (location.hash === "") {
|
|
|
|
// No more element: back to the map!
|
|
|
|
uielement.setData(undefined);
|
|
|
|
onClear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-21 00:07:04 +02:00
|
|
|
new VariableUiElement(new UIEventSource<string>("<h2>Return to the map</h2>"))
|
|
|
|
.onClick(() => {
|
|
|
|
console.log("Clicked 'return to the map'")
|
|
|
|
uielement.setData(undefined);
|
|
|
|
onClear();
|
|
|
|
})
|
|
|
|
.AttachTo("to-the-map");
|
2020-06-27 03:06:51 +02:00
|
|
|
|
2020-06-29 03:12:44 +02:00
|
|
|
|
2020-06-27 03:06:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
listenTo(uiEventSource: UIEventSource<any>) {
|
|
|
|
const self = this;
|
|
|
|
uiEventSource.addCallback(function () {
|
|
|
|
self.update();
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-06-29 03:12:44 +02:00
|
|
|
|
2020-06-27 03:06:51 +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 = ""
|
|
|
|
}
|
2020-06-27 03:06:51 +02:00
|
|
|
return;
|
|
|
|
}
|
2020-06-29 03:12:44 +02:00
|
|
|
location.hash = "#element"
|
2020-06-27 03:06:51 +02:00
|
|
|
wrapper.classList.remove("hidden");
|
|
|
|
|
2020-07-21 00:07:04 +02:00
|
|
|
gen
|
2020-06-27 03:06:51 +02:00
|
|
|
?.HideOnEmpty(true)
|
|
|
|
?.AttachTo("messagesboxmobile")
|
|
|
|
?.Activate();
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|