szurubooru/client/js/main.js

49 lines
1.4 KiB
JavaScript
Raw Normal View History

'use strict';
require('./util/polyfill.js');
2016-04-05 17:57:26 +02:00
const page = require('page');
const origPushState = page.Context.prototype.pushState;
page.Context.prototype.pushState = function() {
window.scrollTo(0, 0);
origPushState.call(this);
};
const mousetrap = require('mousetrap');
page(/.*/, (ctx, next) => {
mousetrap.reset();
next();
});
let controllers = [];
controllers.push(require('./controllers/auth_controller.js'));
controllers.push(require('./controllers/posts_controller.js'));
controllers.push(require('./controllers/users_controller.js'));
controllers.push(require('./controllers/help_controller.js'));
controllers.push(require('./controllers/comments_controller.js'));
controllers.push(require('./controllers/history_controller.js'));
controllers.push(require('./controllers/tags_controller.js'));
controllers.push(require('./controllers/settings_controller.js'));
controllers.push(require('./controllers/home_controller.js'));
2016-04-07 19:03:49 +02:00
const events = require('./events.js');
for (let controller of controllers) {
controller.registerRoutes();
}
2016-04-07 19:03:49 +02:00
const api = require('./api.js');
api.loginFromCookies().then(() => {
2016-04-07 19:03:49 +02:00
page();
}).catch(errorMessage => {
if (window.location.href.indexOf('login') !== -1) {
api.forget();
page();
} else {
page('/');
events.notify(
events.Error,
'An error happened while trying to log you in: ' + errorMessage);
}
2016-04-07 19:03:49 +02:00
});