From 7a261e5e4f84f2ff52b85edae77157797be2e4b5 Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Fri, 19 Feb 2016 15:22:41 +0800 Subject: [PATCH] UX: Hide close mobile navigation on click. --- .../discourse/components/mobile-nav.js.es6 | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/app/assets/javascripts/discourse/components/mobile-nav.js.es6 b/app/assets/javascripts/discourse/components/mobile-nav.js.es6 index 939e3010fa4..cee8a2111aa 100644 --- a/app/assets/javascripts/discourse/components/mobile-nav.js.es6 +++ b/app/assets/javascripts/discourse/components/mobile-nav.js.es6 @@ -1,6 +1,9 @@ +import { on, observes } from 'ember-addons/ember-computed-decorators'; + export default Ember.Component.extend({ - _init: function(){ + @on('init') + _init() { if (!this.get('site.mobileView')) { var classes = this.get('desktopClass'); if (classes) { @@ -8,16 +11,17 @@ export default Ember.Component.extend({ this.set('classNames', classes); } } - }.on('init'), + }, tagName: 'ul', classNames: ['mobile-nav'], - currentPathChanged: function(){ + @observes('currentPath') + currentPathChanged() { this.set('expanded', false); Em.run.next(() => this._updateSelectedHtml()); - }.observes('currentPath'), + }, _updateSelectedHtml(){ const active = this.$('.active'); @@ -26,10 +30,22 @@ export default Ember.Component.extend({ } }, - didInsertElement(){ + didInsertElement() { this._updateSelectedHtml(); }, + @on('didInsertElement') + _bindClick() { + this.$().on("click.mobile-nav", 'ul li', () => { + this.set('expanded', false); + }); + }, + + @on('willDestroyElement') + _unbindClick() { + this.$().off("click.mobile-nav", 'ul li'); + }, + actions: { toggleExpanded(){ this.toggleProperty('expanded');