szurubooru/public_html/js/Bootstrap.js
Marcin Kurczewski 6e09f90251 Fixed top navigation loading glitch
A race condition occurred - router could execute promise.abortAll()
even when top navigation didn't fully load. This caused top navigation
presenter to throw "broken promise" error, which is reserved for
promises made after core modules have been loaded.
2014-10-18 18:48:35 +02:00

33 lines
946 B
JavaScript

var App = App || {};
App.Bootstrap = function(auth, router, util, promise, presenterManager) {
promise.wait(
auth.tryLoginFromCookie(),
presenterManager.init())
.then(startRouting)
.fail(function(error) {
promise.wait(auth.loginAnonymous())
.then(startRouting)
.fail(function(response) {
console.log(response);
window.alert('Fatal authentication error: ' + response.json.error);
});
});
function startRouting() {
try {
router.start();
} catch (err) {
console.log(err);
}
}
};
App.DI.registerSingleton('bootstrap', ['auth', 'router', 'util', 'promise', 'presenterManager'], App.Bootstrap);
App.DI.registerManual('jQuery', function() { return window.$; });
App.DI.registerManual('pathJs', function() { return window.pathjs; });
App.DI.registerManual('_', function() { return window._; });
App.DI.registerManual('mousetrap', function() { return window.Mousetrap; });
App.DI.get('bootstrap');