mirror of
https://github.com/a2nt/webpack-bootstrap-ui-kit.git
synced 2024-10-22 11:05:45 +02:00
Cookies and Flyout UI demo
This commit is contained in:
parent
caf121ab1c
commit
326d491765
10
src/html/_components/Flyout.html
Normal file
10
src/html/_components/Flyout.html
Normal file
@ -0,0 +1,10 @@
|
||||
<div class="flyout-FlyoutUI">
|
||||
<i class="fas fa-times flyout-FlyoutUI__close"></i>
|
||||
<h2 class="flyout-FlyoutUI__title">
|
||||
<i class="fas fa-asterisk"></i>
|
||||
Flyout Demo
|
||||
</h2>
|
||||
<div class="flyout-FlyoutUI__content typography">
|
||||
<p>Lipsum .... .... ....</p>
|
||||
</div>
|
||||
</div>
|
33
src/js/_components/_ui.cookie.js
Executable file
33
src/js/_components/_ui.cookie.js
Executable file
@ -0,0 +1,33 @@
|
||||
"use strict";
|
||||
|
||||
const CookieUI = (($) => {
|
||||
const D = document;
|
||||
const W = window;
|
||||
|
||||
class CookieUI {
|
||||
static get(name) {
|
||||
return D.cookie.split("; ").reduce((r, v) => {
|
||||
const parts = v.split("=");
|
||||
return parts[0] === name ? decodeURIComponent(parts[1]) : r;
|
||||
}, "");
|
||||
}
|
||||
|
||||
static set(name, value, days = 7, path = "/") {
|
||||
const expires = new Date(Date.now() + days * 864e5).toUTCString();
|
||||
D.cookie =
|
||||
name +
|
||||
"=" +
|
||||
encodeURIComponent(value) +
|
||||
"; expires=" +
|
||||
expires +
|
||||
"; path=" +
|
||||
path;
|
||||
}
|
||||
}
|
||||
|
||||
//W.CookieUI = new CookieUI();
|
||||
|
||||
return CookieUI;
|
||||
})($);
|
||||
|
||||
export default CookieUI;
|
64
src/js/_components/_ui.flyout.js
Executable file
64
src/js/_components/_ui.flyout.js
Executable file
@ -0,0 +1,64 @@
|
||||
"use strict";
|
||||
|
||||
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() {
|
||||
const ui = this;
|
||||
|
||||
ui.$modal = $(`.flyout-${NAME}`);
|
||||
const hide = CookieUI.get(COOKIE);
|
||||
|
||||
if (ui.$modal.length && (!hide || hide !== 'true')) {
|
||||
ui.$modal.data(NAME, ui);
|
||||
|
||||
const $close = ui.$modal.find(`.flyout-${NAME}__close`);
|
||||
|
||||
if ($close.length) {
|
||||
$close.on('click', () => {
|
||||
ui.hide();
|
||||
});
|
||||
}
|
||||
|
||||
setTimeout(() => {
|
||||
ui.show();
|
||||
}, TIMEOUT);
|
||||
}
|
||||
}
|
||||
|
||||
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`);
|
||||
}
|
||||
}
|
||||
|
||||
$(W).on(`${Events.AJAX} ${Events.LOADED}`, () => {
|
||||
FlyoutUI.init();
|
||||
});
|
||||
|
||||
W.FlyoutUI = FlyoutUI;
|
||||
|
||||
return FlyoutUI;
|
||||
})($);
|
||||
|
||||
export default FlyoutUI;
|
34
src/scss/_components/_ui.flyout.scss
Executable file
34
src/scss/_components/_ui.flyout.scss
Executable file
@ -0,0 +1,34 @@
|
||||
$flyout-height-padding: 1rem;
|
||||
$flyout-width-padding: 2rem;
|
||||
$flyout-padding: $flyout-height-padding $flyout-width-padding;
|
||||
$flyout-bg: #000 !default;
|
||||
$flyout-color: #fff !default;
|
||||
$flyout-title-color: #fff !default;
|
||||
$flyout-transition: right 2s;
|
||||
|
||||
.flyout-FlyoutUI {
|
||||
position: absolute;
|
||||
z-index: 99;
|
||||
transform: translateY(-50%);
|
||||
transition: $flyout-transition;
|
||||
right: -100%;
|
||||
top: 50%;
|
||||
background: $flyout-bg;
|
||||
color: $flyout-color;
|
||||
padding: $flyout-padding;
|
||||
|
||||
&__active {
|
||||
display: block;
|
||||
right: 0;
|
||||
}
|
||||
|
||||
&__title {
|
||||
color: $flyout-title-color;
|
||||
}
|
||||
|
||||
&__close {
|
||||
position: absolute;
|
||||
top: $flyout-height-padding;
|
||||
right: $flyout-width-padding;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user