szurubooru/public_html/js/PresenterManager.js

73 lines
1.8 KiB
JavaScript
Raw Normal View History

var App = App || {};
App.PresenterManager = function(jQuery, topNavigationPresenter, keyboard) {
2014-09-17 22:37:49 +02:00
var lastContentPresenter = null;
var $spinner;
var spinnerTimeout;
function init() {
2014-09-17 22:37:49 +02:00
initPresenter(topNavigationPresenter, [], function() {});
$spinner = jQuery('body').find('#wait');
}
2014-09-17 22:37:49 +02:00
function initPresenter(presenter, args, loaded) {
presenter.init.call(presenter, args, loaded);
}
function showContentSpinner() {
$spinner.show();
}
function hideContentSpinner() {
$spinner.hide();
}
2014-09-17 22:37:49 +02:00
function switchContentPresenter(presenter, args) {
var contentPresenterLoaded = function() {
window.clearTimeout(spinnerTimeout);
hideContentSpinner();
2014-09-17 22:37:49 +02:00
};
spinnerTimeout = window.setTimeout(function() {
showContentSpinner();
}, 100);
2014-09-17 22:37:49 +02:00
if (lastContentPresenter === null || lastContentPresenter.name !== presenter.name) {
keyboard.reset();
topNavigationPresenter.changeTitle(null);
topNavigationPresenter.focus();
2014-09-17 22:37:49 +02:00
presenter.init.call(presenter, args, contentPresenterLoaded);
lastContentPresenter = presenter;
} else if (lastContentPresenter.reinit) {
2014-09-17 22:37:49 +02:00
lastContentPresenter.reinit.call(lastContentPresenter, args, contentPresenterLoaded);
}
}
function initPresenters(options, loaded) {
var count = 0;
var subPresenterLoaded = function() {
count ++;
if (count === options.length) {
loaded();
}
};
for (var i = 0; i < options.length; i ++) {
initPresenter(options[i][0], options[i][1], subPresenterLoaded);
}
}
return {
init: init,
2014-09-17 22:37:49 +02:00
initPresenter: initPresenter,
initPresenters: initPresenters,
switchContentPresenter: switchContentPresenter,
showContentSpinner: showContentSpinner,
hideContentSpinner: hideContentSpinner,
};
};
App.DI.registerSingleton('presenterManager', ['jQuery', 'topNavigationPresenter', 'keyboard'], App.PresenterManager);