mirror of
https://github.com/rr-/szurubooru.git
synced 2025-07-17 08:26:24 +00:00
Added frontend outline
This commit is contained in:
53
public_html/js/Router.js
Normal file
53
public_html/js/Router.js
Normal file
@ -0,0 +1,53 @@
|
||||
var App = App || {};
|
||||
|
||||
App.Router = function(jQuery) {
|
||||
|
||||
var root = '#/';
|
||||
|
||||
injectRoutes();
|
||||
|
||||
function navigateToMainPage() {
|
||||
window.location.href = root;
|
||||
};
|
||||
|
||||
function navigate(url) {
|
||||
window.location.href = url;
|
||||
};
|
||||
|
||||
function start() {
|
||||
Path.listen();
|
||||
};
|
||||
|
||||
function changePresenter(presenterGetter) {
|
||||
jQuery('#content').empty();
|
||||
var presenter = presenterGetter();
|
||||
};
|
||||
|
||||
function injectRoutes() {
|
||||
inject('#/login', function() { return new App.DI.get('loginPresenter'); });
|
||||
inject('#/logout', function() { return new App.DI.get('logoutPresenter'); });
|
||||
inject('#/register', function() { return new App.DI.get('registrationPresenter'); });
|
||||
inject('#/users', function() { return App.DI.get('userListPresenter'); });
|
||||
setRoot('#/users');
|
||||
};
|
||||
|
||||
function setRoot(newRoot) {
|
||||
root = newRoot;
|
||||
Path.root(newRoot);
|
||||
};
|
||||
|
||||
function inject(path, presenterGetter) {
|
||||
Path.map(path).to(function() {
|
||||
changePresenter(presenterGetter);
|
||||
});
|
||||
};
|
||||
|
||||
return {
|
||||
start: start,
|
||||
navigate: navigate,
|
||||
navigateToMainPage: navigateToMainPage,
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
App.DI.registerSingleton('router', App.Router);
|
Reference in New Issue
Block a user