2017-05-29 21:50:03 +03:00
|
|
|
import $ from 'jquery';
|
2022-02-03 01:11:11 +03:00
|
|
|
import classic from 'ember-classic-decorator';
|
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-08-22 10:53:26 +03:00
|
|
|
import Evented from '@ember/object/evented';
|
|
|
|
import Service from '@ember/service';
|
2023-01-23 12:47:33 +03:00
|
|
|
import {action} from '@ember/object';
|
2014-09-29 15:17:27 +04:00
|
|
|
|
2022-02-03 01:11:11 +03:00
|
|
|
@classic
|
|
|
|
export default class DropdownService extends 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();
|
|
|
|
}
|
2022-02-03 01:11:11 +03:00
|
|
|
}
|
2015-05-26 05:10:50 +03:00
|
|
|
|
2023-01-23 12:47:33 +03:00
|
|
|
@action
|
2015-10-28 14:36:45 +03:00
|
|
|
closeDropdowns() {
|
2014-09-29 15:17:27 +04:00
|
|
|
this.trigger('close');
|
2022-02-03 01:11:11 +03:00
|
|
|
}
|
2015-05-26 05:10:50 +03:00
|
|
|
|
2023-01-23 12:47:33 +03:00
|
|
|
@action
|
2023-04-04 15:43:43 +03:00
|
|
|
toggleDropdown(dropdownName, dropdownButton, options = {}) {
|
|
|
|
this.trigger('toggle', {target: dropdownName, button: dropdownButton, ...options});
|
2014-09-29 15:17:27 +04:00
|
|
|
}
|
2022-02-03 01:11:11 +03:00
|
|
|
}
|