Cookies and Flyout UI demo

This commit is contained in:
Tony Air 2019-11-30 15:29:27 +07:00
parent caf121ab1c
commit 326d491765
4 changed files with 141 additions and 0 deletions

View 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>

View 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;

View 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;

View 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;
}
}