szurubooru/public_html/js/PresenterManager.js

56 lines
1.5 KiB
JavaScript
Raw Normal View History

var App = App || {};
App.PresenterManager = function(jQuery, promise, topNavigationPresenter, keyboard) {
2014-09-17 22:37:49 +02:00
var lastContentPresenter = null;
function init() {
return promise.make(function(resolve, reject) {
initPresenter(topNavigationPresenter, [], resolve);
});
}
2014-09-17 22:37:49 +02:00
function initPresenter(presenter, args, loaded) {
presenter.init.call(presenter, args, loaded);
}
2014-09-17 22:37:49 +02:00
function switchContentPresenter(presenter, args) {
if (lastContentPresenter === null || lastContentPresenter.name !== presenter.name) {
2014-10-02 00:30:25 +02:00
if (lastContentPresenter !== null && lastContentPresenter.deinit) {
lastContentPresenter.deinit();
}
keyboard.reset();
topNavigationPresenter.changeTitle(null);
topNavigationPresenter.focus();
presenter.init.call(presenter, args, function() {});
lastContentPresenter = presenter;
} else if (lastContentPresenter.reinit) {
lastContentPresenter.reinit.call(lastContentPresenter, args, function() {});
2014-09-17 22:37:49 +02:00
}
}
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,
};
};
App.DI.registerSingleton('presenterManager', ['jQuery', 'promise', 'topNavigationPresenter', 'keyboard'], App.PresenterManager);