diff --git a/web/src/app/js/app.js b/web/src/app/js/app.js index dfcd256..122da9d 100644 --- a/web/src/app/js/app.js +++ b/web/src/app/js/app.js @@ -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) {