From 972aeac0376a90e7585433afb61f62bdd29837eb Mon Sep 17 00:00:00 2001 From: Jacob Gable Date: Sun, 1 Sep 2013 22:54:19 -0500 Subject: [PATCH] Fix settings back button functionality Added a redirect call to the router instead of defaulting the pane. To handle using the back button after clicking through to other tabs I added an event listener on the route:settings event. --- core/client/router.js | 9 +++++++++ core/client/views/settings.js | 22 +++++++++++++++++++--- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/core/client/router.js b/core/client/router.js index 8451dde349..e6d8f024ad 100644 --- a/core/client/router.js +++ b/core/client/router.js @@ -33,6 +33,15 @@ }, settings: function (pane) { + if (!pane) { + // Redirect to settings/general if no pane supplied + this.navigate('/settings/general', { + trigger: true, + replace: true + }); + return; + } + // only update the currentView if we don't already have a Settings view if (!Ghost.currentView || !(Ghost.currentView instanceof Ghost.Views.Settings)) { Ghost.currentView = new Ghost.Views.Settings({ el: '#main', pane: pane }); diff --git a/core/client/views/settings.js b/core/client/views/settings.js index 92c4886727..3208e032cb 100644 --- a/core/client/views/settings.js +++ b/core/client/views/settings.js @@ -9,11 +9,26 @@ Ghost.Views.Settings = Ghost.View.extend({ initialize: function (options) { $(".settings-content").removeClass('active'); - this.addSubview(new Settings.Sidebar({ + + this.sidebar = new Settings.Sidebar({ el: '.settings-sidebar', pane: options.pane, model: this.model - })); + }); + + this.addSubview(this.sidebar); + + this.listenTo(Ghost.router, "route:settings", this.changePane); + }, + + changePane: function (pane) { + if (!pane) { + // Can happen when trying to load /settings with no pane specified + // let the router navigate itself to /settings/general + return; + } + + this.sidebar.showContent(pane); } }); @@ -23,7 +38,7 @@ initialize: function (options) { this.render(); this.menu = this.$('.settings-menu'); - this.showContent(options.pane || 'general'); + this.showContent(options.pane); }, models: {}, @@ -36,6 +51,7 @@ e.preventDefault(); var item = $(e.currentTarget), id = item.find('a').attr('href').substring(1); + this.showContent(id); },