2018-03-09 20:18:59 +00:00
|
|
|
import $ from 'jquery';
|
2017-03-11 06:45:34 +00:00
|
|
|
import Cookies from 'js-cookie';
|
2017-02-15 01:49:36 +00:00
|
|
|
|
2017-03-22 08:26:12 +00:00
|
|
|
export default class UserCallout {
|
2017-09-05 11:04:19 +00:00
|
|
|
constructor(options = {}) {
|
|
|
|
this.options = options;
|
|
|
|
|
|
|
|
const className = this.options.className || 'user-callout';
|
|
|
|
|
2017-05-24 10:25:44 +00:00
|
|
|
this.userCalloutBody = $(`.${className}`);
|
|
|
|
this.cookieName = this.userCalloutBody.data('uid');
|
|
|
|
this.isCalloutDismissed = Cookies.get(this.cookieName);
|
2017-02-17 17:28:52 +00:00
|
|
|
this.init();
|
|
|
|
}
|
2017-02-15 01:49:36 +00:00
|
|
|
|
2017-02-17 17:28:52 +00:00
|
|
|
init() {
|
2017-02-23 21:23:33 +00:00
|
|
|
if (!this.isCalloutDismissed || this.isCalloutDismissed === 'false') {
|
2020-12-23 21:10:24 +00:00
|
|
|
this.userCalloutBody.find('.js-close-callout').on('click', (e) => this.dismissCallout(e));
|
2017-02-23 21:23:33 +00:00
|
|
|
}
|
2017-02-17 17:28:52 +00:00
|
|
|
}
|
2017-02-16 22:02:40 +00:00
|
|
|
|
2017-02-23 21:23:33 +00:00
|
|
|
dismissCallout(e) {
|
|
|
|
const $currentTarget = $(e.currentTarget);
|
2020-06-04 12:08:21 +00:00
|
|
|
const cookieOptions = {};
|
2017-03-24 12:41:42 +00:00
|
|
|
|
2020-06-04 12:08:21 +00:00
|
|
|
if (!$currentTarget.hasClass('js-close-session')) {
|
|
|
|
cookieOptions.expires = 365;
|
|
|
|
}
|
2017-09-05 11:04:19 +00:00
|
|
|
if (this.options.setCalloutPerProject) {
|
2020-06-04 12:08:21 +00:00
|
|
|
cookieOptions.path = this.userCalloutBody.data('projectPath');
|
2017-09-05 11:04:19 +00:00
|
|
|
}
|
2017-03-24 12:41:42 +00:00
|
|
|
|
2020-06-04 12:08:21 +00:00
|
|
|
Cookies.set(this.cookieName, 'true', cookieOptions);
|
|
|
|
|
2018-05-11 10:41:37 +00:00
|
|
|
if ($currentTarget.hasClass('close') || $currentTarget.hasClass('js-close')) {
|
2017-03-02 21:10:39 +00:00
|
|
|
this.userCalloutBody.remove();
|
2017-02-15 01:49:36 +00:00
|
|
|
}
|
|
|
|
}
|
2017-02-17 17:28:52 +00:00
|
|
|
}
|