2015-02-13 07:22:32 +03:00
|
|
|
import Ember from 'ember';
|
2014-09-16 08:55:37 +04:00
|
|
|
import mobileQuery from 'ghost/utils/mobile';
|
2014-09-01 20:45:06 +04:00
|
|
|
|
2014-07-07 18:55:22 +04:00
|
|
|
var ApplicationView = Ember.View.extend({
|
2014-09-15 04:40:24 +04:00
|
|
|
elementId: 'container',
|
|
|
|
|
2015-02-18 20:11:02 +03:00
|
|
|
didInsertElement: function () {
|
2014-07-07 18:55:22 +04:00
|
|
|
// #### Navigating within the sidebar closes it.
|
2014-09-01 20:45:06 +04:00
|
|
|
var self = this;
|
2015-02-18 20:11:02 +03:00
|
|
|
|
2014-09-25 20:33:47 +04:00
|
|
|
$('body').on('click tap', '.js-nav-item', function () {
|
2015-02-18 20:11:02 +03:00
|
|
|
Ember.run(function () {
|
|
|
|
if (mobileQuery.matches) {
|
|
|
|
self.set('controller.showGlobalMobileNav', false);
|
|
|
|
}
|
|
|
|
});
|
2014-07-07 18:55:22 +04:00
|
|
|
});
|
2014-09-01 20:45:06 +04:00
|
|
|
|
|
|
|
// #### Close the nav if mobile and clicking outside of the nav or not the burger toggle
|
2014-09-25 20:33:47 +04:00
|
|
|
$('.js-nav-cover').on('click tap', function () {
|
2015-02-18 20:11:02 +03:00
|
|
|
Ember.run(function () {
|
|
|
|
var isOpen = self.get('controller.showGlobalMobileNav');
|
|
|
|
|
|
|
|
if (isOpen) {
|
|
|
|
self.set('controller.showGlobalMobileNav', false);
|
|
|
|
}
|
|
|
|
});
|
2014-09-01 20:45:06 +04:00
|
|
|
});
|
|
|
|
|
|
|
|
// #### Listen to the viewport and change user-menu dropdown triangle classes accordingly
|
2015-02-18 20:11:02 +03:00
|
|
|
this.set('swapUserMenuDropdownTriangleClasses', Ember.run.bind(this, swapUserMenuDropdownTriangleClasses));
|
2014-09-01 20:45:06 +04:00
|
|
|
|
2015-02-18 20:11:02 +03:00
|
|
|
mobileQuery.addListener(this.get('swapUserMenuDropdownTriangleClasses'));
|
|
|
|
swapUserMenuDropdownTriangleClasses(mobileQuery);
|
|
|
|
|
|
|
|
this.set('closeGlobalMobileNavOnDesktop', Ember.run.bind(this, function closeGlobalMobileNavOnDesktop(mq) {
|
|
|
|
if (!mq.matches) {
|
|
|
|
// Is desktop sized
|
|
|
|
this.set('controller.showGlobalMobileNav', false);
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
|
|
|
|
mobileQuery.addListener(this.get('closeGlobalMobileNavOnDesktop'));
|
2014-09-01 20:45:06 +04:00
|
|
|
},
|
2014-09-16 08:55:37 +04:00
|
|
|
|
2014-09-01 20:45:06 +04:00
|
|
|
showGlobalMobileNavObserver: function () {
|
|
|
|
if (this.get('controller.showGlobalMobileNav')) {
|
|
|
|
$('body').addClass('global-nav-expanded');
|
|
|
|
} else {
|
|
|
|
$('body').removeClass('global-nav-expanded');
|
2014-08-11 00:50:25 +04:00
|
|
|
}
|
2014-09-01 20:45:06 +04:00
|
|
|
}.observes('controller.showGlobalMobileNav'),
|
|
|
|
|
2015-02-18 20:11:02 +03:00
|
|
|
willDestroyElement: function () {
|
|
|
|
mobileQuery.removeListener(this.get('closeGlobalMobileNavOnDesktop'));
|
|
|
|
mobileQuery.removeListener(this.get('swapUserMenuDropdownTriangleClasses'));
|
|
|
|
},
|
2014-09-01 20:45:06 +04:00
|
|
|
|
2014-10-13 19:23:06 +04:00
|
|
|
toggleSettingsMenuBodyClass: function () {
|
|
|
|
$('body').toggleClass('settings-menu-expanded', this.get('controller.showSettingsMenu'));
|
|
|
|
}.observes('controller.showSettingsMenu')
|
2014-07-07 18:55:22 +04:00
|
|
|
});
|
|
|
|
|
|
|
|
export default ApplicationView;
|