diff --git a/app/assets/javascripts/discourse/views/header_view.js b/app/assets/javascripts/discourse/views/header_view.js index 2d25a8a70..3f1b47c9e 100644 --- a/app/assets/javascripts/discourse/views/header_view.js +++ b/app/assets/javascripts/discourse/views/header_view.js @@ -20,7 +20,10 @@ Discourse.HeaderView = Discourse.View.extend({ $html = $('html'), self = this; - self.set('controller.visibleDropdown', elementId); + var controller = self.get('controller'); + if(controller && !controller.isDestroyed){ + controller.set('visibleDropdown', elementId); + } // we need to ensure we are rendered, // this optimises the speed of the initial render var render = $target.data('render'); @@ -38,7 +41,10 @@ Discourse.HeaderView = Discourse.View.extend({ $dropdown.fadeOut('fast'); $li.removeClass('active'); $html.data('hide-dropdown', null); - self.set('controller.visibleDropdown', null); + var controller = self.get('controller'); + if(controller && !controller.isDestroyed){ + controller.set('visibleDropdown', null); + } return $html.off('click.d-dropdown'); }; diff --git a/test/javascripts/integration/header_test.js b/test/javascripts/integration/header_test.js index 897843591..fbecf25e9 100644 --- a/test/javascripts/integration/header_test.js +++ b/test/javascripts/integration/header_test.js @@ -90,10 +90,11 @@ test("sitemap dropdown", function() { Discourse.SiteSettings.faq_url = "faq-url"; Discourse.SiteSettings.enable_mobile_theme = true; - Discourse.User.current.returns({ + Discourse.User.current.returns(Ember.Object.create({ + username: 'test', staff: true, site_flagged_posts_count: 1 - }); + })); Discourse.Category.list.returns([ Discourse.Category.create({