FIX: collapse mobile nav on outside click

This commit is contained in:
Sam 2017-05-12 13:15:04 -04:00
parent 3113a6a18a
commit b92b654ea3
2 changed files with 16 additions and 13 deletions

View File

@ -35,21 +35,24 @@ export default Ember.Component.extend({
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');
Em.run.next(()=>{
if (this.get('expanded')) {
$(window)
.off("click.mobile-nav")
.on("click.mobile-nav", (e) => {
let expander = this.$('.expander');
expander = expander && expander[0];
if ($(e.target)[0] !== expander) {
this.set('expanded', false);
$(window).off("click.mobile-nav");
}
});
}
});
}
}
});

View File

@ -1,5 +1,5 @@
{{#if selectedHtml}}
<li><a {{action 'toggleExpanded'}}>{{{selectedHtml}}} <i class='fa fa-caret-down'></i></a></li>
<li><a class='expander' {{action 'toggleExpanded'}}>{{{selectedHtml}}} <i class='fa fa-caret-down'></i></a></li>
{{/if}}
<ul class='drop {{if expanded 'expanded'}}'>
{{yield}}