2014-05-31 04:07:15 +04:00
|
|
|
import PopoverMixin from 'ghost/mixins/popover-mixin';
|
2014-04-07 02:11:22 +04:00
|
|
|
|
2014-05-31 04:07:15 +04:00
|
|
|
var GhostPopover = Ember.Component.extend(PopoverMixin, {
|
2014-09-24 17:36:20 +04:00
|
|
|
classNames: 'ghost-popover',
|
2014-05-31 04:07:15 +04:00
|
|
|
name: null,
|
2014-08-06 18:32:10 +04:00
|
|
|
closeOnClick: false,
|
|
|
|
//Helps track the user re-opening the menu while it's fading out.
|
|
|
|
closing: false,
|
2014-09-24 17:36:20 +04:00
|
|
|
//Helps track whether the popover is open or closes, or in a transition to either
|
|
|
|
isOpen: false,
|
|
|
|
//Managed the toggle between the fade-in and fade-out classes
|
|
|
|
fadeIn: Ember.computed('isOpen', 'closing', function () {
|
|
|
|
return this.get('isOpen') && !this.get('closing');
|
|
|
|
}),
|
|
|
|
|
|
|
|
classNameBindings: ['fadeIn:fade-in-scale:fade-out', 'isOpen:open:closed'],
|
2014-07-01 22:56:02 +04:00
|
|
|
|
|
|
|
open: function () {
|
|
|
|
this.set('isOpen', true);
|
2014-09-24 17:36:20 +04:00
|
|
|
this.set('closing', false);
|
2014-08-06 18:32:10 +04:00
|
|
|
this.set('button.isOpen', true);
|
2014-07-01 22:56:02 +04:00
|
|
|
},
|
|
|
|
close: function () {
|
|
|
|
var self = this;
|
|
|
|
this.set('closing', true);
|
2014-08-06 18:32:10 +04:00
|
|
|
if (this.get('button')) {
|
|
|
|
this.set('button.isOpen', false);
|
|
|
|
}
|
2014-09-24 17:36:20 +04:00
|
|
|
this.$().on('animationend webkitAnimationEnd oanimationend MSAnimationEnd', function (event) {
|
|
|
|
if (event.originalEvent.animationName === 'fade-out') {
|
|
|
|
if (self.get('closing')) {
|
|
|
|
self.set('isOpen', false);
|
|
|
|
self.set('closing', false);
|
|
|
|
}
|
2014-07-01 22:56:02 +04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
//Called by the popover service when any popover button is clicked.
|
|
|
|
toggle: function (options) {
|
|
|
|
var isClosing = this.get('closing'),
|
|
|
|
isOpen = this.get('isOpen'),
|
|
|
|
name = this.get('name'),
|
2014-08-06 18:32:10 +04:00
|
|
|
button = this.get('button'),
|
2014-07-01 22:56:02 +04:00
|
|
|
targetPopoverName = options.target;
|
|
|
|
|
|
|
|
if (name === targetPopoverName && (!isOpen || isClosing)) {
|
2014-08-06 18:32:10 +04:00
|
|
|
if (!button) {
|
|
|
|
button = options.button;
|
|
|
|
this.set('button', button);
|
|
|
|
}
|
2014-07-01 22:56:02 +04:00
|
|
|
this.open();
|
|
|
|
} else if (isOpen) {
|
|
|
|
this.close();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
click: function (event) {
|
|
|
|
this._super(event);
|
|
|
|
if (this.get('closeOnClick')) {
|
|
|
|
return this.close();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2014-05-31 04:07:15 +04:00
|
|
|
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);
|
|
|
|
}
|
2014-04-07 02:11:22 +04:00
|
|
|
});
|
|
|
|
|
2014-09-24 17:36:20 +04:00
|
|
|
export default GhostPopover;
|