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