1
0
Fork 0
mirror of https://github.com/TryGhost/Ghost-Admin.git synced 2023-12-14 02:33:04 +01:00
Ghost-Admin/mixins/body-event-listener.js
Jason Williams e1666234be Enable JSCS checking on client.
Refs #4001
- grunt-jscs@0.8.1 which provides ES6 support.
2014-10-25 16:13:04 +00:00

47 lines
1.1 KiB
JavaScript

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