diff --git a/public_html/index.html b/public_html/index.html
index 97c7795f..a09aee8b 100644
--- a/public_html/index.html
+++ b/public_html/index.html
@@ -58,6 +58,7 @@
+
diff --git a/public_html/js/Bootstrap.js b/public_html/js/Bootstrap.js
index dce924b8..aac55f5d 100644
--- a/public_html/js/Bootstrap.js
+++ b/public_html/js/Bootstrap.js
@@ -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._; });
diff --git a/public_html/js/PresenterManager.js b/public_html/js/PresenterManager.js
new file mode 100644
index 00000000..10ec786e
--- /dev/null
+++ b/public_html/js/PresenterManager.js
@@ -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);
diff --git a/public_html/js/Presenters/CommentListPresenter.js b/public_html/js/Presenters/CommentListPresenter.js
index dc1e4d11..ab65b62d 100644
--- a/public_html/js/Presenters/CommentListPresenter.js
+++ b/public_html/js/Presenters/CommentListPresenter.js
@@ -9,6 +9,7 @@ App.Presenters.CommentListPresenter = function(
function init(args) {
topNavigationPresenter.select('comments');
+ topNavigationPresenter.changeTitle('Comments');
render();
}
diff --git a/public_html/js/Presenters/HelpPresenter.js b/public_html/js/Presenters/HelpPresenter.js
index 1978db0d..9f6fcff6 100644
--- a/public_html/js/Presenters/HelpPresenter.js
+++ b/public_html/js/Presenters/HelpPresenter.js
@@ -9,6 +9,7 @@ App.Presenters.HelpPresenter = function(
function init(args) {
topNavigationPresenter.select('help');
+ topNavigationPresenter.changeTitle('Help');
render();
}
diff --git a/public_html/js/Presenters/HomePresenter.js b/public_html/js/Presenters/HomePresenter.js
index 85bf08d2..c550eb8a 100644
--- a/public_html/js/Presenters/HomePresenter.js
+++ b/public_html/js/Presenters/HomePresenter.js
@@ -9,6 +9,7 @@ App.Presenters.HomePresenter = function(
function init(args) {
topNavigationPresenter.select('home');
+ topNavigationPresenter.changeTitle('Home');
render();
}
diff --git a/public_html/js/Presenters/LoginPresenter.js b/public_html/js/Presenters/LoginPresenter.js
index 5bf93e72..edb5068d 100644
--- a/public_html/js/Presenters/LoginPresenter.js
+++ b/public_html/js/Presenters/LoginPresenter.js
@@ -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);
diff --git a/public_html/js/Presenters/LogoutPresenter.js b/public_html/js/Presenters/LogoutPresenter.js
index c3631951..ecd9eac0 100644
--- a/public_html/js/Presenters/LogoutPresenter.js
+++ b/public_html/js/Presenters/LogoutPresenter.js
@@ -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. Back to main page');
diff --git a/public_html/js/Presenters/PostListPresenter.js b/public_html/js/Presenters/PostListPresenter.js
index e62ffae5..bf5ad9b0 100644
--- a/public_html/js/Presenters/PostListPresenter.js
+++ b/public_html/js/Presenters/PostListPresenter.js
@@ -9,6 +9,7 @@ App.Presenters.PostListPresenter = function(
function init(args) {
topNavigationPresenter.select('posts');
+ topNavigationPresenter.changeTitle('Posts');
render();
}
diff --git a/public_html/js/Presenters/PostUploadPresenter.js b/public_html/js/Presenters/PostUploadPresenter.js
index 8949fbec..04e62426 100644
--- a/public_html/js/Presenters/PostUploadPresenter.js
+++ b/public_html/js/Presenters/PostUploadPresenter.js
@@ -9,6 +9,7 @@ App.Presenters.PostUploadPresenter = function(
function init(args) {
topNavigationPresenter.select('upload');
+ topNavigationPresenter.changeTitle('Upload');
render();
}
diff --git a/public_html/js/Presenters/RegistrationPresenter.js b/public_html/js/Presenters/RegistrationPresenter.js
index 16c7b7bc..b96eb444 100644
--- a/public_html/js/Presenters/RegistrationPresenter.js
+++ b/public_html/js/Presenters/RegistrationPresenter.js
@@ -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();
diff --git a/public_html/js/Presenters/TagListPresenter.js b/public_html/js/Presenters/TagListPresenter.js
index 5bb9902e..3cb11590 100644
--- a/public_html/js/Presenters/TagListPresenter.js
+++ b/public_html/js/Presenters/TagListPresenter.js
@@ -9,6 +9,7 @@ App.Presenters.TagListPresenter = function(
function init(args) {
topNavigationPresenter.select('tags');
+ topNavigationPresenter.changeTitle('Tags');
render();
}
diff --git a/public_html/js/Presenters/TopNavigationPresenter.js b/public_html/js/Presenters/TopNavigationPresenter.js
index 2dc099df..011e9de2 100644
--- a/public_html/js/Presenters/TopNavigationPresenter.js
+++ b/public_html/js/Presenters/TopNavigationPresenter.js
@@ -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,
};
};
diff --git a/public_html/js/Presenters/UserActivationPresenter.js b/public_html/js/Presenters/UserActivationPresenter.js
index 55b1d1fb..c1bbcc82 100644
--- a/public_html/js/Presenters/UserActivationPresenter.js
+++ b/public_html/js/Presenters/UserActivationPresenter.js
@@ -20,6 +20,7 @@ App.Presenters.UserActivationPresenter = function(
function init(args) {
topNavigationPresenter.select('login');
+ topNavigationPresenter.changeTitle('Account recovery');
reinit(args);
}
diff --git a/public_html/js/Presenters/UserListPresenter.js b/public_html/js/Presenters/UserListPresenter.js
index 4fe33b74..0499f496 100644
--- a/public_html/js/Presenters/UserListPresenter.js
+++ b/public_html/js/Presenters/UserListPresenter.js
@@ -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);
diff --git a/public_html/js/Presenters/UserPresenter.js b/public_html/js/Presenters/UserPresenter.js
index d224bc4a..0dc0afa3 100644
--- a/public_html/js/Presenters/UserPresenter.js
+++ b/public_html/js/Presenters/UserPresenter.js
@@ -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'),
diff --git a/public_html/js/Router.js b/public_html/js/Router.js
index 533f6554..e920167b 100644
--- a/public_html/js/Router.js
+++ b/public_html/js/Router.js
@@ -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);
diff --git a/public_html/js/Util.js b/public_html/js/Util.js
index a01593f2..609b8448 100644
--- a/public_html/js/Util.js
+++ b/public_html/js/Util.js
@@ -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,