gitlab-org--gitlab-foss/app/assets/javascripts/user_callout.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

40 lines
1.1 KiB
JavaScript
Raw Normal View History

import $ from 'jquery';
import { getCookie, setCookie } from '~/lib/utils/common_utils';
2017-02-14 20:49:36 -05:00
2017-03-22 04:26:12 -04:00
export default class UserCallout {
constructor(options = {}) {
this.options = options;
const className = this.options.className || 'user-callout';
this.userCalloutBody = $(`.${className}`);
this.cookieName = this.userCalloutBody.data('uid');
this.isCalloutDismissed = getCookie(this.cookieName);
this.init();
}
2017-02-14 20:49:36 -05:00
init() {
if (!this.isCalloutDismissed || this.isCalloutDismissed === 'false') {
this.userCalloutBody.find('.js-close-callout').on('click', (e) => this.dismissCallout(e));
}
}
dismissCallout(e) {
const $currentTarget = $(e.currentTarget);
const cookieOptions = {};
if (!$currentTarget.hasClass('js-close-session')) {
cookieOptions.expires = 365;
}
if (this.options.setCalloutPerProject) {
cookieOptions.path = this.userCalloutBody.data('projectPath');
}
setCookie(this.cookieName, 'true', cookieOptions);
if ($currentTarget.hasClass('close') || $currentTarget.hasClass('js-close')) {
this.userCalloutBody.remove();
2017-02-14 20:49:36 -05:00
}
}
}