szurubooru/public_html/js/Router.js

52 lines
1,021 B
JavaScript
Raw Normal View History

2014-08-31 23:22:56 +02:00
var App = App || {};
2014-09-04 19:57:06 +02:00
App.Router = function(jQuery, util, appState) {
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() {
2014-09-07 09:30:48 +02:00
inject('#/login', 'loginPresenter');
inject('#/logout', 'logoutPresenter');
inject('#/register', 'registrationPresenter');
inject('#/users', 'userListPresenter');
inject('#/users/:searchArgs', 'userListPresenter');
inject('#/user/:userName', 'userPresenter');
2014-09-07 09:57:01 +02:00
inject('#/user/:userName/:tab', 'userPresenter');
2014-08-31 23:22:56 +02:00
setRoot('#/users');
};
function setRoot(newRoot) {
root = newRoot;
Path.root(newRoot);
};
2014-09-07 09:30:48 +02:00
function inject(path, presenterName) {
2014-08-31 23:22:56 +02:00
Path.map(path).to(function() {
2014-09-07 09:30:48 +02:00
util.initContentPresenter(presenterName, this.params);
2014-08-31 23:22:56 +02:00
});
};
return {
start: start,
navigate: navigate,
navigateToMainPage: navigateToMainPage,
};
};
App.DI.registerSingleton('router', App.Router);