Improved hash handling wrapper

This commit is contained in:
Niko 2022-02-12 00:33:38 +01:00
parent bca16a4784
commit 8967289631
1 changed files with 15 additions and 12 deletions

View File

@ -7,19 +7,22 @@ app.script = function(name, cback) {
loadScript(name, file, cback);
}
function scriptPageHandler(modname, cfg) {
cfg['callback'] = function(args) {
app.script(modname, function(ok) {
if (!ok) return;
eval(`app.${modname}`).load(args);
});
};
app.hashHandlers.push(cfg);
}
window.onload = function(e) {
app.hashHandlers.push({'exact': '', 'callback': function(args) {
app.script('pages.home', function(ok) {
if (!ok) return;
app.pages.home.load(args);
});
}});
app.hashHandlers.push({'exact': 'meet', 'callback': function(args) {
app.script('pages.meet', function(ok) {
if (!ok) return;
app.pages.meet.load(args);
});
}});
scriptPageHandler('pages.home', { exact: '' });
scriptPageHandler('pages.meet', { exact: 'meet' });
scriptPageHandler('pages.crushes', { exact: 'crushes' });
scriptPageHandler('pages.chat', { exact: 'chat' });
window.onhashchange();
}
window.onhashchange = function(e) {