Added page title management (closed #33)
This commit is contained in:
parent
2bb20c49fd
commit
c1739d1d1d
18 changed files with 65 additions and 26 deletions
|
@ -58,6 +58,7 @@
|
|||
<script type="text/javascript" src="/js/Util.js"></script>
|
||||
<script type="text/javascript" src="/js/BrowsingSettings.js"></script>
|
||||
<script type="text/javascript" src="/js/Controls/FileDropper.js"></script>
|
||||
<script type="text/javascript" src="/js/PresenterManager.js"></script>
|
||||
<script type="text/javascript" src="/js/Presenters/TopNavigationPresenter.js"></script>
|
||||
<script type="text/javascript" src="/js/Presenters/PagedCollectionPresenter.js"></script>
|
||||
<script type="text/javascript" src="/js/Presenters/LoginPresenter.js"></script>
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
var App = App || {};
|
||||
|
||||
App.Bootstrap = function(auth, router, util, promise) {
|
||||
App.Bootstrap = function(auth, router, util, promise, presenterManager) {
|
||||
|
||||
util.initPresenter('topNavigationPresenter');
|
||||
presenterManager.init();
|
||||
|
||||
promise.wait(auth.tryLoginFromCookie())
|
||||
.then(startRouting)
|
||||
|
@ -25,7 +25,7 @@ App.Bootstrap = function(auth, router, util, promise) {
|
|||
|
||||
};
|
||||
|
||||
App.DI.registerSingleton('bootstrap', ['auth', 'router', 'util', 'promise'], App.Bootstrap);
|
||||
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.Path; });
|
||||
App.DI.registerManual('_', function() { return window._; });
|
||||
|
|
36
public_html/js/PresenterManager.js
Normal file
36
public_html/js/PresenterManager.js
Normal file
|
@ -0,0 +1,36 @@
|
|||
var App = App || {};
|
||||
|
||||
App.PresenterManager = function(topNavigationPresenter) {
|
||||
|
||||
var lastContentPresenterName;
|
||||
var lastContentPresenter;
|
||||
|
||||
function init() {
|
||||
initPresenter('topNavigationPresenter');
|
||||
}
|
||||
|
||||
function initPresenter(presenterName, args) {
|
||||
var presenter = App.DI.get(presenterName);
|
||||
presenter.init.call(presenter, args);
|
||||
}
|
||||
|
||||
function switchContentPresenter(presenterName, args) {
|
||||
if (lastContentPresenterName !== presenterName) {
|
||||
topNavigationPresenter.changeTitle(null);
|
||||
var presenter = App.DI.get(presenterName);
|
||||
presenter.init.call(presenter, args);
|
||||
lastContentPresenterName = presenterName;
|
||||
lastContentPresenter = presenter;
|
||||
} else if (lastContentPresenter.reinit) {
|
||||
lastContentPresenter.reinit.call(lastContentPresenter, args);
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
init: init,
|
||||
switchContentPresenter: switchContentPresenter,
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
App.DI.registerSingleton('presenterManager', ['topNavigationPresenter'], App.PresenterManager);
|
|
@ -9,6 +9,7 @@ App.Presenters.CommentListPresenter = function(
|
|||
|
||||
function init(args) {
|
||||
topNavigationPresenter.select('comments');
|
||||
topNavigationPresenter.changeTitle('Comments');
|
||||
render();
|
||||
}
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ App.Presenters.HelpPresenter = function(
|
|||
|
||||
function init(args) {
|
||||
topNavigationPresenter.select('help');
|
||||
topNavigationPresenter.changeTitle('Help');
|
||||
render();
|
||||
}
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ App.Presenters.HomePresenter = function(
|
|||
|
||||
function init(args) {
|
||||
topNavigationPresenter.select('home');
|
||||
topNavigationPresenter.changeTitle('Home');
|
||||
render();
|
||||
}
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@ App.Presenters.LoginPresenter = function(
|
|||
|
||||
function init(args) {
|
||||
topNavigationPresenter.select('login');
|
||||
topNavigationPresenter.changeTitle('Login');
|
||||
previousRoute = args.previousRoute;
|
||||
promise.wait(util.promiseTemplate('login-form')).then(function(html) {
|
||||
template = _.template(html);
|
||||
|
|
|
@ -13,6 +13,7 @@ App.Presenters.LogoutPresenter = function(
|
|||
|
||||
function init() {
|
||||
topNavigationPresenter.select('logout');
|
||||
topNavigationPresenter.changeTitle('Logout');
|
||||
promise.wait(auth.logout()).then(function() {
|
||||
$messages.empty();
|
||||
var $messageDiv = messagePresenter.showInfo($messages, 'Logged out. <a href="">Back to main page</a>');
|
||||
|
|
|
@ -9,6 +9,7 @@ App.Presenters.PostListPresenter = function(
|
|||
|
||||
function init(args) {
|
||||
topNavigationPresenter.select('posts');
|
||||
topNavigationPresenter.changeTitle('Posts');
|
||||
render();
|
||||
}
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ App.Presenters.PostUploadPresenter = function(
|
|||
|
||||
function init(args) {
|
||||
topNavigationPresenter.select('upload');
|
||||
topNavigationPresenter.changeTitle('Upload');
|
||||
render();
|
||||
}
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@ App.Presenters.RegistrationPresenter = function(
|
|||
|
||||
function init() {
|
||||
topNavigationPresenter.select('register');
|
||||
topNavigationPresenter.changeTitle('Registration');
|
||||
promise.wait(util.promiseTemplate('registration-form')).then(function(html) {
|
||||
template = _.template(html);
|
||||
render();
|
||||
|
|
|
@ -9,6 +9,7 @@ App.Presenters.TagListPresenter = function(
|
|||
|
||||
function init(args) {
|
||||
topNavigationPresenter.select('tags');
|
||||
topNavigationPresenter.changeTitle('Tags');
|
||||
render();
|
||||
}
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ App.Presenters.TopNavigationPresenter = function(
|
|||
var selectedElement = null;
|
||||
var $el = jQuery('#top-navigation');
|
||||
var template;
|
||||
var baseTitle = document.title;
|
||||
|
||||
function init() {
|
||||
promise.wait(util.promiseTemplate('top-navigation')).then(function(html) {
|
||||
|
@ -44,10 +45,19 @@ App.Presenters.TopNavigationPresenter = function(
|
|||
$el.find('li.' + selectedElement).addClass('active');
|
||||
}
|
||||
|
||||
function changeTitle(subTitle) {
|
||||
var newTitle = baseTitle;
|
||||
if (subTitle) {
|
||||
newTitle += ' - ' + subTitle;
|
||||
}
|
||||
document.title = newTitle;
|
||||
}
|
||||
|
||||
return {
|
||||
init: init,
|
||||
render: render,
|
||||
select: select,
|
||||
changeTitle: changeTitle,
|
||||
};
|
||||
|
||||
};
|
||||
|
|
|
@ -20,6 +20,7 @@ App.Presenters.UserActivationPresenter = function(
|
|||
|
||||
function init(args) {
|
||||
topNavigationPresenter.select('login');
|
||||
topNavigationPresenter.changeTitle('Account recovery');
|
||||
reinit(args);
|
||||
}
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@ App.Presenters.UserListPresenter = function(
|
|||
|
||||
function init(args) {
|
||||
topNavigationPresenter.select('users');
|
||||
topNavigationPresenter.changeTitle('Users');
|
||||
|
||||
promise.wait(util.promiseTemplate('user-list')).then(function(html) {
|
||||
template = _.template(html);
|
||||
|
|
|
@ -24,6 +24,7 @@ App.Presenters.UserPresenter = function(
|
|||
function init(args) {
|
||||
userName = args.userName;
|
||||
topNavigationPresenter.select(auth.isLoggedIn(userName) ? 'my-account' : 'users');
|
||||
topNavigationPresenter.changeTitle(userName);
|
||||
|
||||
promise.waitAll(
|
||||
util.promiseTemplate('user'),
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
var App = App || {};
|
||||
|
||||
App.Router = function(pathJs, _, jQuery, util, appState) {
|
||||
App.Router = function(pathJs, _, jQuery, util, appState, presenterManager) {
|
||||
|
||||
var root = '#/';
|
||||
|
||||
|
@ -47,7 +47,7 @@ App.Router = function(pathJs, _, jQuery, util, appState) {
|
|||
additionalParams,
|
||||
{previousRoute: pathJs.routes.previous});
|
||||
|
||||
util.initContentPresenter( presenterName, finalParams);
|
||||
presenterManager.switchContentPresenter( presenterName, finalParams);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -59,4 +59,4 @@ App.Router = function(pathJs, _, jQuery, util, appState) {
|
|||
|
||||
};
|
||||
|
||||
App.DI.registerSingleton('router', ['pathJs', '_', 'jQuery', 'util', 'appState'], App.Router);
|
||||
App.DI.registerSingleton('router', ['pathJs', '_', 'jQuery', 'util', 'appState', 'presenterManager'], App.Router);
|
||||
|
|
|
@ -3,8 +3,6 @@ var App = App || {};
|
|||
App.Util = function(_, jQuery, promise) {
|
||||
|
||||
var templateCache = {};
|
||||
var lastContentPresenterName;
|
||||
var lastContentPresenter;
|
||||
|
||||
function parseComplexRouteArgs(args) {
|
||||
var result = {};
|
||||
|
@ -32,22 +30,6 @@ App.Util = function(_, jQuery, promise) {
|
|||
return result;
|
||||
}
|
||||
|
||||
function initPresenter(presenterName, args) {
|
||||
var presenter = App.DI.get(presenterName);
|
||||
presenter.init.call(presenter, args);
|
||||
}
|
||||
|
||||
function initContentPresenter(presenterName, args) {
|
||||
if (lastContentPresenterName !== presenterName) {
|
||||
var presenter = App.DI.get(presenterName);
|
||||
presenter.init.call(presenter, args);
|
||||
lastContentPresenterName = presenterName;
|
||||
lastContentPresenter = presenter;
|
||||
} else if (lastContentPresenter.reinit) {
|
||||
lastContentPresenter.reinit.call(lastContentPresenter, args);
|
||||
}
|
||||
}
|
||||
|
||||
function promiseTemplate(templateName) {
|
||||
return promiseTemplateFromCache(templateName) ||
|
||||
promiseTemplateFromDOM(templateName) ||
|
||||
|
@ -151,8 +133,6 @@ App.Util = function(_, jQuery, promise) {
|
|||
|
||||
return {
|
||||
promiseTemplate: promiseTemplate,
|
||||
initPresenter : initPresenter,
|
||||
initContentPresenter: initContentPresenter,
|
||||
parseComplexRouteArgs: parseComplexRouteArgs,
|
||||
compileComplexRouteArgs: compileComplexRouteArgs,
|
||||
formatRelativeTime: formatRelativeTime,
|
||||
|
|
Loading…
Reference in a new issue