1
0
Fork 0
mirror of https://github.com/TryGhost/Ghost-Admin.git synced 2023-12-14 02:33:04 +01:00
Ghost-Admin/app/mixins/body-event-listener.js
Kevin Ansfield 7afb88a0c2 Switch to eslint-plugin-ghost extending plugin:ghost/ember
no issue
- fix lint errors in lib/gh-koenig
- fix ghost:base eslint errors
- update ember plugin refs, remove ember-suave plugin refs
- remove old jshint refs
- add `lint:js` script
- switch to `eslint-plugin-ghost` extending `plugin:ghost/ember`
2018-01-12 12:17:56 +00:00

47 lines
1.1 KiB
JavaScript

import $ from 'jquery';
import Mixin from '@ember/object/mixin';
import {run} from '@ember/runloop';
function K() {
return this;
}
// Code modified from Addepar/ember-widgets
// https://github.com/Addepar/ember-widgets/blob/master/src/mixins.coffee#L39
export default Mixin.create({
bodyElementSelector: 'html',
bodyClick: K,
init() {
this._super(...arguments);
return run.next(this, this._setupDocumentHandlers);
},
willDestroy() {
this._super(...arguments);
return this._removeDocumentHandlers();
},
_setupDocumentHandlers() {
if (this._clickHandler) {
return;
}
this._clickHandler = event => this.bodyClick(event);
return $(this.get('bodyElementSelector')).on('click', this._clickHandler);
},
_removeDocumentHandlers() {
$(this.get('bodyElementSelector')).off('click', this._clickHandler);
this._clickHandler = null;
},
// http://stackoverflow.com/questions/152975/how-to-detect-a-click-outside-an-element
click(event) {
return event.stopPropagation();
}
});