2018-05-09 12:01:36 +05:30
|
|
|
import $ from 'jquery';
|
2022-04-04 11:22:00 +05:30
|
|
|
import { getCookie, setCookie } from '~/lib/utils/common_utils';
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
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');
|
2022-04-04 11:22:00 +05:30
|
|
|
this.isCalloutDismissed = getCookie(this.cookieName);
|
2017-08-17 22:00:37 +05:30
|
|
|
this.init();
|
|
|
|
}
|
|
|
|
|
|
|
|
init() {
|
|
|
|
if (!this.isCalloutDismissed || this.isCalloutDismissed === 'false') {
|
2021-03-08 18:12:59 +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);
|
2020-06-23 00:09:42 +05:30
|
|
|
const cookieOptions = {};
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
if (!$currentTarget.hasClass('js-close-session')) {
|
|
|
|
cookieOptions.expires = 365;
|
|
|
|
}
|
2018-03-17 18:26:18 +05:30
|
|
|
if (this.options.setCalloutPerProject) {
|
2020-06-23 00:09:42 +05:30
|
|
|
cookieOptions.path = this.userCalloutBody.data('projectPath');
|
2018-03-17 18:26:18 +05:30
|
|
|
}
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
setCookie(this.cookieName, 'true', cookieOptions);
|
2020-06-23 00:09:42 +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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|