debian-mirror-gitlab/app/assets/javascripts/groups/landing.js

38 lines
976 B
JavaScript
Raw Normal View History

2022-04-04 11:22:00 +05:30
import { getCookie, setCookie, parseBoolean } from '~/lib/utils/common_utils';
2017-08-17 22:00:37 +05:30
class Landing {
constructor(landingElement, dismissButton, cookieName) {
this.landingElement = landingElement;
this.cookieName = cookieName;
this.dismissButton = dismissButton;
this.eventWrapper = {};
}
toggle() {
const isDismissed = this.isDismissed();
this.landingElement.classList.toggle('hidden', isDismissed);
if (!isDismissed) this.addEvents();
}
addEvents() {
this.eventWrapper.dismissLanding = this.dismissLanding.bind(this);
this.dismissButton.addEventListener('click', this.eventWrapper.dismissLanding);
}
removeEvents() {
this.dismissButton.removeEventListener('click', this.eventWrapper.dismissLanding);
}
dismissLanding() {
this.landingElement.classList.add('hidden');
2022-04-04 11:22:00 +05:30
setCookie(this.cookieName, 'true');
2017-08-17 22:00:37 +05:30
}
isDismissed() {
2022-04-04 11:22:00 +05:30
return parseBoolean(getCookie(this.cookieName));
2017-08-17 22:00:37 +05:30
}
}
export default Landing;