szurubooru/public_html/js/Router.js

51 lines
1.1 KiB
JavaScript
Raw Normal View History

2014-08-31 23:22:56 +02:00
var App = App || {};
App.Router = function(jQuery, util) {
2014-08-31 23:22:56 +02:00
var root = '#/';
injectRoutes();
function navigateToMainPage() {
window.location.href = root;
};
function navigate(url) {
window.location.href = url;
};
function start() {
Path.listen();
};
function injectRoutes() {
inject('#/login', function() { return App.DI.get('loginPresenter'); });
inject('#/logout', function() { return App.DI.get('logoutPresenter'); });
inject('#/register', function() { return App.DI.get('registrationPresenter'); });
2014-08-31 23:22:56 +02:00
inject('#/users', function() { return App.DI.get('userListPresenter'); });
inject('#/users/:searchArgs', function() { return App.DI.get('userListPresenter'); });
inject('#/user/:userName', function() { return App.DI.get('userPresenter'); });
2014-08-31 23:22:56 +02:00
setRoot('#/users');
};
function setRoot(newRoot) {
root = newRoot;
Path.root(newRoot);
};
function inject(path, presenterGetter) {
Path.map(path).to(function() {
util.initContentPresenter(presenterGetter, this.params);
2014-08-31 23:22:56 +02:00
});
};
return {
start: start,
navigate: navigate,
navigateToMainPage: navigateToMainPage,
};
};
App.DI.registerSingleton('router', App.Router);