2020-03-13 15:44:24 +05:30
|
|
|
import Vue from 'vue';
|
2022-01-26 12:08:38 +05:30
|
|
|
import Cookies from 'js-cookie';
|
2020-03-13 15:44:24 +05:30
|
|
|
import { parseBoolean } from '~/lib/utils/common_utils';
|
|
|
|
import DismissibleAlert from '~/vue_shared/components/dismissible_alert.vue';
|
|
|
|
|
2022-01-26 12:08:38 +05:30
|
|
|
const getCookieExpirationPeriod = (expirationPeriod) => {
|
|
|
|
const defaultExpirationPeriod = 30;
|
|
|
|
const alertExpirationPeriod = Number(expirationPeriod);
|
|
|
|
|
|
|
|
return !expirationPeriod || Number.isNaN(alertExpirationPeriod)
|
|
|
|
? defaultExpirationPeriod
|
|
|
|
: alertExpirationPeriod;
|
|
|
|
};
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
const mountVueAlert = (el) => {
|
2020-03-13 15:44:24 +05:30
|
|
|
const props = {
|
|
|
|
html: el.innerHTML,
|
|
|
|
};
|
|
|
|
const attrs = {
|
|
|
|
...el.dataset,
|
|
|
|
dismissible: parseBoolean(el.dataset.dismissible),
|
|
|
|
};
|
2022-01-26 12:08:38 +05:30
|
|
|
const { dismissCookieName, dismissCookieExpire } = el.dataset;
|
2020-03-13 15:44:24 +05:30
|
|
|
|
|
|
|
return new Vue({
|
|
|
|
el,
|
2022-01-26 12:08:38 +05:30
|
|
|
render(createElement) {
|
|
|
|
return createElement(DismissibleAlert, {
|
|
|
|
props,
|
|
|
|
attrs,
|
|
|
|
on: {
|
|
|
|
alertDismissed() {
|
|
|
|
if (!dismissCookieName) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Cookies.set(dismissCookieName, true, {
|
|
|
|
expires: getCookieExpirationPeriod(dismissCookieExpire),
|
|
|
|
});
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
2020-03-13 15:44:24 +05:30
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
export default () => [...document.querySelectorAll('.js-vue-alert')].map(mountVueAlert);
|