debian-mirror-gitlab/app/assets/javascripts/user_callout.js

40 lines
1.1 KiB
JavaScript
Raw Normal View History

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);
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
2020-06-23 00:09:42 +05:30
Cookies.set(this.cookieName, 'true', cookieOptions);
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();
}
}
}