mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
57 lines
1.4 KiB
JavaScript
57 lines
1.4 KiB
JavaScript
export default Ember.Component.extend({
|
|
tagName: 'ul',
|
|
classNameBindings: [':nav', ':nav-pills'],
|
|
id: 'navigation-bar',
|
|
selectedNavItem: function(){
|
|
const filterMode = this.get('filterMode'),
|
|
navItems = this.get('navItems');
|
|
|
|
var item = navItems.find(function(item){
|
|
return item.get('filterMode').indexOf(filterMode) === 0;
|
|
});
|
|
|
|
return item || navItems[0];
|
|
}.property('filterMode'),
|
|
|
|
closedNav: function(){
|
|
if (!this.get('expanded')) {
|
|
this.ensureDropClosed();
|
|
}
|
|
}.observes('expanded'),
|
|
|
|
ensureDropClosed: function(){
|
|
if (!this.get('expanded')) {
|
|
this.set('expanded',false);
|
|
}
|
|
$(window).off('click.navigation-bar');
|
|
Discourse.URL.appEvents.off('dom:clean', this, this.ensureDropClosed);
|
|
},
|
|
|
|
actions: {
|
|
toggleDrop: function(){
|
|
this.set('expanded', !this.get('expanded'));
|
|
var self = this;
|
|
if (this.get('expanded')) {
|
|
|
|
Discourse.URL.appEvents.on('dom:clean', this, this.ensureDropClosed);
|
|
|
|
Em.run.next(function() {
|
|
|
|
if (!self.get('expanded')) { return; }
|
|
|
|
self.$('.drop a').on('click', function(){
|
|
self.$('.drop').hide();
|
|
self.set('expanded', false);
|
|
return true;
|
|
});
|
|
|
|
$(window).on('click.navigation-bar', function() {
|
|
self.set('expanded', false);
|
|
return true;
|
|
});
|
|
});
|
|
}
|
|
}
|
|
}
|
|
});
|