2020-11-17 02:22:48 +01:00
|
|
|
import {UIEventSource} from "../UIEventSource";
|
2021-01-06 02:21:50 +01:00
|
|
|
import Constants from "../../Models/Constants";
|
|
|
|
import {Utils} from "../../Utils";
|
2020-11-17 02:22:48 +01:00
|
|
|
|
|
|
|
export default class Hash {
|
|
|
|
|
2021-01-06 02:09:04 +01:00
|
|
|
public static hash : UIEventSource<string> = Hash.Get();
|
|
|
|
|
|
|
|
private static Get() : UIEventSource<string>{
|
2021-01-06 02:21:50 +01:00
|
|
|
if(Utils.runningFromConsole){
|
|
|
|
return new UIEventSource<string>(undefined);
|
|
|
|
}
|
2020-11-17 02:22:48 +01:00
|
|
|
const hash = new UIEventSource<string>(window.location.hash.substr(1));
|
|
|
|
hash.addCallback(h => {
|
2021-01-06 02:09:04 +01:00
|
|
|
if(h === undefined || h === ""){
|
|
|
|
window.location.hash = "";
|
|
|
|
return;
|
|
|
|
}
|
2020-11-17 02:22:48 +01:00
|
|
|
h = h.replace(/\//g, "_");
|
2021-01-06 02:09:04 +01:00
|
|
|
window.location.hash = "#" + h;
|
2020-11-17 02:22:48 +01:00
|
|
|
});
|
|
|
|
window.onhashchange = () => {
|
|
|
|
hash.setData(window.location.hash.substr(1))
|
|
|
|
}
|
|
|
|
|
|
|
|
return hash;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|