szurubooru/public_html/js/Presenters/TopNavigationPresenter.js

50 lines
1.1 KiB
JavaScript
Raw Normal View History

2014-08-31 23:22:56 +02:00
var App = App || {};
App.Presenters = App.Presenters || {};
2014-09-04 19:06:12 +02:00
App.Presenters.TopNavigationPresenter = function(
jQuery,
util,
promise,
appState) {
2014-08-31 23:22:56 +02:00
var selectedElement = null;
2014-09-02 23:07:50 +02:00
var $el = jQuery('#top-navigation');
2014-09-02 09:36:42 +02:00
var template;
2014-09-02 23:07:50 +02:00
function init() {
2014-09-04 18:06:25 +02:00
promise.wait(util.promiseTemplate('top-navigation')).then(function(html) {
template = _.template(html);
render();
appState.startObserving('loggedIn', 'top-navigation', loginStateChanged);
});
2014-09-02 23:07:50 +02:00
}
2014-08-31 23:22:56 +02:00
function select(newSelectedElement) {
selectedElement = newSelectedElement;
$el.find('li').removeClass('active');
$el.find('li.' + selectedElement).addClass('active');
};
2014-09-02 23:07:50 +02:00
function loginStateChanged() {
render();
}
2014-08-31 23:22:56 +02:00
function render() {
$el.html(template({
loggedIn: appState.get('loggedIn'),
user: appState.get('loggedInUser'),
2014-09-04 19:57:06 +02:00
privileges: appState.get('privileges'),
}));
2014-08-31 23:22:56 +02:00
$el.find('li.' + selectedElement).addClass('active');
};
return {
init: init,
2014-08-31 23:22:56 +02:00
render: render,
select: select,
};
};
App.DI.registerSingleton('topNavigationPresenter', App.Presenters.TopNavigationPresenter);