gallery.accords-library.com/client/js/main.js

67 lines
1.9 KiB
JavaScript
Raw Normal View History

'use strict';
require('./util/polyfill.js');
const misc = require('./util/misc.js');
2016-04-05 15:57:26 +00:00
const router = require('./router.js');
const origPushState = router.Context.prototype.pushState;
router.Context.prototype.pushState = function() {
window.scrollTo(0, 0);
origPushState.call(this);
};
router.exit(
/.*/,
(ctx, next) => {
views.unlistenToMessages();
if (misc.confirmPageExit()) {
next();
}
});
const mousetrap = require('mousetrap');
router.enter(
/.*/,
(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'));
// home defines 404 routes, need to be registered as last
controllers.push(require('./controllers/home_controller.js'));
2016-05-10 08:57:59 +00:00
const tags = require('./tags.js');
2016-04-07 17:03:49 +00:00
const events = require('./events.js');
const views = require('./util/views.js');
for (let controller of controllers) {
controller.registerRoutes();
}
2016-04-07 17:03:49 +00:00
const api = require('./api.js');
2016-05-10 08:57:59 +00:00
Promise.all([tags.refreshExport(), api.loginFromCookies()])
.then(() => {
router.start();
2016-05-10 08:57:59 +00:00
}).catch(errorMessage => {
if (window.location.href.indexOf('login') !== -1) {
api.forget();
router.start();
2016-05-10 08:57:59 +00:00
} else {
router.start('/');
2016-05-10 08:57:59 +00:00
events.notify(
events.Error,
2016-05-10 12:13:24 +00:00
'An error happened while trying to log you in: ' +
errorMessage);
2016-05-10 08:57:59 +00:00
}
});