2018-05-09 12:01:36 +05:30
|
|
|
import $ from 'jquery';
|
2017-08-17 22:00:37 +05:30
|
|
|
import Cookies from 'js-cookie';
|
|
|
|
|
|
|
|
export default class UserCallout {
|
2018-03-17 18:26:18 +05:30
|
|
|
constructor(options = {}) {
|
|
|
|
this.options = options;
|
|
|
|
|
|
|
|
const className = this.options.className || 'user-callout';
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
this.userCalloutBody = $(`.${className}`);
|
|
|
|
this.cookieName = this.userCalloutBody.data('uid');
|
|
|
|
this.isCalloutDismissed = Cookies.get(this.cookieName);
|
2017-08-17 22:00:37 +05:30
|
|
|
this.init();
|
|
|
|
}
|
|
|
|
|
|
|
|
init() {
|
|
|
|
if (!this.isCalloutDismissed || this.isCalloutDismissed === 'false') {
|
2018-11-08 19:23:39 +05:30
|
|
|
this.userCalloutBody.find('.js-close-callout').on('click', e => this.dismissCallout(e));
|
2017-08-17 22:00:37 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
dismissCallout(e) {
|
|
|
|
const $currentTarget = $(e.currentTarget);
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
if (this.options.setCalloutPerProject) {
|
2018-11-08 19:23:39 +05:30
|
|
|
Cookies.set(this.cookieName, 'true', {
|
|
|
|
expires: 365,
|
|
|
|
path: this.userCalloutBody.data('projectPath'),
|
|
|
|
});
|
2018-03-17 18:26:18 +05:30
|
|
|
} else {
|
|
|
|
Cookies.set(this.cookieName, 'true', { expires: 365 });
|
|
|
|
}
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
if ($currentTarget.hasClass('close') || $currentTarget.hasClass('js-close')) {
|
2017-08-17 22:00:37 +05:30
|
|
|
this.userCalloutBody.remove();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|