mapcomplete/Logic/Web/Hash.ts

24 lines
678 B
TypeScript
Raw Normal View History

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