2017-05-29 21:50:03 +03:00
|
|
|
import $ from 'jquery';
|
2017-04-05 16:08:29 +03:00
|
|
|
// This is used by the dropdown initializer to manage closing & toggling
|
2016-05-24 15:06:59 +03:00
|
|
|
import BodyEventListener from 'ghost-admin/mixins/body-event-listener';
|
2017-05-29 21:50:03 +03:00
|
|
|
import Evented from 'ember-evented';
|
|
|
|
import Service from 'ember-service';
|
2014-09-29 15:17:27 +04:00
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
export default Service.extend(Evented, BodyEventListener, {
|
2017-04-05 17:26:01 +03:00
|
|
|
bodyClick(event) {
|
|
|
|
let dropdownSelector = '.ember-basic-dropdown-trigger, .ember-basic-dropdown-content';
|
|
|
|
|
|
|
|
if ($(event.target).closest(dropdownSelector).length <= 0) {
|
|
|
|
this.closeDropdowns();
|
|
|
|
}
|
2014-09-29 15:17:27 +04:00
|
|
|
},
|
2015-05-26 05:10:50 +03:00
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
closeDropdowns() {
|
2014-09-29 15:17:27 +04:00
|
|
|
this.trigger('close');
|
|
|
|
},
|
2015-05-26 05:10:50 +03:00
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
toggleDropdown(dropdownName, dropdownButton) {
|
2014-09-29 15:17:27 +04:00
|
|
|
this.trigger('toggle', {target: dropdownName, button: dropdownButton});
|
|
|
|
}
|
|
|
|
});
|