2017-08-22 10:53:26 +03:00
|
|
|
import Component from '@ember/component';
|
|
|
|
import {computed} from '@ember/object';
|
|
|
|
import {isBlank} from '@ember/utils';
|
|
|
|
import {reads} from '@ember/object/computed';
|
|
|
|
import {run} from '@ember/runloop';
|
2017-10-30 12:38:01 +03:00
|
|
|
import {inject as service} from '@ember/service';
|
2017-06-08 18:00:10 +03:00
|
|
|
|
|
|
|
let instancesCounter = 0;
|
|
|
|
|
|
|
|
let triangleClassPositions = {
|
|
|
|
'top-left': {
|
|
|
|
attachment: 'top left',
|
|
|
|
targetAttachment: 'bottom center',
|
|
|
|
offset: '0 28px'
|
|
|
|
},
|
2018-01-05 18:38:23 +03:00
|
|
|
top: {
|
2017-06-08 18:00:10 +03:00
|
|
|
attachment: 'top center',
|
|
|
|
targetAttachment: 'bottom center'
|
|
|
|
},
|
|
|
|
'top-right': {
|
|
|
|
attachment: 'top right',
|
|
|
|
targetAttachment: 'bottom center',
|
|
|
|
offset: '0 -28px'
|
|
|
|
},
|
|
|
|
'right-top': {
|
|
|
|
attachment: 'top right',
|
|
|
|
targetAttachment: 'middle left',
|
|
|
|
offset: '28px 0'
|
|
|
|
},
|
2018-01-05 18:38:23 +03:00
|
|
|
right: {
|
2017-06-08 18:00:10 +03:00
|
|
|
attachment: 'middle right',
|
|
|
|
targetAttachment: 'middle left'
|
|
|
|
},
|
|
|
|
'right-bottom': {
|
|
|
|
attachment: 'bottom right',
|
|
|
|
targetAttachment: 'middle left',
|
|
|
|
offset: '-28px 0'
|
|
|
|
},
|
|
|
|
'bottom-right': {
|
|
|
|
attachment: 'bottom right',
|
|
|
|
targetAttachment: 'top center',
|
|
|
|
offset: '0 -28px'
|
|
|
|
},
|
2018-01-05 18:38:23 +03:00
|
|
|
bottom: {
|
2017-06-08 18:00:10 +03:00
|
|
|
attachment: 'bottom center',
|
|
|
|
targetAttachment: 'top center'
|
|
|
|
},
|
|
|
|
'bottom-left': {
|
|
|
|
attachment: 'bottom left',
|
|
|
|
targetAttachment: 'top center',
|
|
|
|
offset: '0 28px'
|
|
|
|
},
|
|
|
|
'left-bottom': {
|
|
|
|
attachment: 'bottom left',
|
|
|
|
targetAttachment: 'middle right',
|
|
|
|
offset: '-28px 0'
|
|
|
|
},
|
2018-01-05 18:38:23 +03:00
|
|
|
left: {
|
2017-06-08 18:00:10 +03:00
|
|
|
attachment: 'middle left',
|
|
|
|
targetAttachment: 'middle right'
|
|
|
|
},
|
|
|
|
'left-top': {
|
|
|
|
attachment: 'top left',
|
|
|
|
targetAttachment: 'middle right',
|
|
|
|
offset: '28px 0'
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const GhTourItemComponent = Component.extend({
|
|
|
|
|
2017-10-30 12:38:01 +03:00
|
|
|
mediaQueries: service(),
|
|
|
|
tour: service(),
|
2021-02-09 14:43:44 +03:00
|
|
|
ui: service(),
|
2017-06-08 18:00:10 +03:00
|
|
|
|
|
|
|
tagName: '',
|
|
|
|
|
|
|
|
throbberId: null,
|
|
|
|
target: null,
|
|
|
|
throbberAttachment: 'middle center',
|
|
|
|
popoverTriangleClass: 'top',
|
|
|
|
isOpen: false,
|
|
|
|
|
|
|
|
_elementId: null,
|
|
|
|
_throbber: null,
|
|
|
|
_throbberElementId: null,
|
|
|
|
_throbberElementSelector: null,
|
|
|
|
_popoverAttachment: null,
|
|
|
|
_popoverTargetAttachment: null,
|
|
|
|
_popoverOffset: null,
|
|
|
|
|
|
|
|
isMobile: reads('mediaQueries.isMobile'),
|
2021-02-09 14:43:44 +03:00
|
|
|
isVisible: computed('isMobile', '_throbber', 'ui.showTour', function () {
|
|
|
|
let showTour = this.ui.showTour;
|
2019-03-06 16:53:54 +03:00
|
|
|
let isMobile = this.isMobile;
|
|
|
|
let hasThrobber = !isBlank(this._throbber);
|
2017-06-08 18:00:10 +03:00
|
|
|
|
2021-02-09 14:43:44 +03:00
|
|
|
return showTour && !isMobile && hasThrobber;
|
2017-06-08 18:00:10 +03:00
|
|
|
}),
|
|
|
|
|
|
|
|
init() {
|
|
|
|
this._super(...arguments);
|
|
|
|
// this is a tagless component so we need to generate our own elementId
|
2018-01-05 18:38:23 +03:00
|
|
|
this._elementId = instancesCounter += 1;
|
2017-06-08 18:00:10 +03:00
|
|
|
this._throbberElementId = `throbber-${this._elementId}`;
|
|
|
|
this._throbberElementSelector = `#throbber-${this._elementId}`;
|
|
|
|
|
|
|
|
this._handleOptOut = run.bind(this, this._remove);
|
|
|
|
this._handleViewed = run.bind(this, this._removeIfViewed);
|
|
|
|
|
2019-03-06 16:53:54 +03:00
|
|
|
this.tour.on('optOut', this._handleOptOut);
|
|
|
|
this.tour.on('viewed', this._handleViewed);
|
2017-06-08 18:00:10 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
didReceiveAttrs() {
|
2019-03-06 16:53:54 +03:00
|
|
|
let throbberId = this.throbberId;
|
|
|
|
let throbber = this.tour.activeThrobber(throbberId);
|
|
|
|
let triangleClass = this.popoverTriangleClass;
|
2017-06-08 18:00:10 +03:00
|
|
|
let popoverPositions = triangleClassPositions[triangleClass];
|
|
|
|
|
|
|
|
this._throbber = throbber;
|
|
|
|
this._popoverAttachment = popoverPositions.attachment;
|
|
|
|
this._popoverTargetAttachment = popoverPositions.targetAttachment;
|
|
|
|
this._popoverOffset = popoverPositions.offset;
|
|
|
|
},
|
|
|
|
|
|
|
|
willDestroyElement() {
|
2019-03-06 16:53:54 +03:00
|
|
|
this.tour.off('optOut', this._handleOptOut);
|
|
|
|
this.tour.off('viewed', this._handleViewed);
|
2017-07-10 15:15:20 +03:00
|
|
|
this._super(...arguments);
|
2017-06-08 18:00:10 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
actions: {
|
|
|
|
open() {
|
|
|
|
this.set('isOpen', true);
|
|
|
|
},
|
|
|
|
|
|
|
|
close() {
|
|
|
|
this._close();
|
|
|
|
},
|
|
|
|
|
|
|
|
markAsViewed() {
|
2019-03-06 16:53:54 +03:00
|
|
|
let throbberId = this.throbberId;
|
|
|
|
this.tour.markThrobberAsViewed(throbberId);
|
2017-06-08 18:00:10 +03:00
|
|
|
this.set('_throbber', null);
|
|
|
|
this._close();
|
|
|
|
},
|
|
|
|
|
|
|
|
optOut() {
|
2019-03-06 16:53:54 +03:00
|
|
|
this.tour.optOut();
|
2017-06-08 18:00:10 +03:00
|
|
|
this.set('_throbber', null);
|
|
|
|
this._close();
|
|
|
|
}
|
2018-01-11 20:43:23 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
_removeIfViewed(id) {
|
2019-03-06 16:53:54 +03:00
|
|
|
if (id === this.throbberId) {
|
2018-01-11 20:43:23 +03:00
|
|
|
this._remove();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_remove() {
|
|
|
|
this.set('_throbber', null);
|
|
|
|
},
|
|
|
|
|
|
|
|
_close() {
|
|
|
|
this.set('isOpen', false);
|
2017-06-08 18:00:10 +03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
export default GhTourItemComponent;
|