2014-05-30 18:07:15 -06:00
|
|
|
import PopoverMixin from 'ghost/mixins/popover-mixin';
|
2014-04-06 18:11:22 -04:00
|
|
|
|
2014-05-30 18:07:15 -06:00
|
|
|
var GhostPopover = Ember.Component.extend(PopoverMixin, {
|
|
|
|
classNames: 'ghost-popover fade-in',
|
2014-04-06 18:11:22 -04:00
|
|
|
classNameBindings: ['open'],
|
2014-05-30 18:07:15 -06:00
|
|
|
name: null,
|
|
|
|
closeOnClick: false,
|
|
|
|
didInsertElement: function () {
|
|
|
|
this._super();
|
|
|
|
|
|
|
|
var popoverService = this.get('popover');
|
|
|
|
|
|
|
|
popoverService.on('close', this, this.close);
|
|
|
|
popoverService.on('toggle', this, this.toggle);
|
|
|
|
},
|
|
|
|
willDestroyElement: function () {
|
|
|
|
this._super();
|
|
|
|
var popoverService = this.get('popover');
|
|
|
|
|
|
|
|
popoverService.off('close', this, this.close);
|
|
|
|
popoverService.off('toggle', this, this.toggle);
|
|
|
|
},
|
|
|
|
click: function (event) {
|
|
|
|
this._super(event);
|
|
|
|
if (this.get('closeOnClick')) {
|
|
|
|
return this.close();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
close: function () {
|
|
|
|
return this.set('open', false);
|
|
|
|
},
|
|
|
|
toggle: function (options) {
|
|
|
|
/*
|
|
|
|
Close all popovers whose button was not clicked,
|
|
|
|
and toggle the actual target.
|
|
|
|
*/
|
|
|
|
var targetPopoverName = options.target;
|
|
|
|
if (this.get('name') === targetPopoverName) {
|
|
|
|
this.toggleProperty('open');
|
|
|
|
} else {
|
|
|
|
this.close();
|
|
|
|
}
|
|
|
|
}
|
2014-04-06 18:11:22 -04:00
|
|
|
});
|
|
|
|
|
2014-05-30 18:07:15 -06:00
|
|
|
export default GhostPopover;
|