webpack-bootstrap-ui-kit/src/js_old/_components/_ui.flyout.js

70 lines
1.3 KiB
JavaScript
Raw Normal View History

2020-12-24 23:42:33 +01:00
'use strict';
2019-11-30 09:29:27 +01:00
import $ from 'jquery';
import Events from '../_events';
import CookieUI from './_ui.cookie';
const FlyoutUI = (($) => {
const W = window;
const D = document;
const $Body = $('body');
const NAME = 'FlyoutUI';
const COOKIE = `${NAME}-hide`;
const TIMEOUT = 2000;
class FlyoutUI {
static init() {
2020-12-24 23:42:33 +01:00
console.log(`${NAME}: init`);
2019-11-30 09:29:27 +01:00
const ui = this;
ui.$modal = $(`.flyout-${NAME}`);
2019-12-04 12:19:04 +01:00
if (!ui.$modal.length) {
return false;
}
const $close = ui.$modal.find(`.flyout-${NAME}__close`);
ui.$modal.data(NAME, ui);
2019-11-30 09:29:27 +01:00
2019-12-04 12:19:04 +01:00
if ($close.length) {
$close.on('click', () => {
ui.hide();
});
}
2019-11-30 09:29:27 +01:00
2019-12-04 12:19:04 +01:00
const hide = CookieUI.get(COOKIE);
2019-12-04 12:19:04 +01:00
if (!$close.length || !hide || hide !== 'true') {
setTimeout(() => {
ui.show();
}, TIMEOUT);
2019-11-30 09:29:27 +01:00
}
}
static show(callback) {
const ui = this;
ui.$modal.addClass(`flyout-${NAME}__active`);
}
static hide(callback) {
const ui = this;
CookieUI.set(COOKIE, 'true', 1);
ui.$modal.removeClass(`flyout-${NAME}__active`);
}
}
2020-09-09 17:40:58 +02:00
$(W).on(`${NAME}.init ${Events.AJAX} ${Events.LOADED}`, () => {
2019-11-30 09:29:27 +01:00
FlyoutUI.init();
});
W.FlyoutUI = FlyoutUI;
return FlyoutUI;
})($);
export default FlyoutUI;