@madj2k/fe-frontend-kit 2.0.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Overlay (Vanilla JS)
|
|
3
|
+
*
|
|
4
|
+
* A lightweight class to show a full-page overlay (banner, popup, hint or cookie layer),
|
|
5
|
+
* with opening and closing animation and optional cookie persistence.
|
|
6
|
+
*
|
|
7
|
+
* Usage example: cookie notices, teaser banners, welcome layers.
|
|
8
|
+
*
|
|
9
|
+
* The overlay is only shown if no cookie with the given name is set.
|
|
10
|
+
* When the user closes the overlay, a cookie is written to remember this state.
|
|
11
|
+
*
|
|
12
|
+
* Includes customizable CSS classes for transitions and state (active/opening/open/closing).
|
|
13
|
+
*
|
|
14
|
+
* Works without dependencies — ideal for CMS environments (TYPO3, WordPress, etc.).
|
|
15
|
+
*
|
|
16
|
+
* @author Steffen Kroggel <developer@steffenkroggel.de>
|
|
17
|
+
* @copyright 2025 Steffen Kroggel
|
|
18
|
+
* @version 2.0.0
|
|
19
|
+
* @license GNU General Public License v3.0
|
|
20
|
+
* @see https://www.gnu.org/licenses/gpl-3.0.en.html
|
|
21
|
+
*
|
|
22
|
+
*
|
|
23
|
+
* Basic HTML structure:
|
|
24
|
+
*
|
|
25
|
+
* <div id="my-banner" class="my-banner">
|
|
26
|
+
* <div class="my-banner-content">
|
|
27
|
+
* <button id="my-banner-close" class="my-banner-close">Close</button>
|
|
28
|
+
* <p>Your overlay content here ...</p>
|
|
29
|
+
* </div>
|
|
30
|
+
* </div>
|
|
31
|
+
*
|
|
32
|
+
*
|
|
33
|
+
* Example CSS:
|
|
34
|
+
*
|
|
35
|
+
* .my-banner {
|
|
36
|
+
* position: fixed;
|
|
37
|
+
* top: 0;
|
|
38
|
+
* left: 0;
|
|
39
|
+
* width: 100%;
|
|
40
|
+
* height: 100%;
|
|
41
|
+
* background: rgba(0, 0, 0, 0.8);
|
|
42
|
+
* opacity: 0;
|
|
43
|
+
* visibility: hidden;
|
|
44
|
+
* transition: opacity 0.5s ease, visibility 0.5s ease;
|
|
45
|
+
* z-index: 9999;
|
|
46
|
+
* }
|
|
47
|
+
*
|
|
48
|
+
* .my-banner.active {
|
|
49
|
+
* visibility: visible;
|
|
50
|
+
* }
|
|
51
|
+
*
|
|
52
|
+
* .my-banner.open {
|
|
53
|
+
* opacity: 1;
|
|
54
|
+
* }
|
|
55
|
+
*
|
|
56
|
+
* .my-banner.closing {
|
|
57
|
+
* opacity: 0;
|
|
58
|
+
* }
|
|
59
|
+
*
|
|
60
|
+
*
|
|
61
|
+
* Basic usage:
|
|
62
|
+
*
|
|
63
|
+
* const banner = new Madj2kBanner();
|
|
64
|
+
*
|
|
65
|
+
*
|
|
66
|
+
* Advanced usage with config:
|
|
67
|
+
*
|
|
68
|
+
* const overlay = new Madj2kBanner({
|
|
69
|
+
* overlayId: 'my-banner',
|
|
70
|
+
* overlayCloseId: 'my-banner-close',
|
|
71
|
+
* activeClass: 'active',
|
|
72
|
+
* openClass: 'open',
|
|
73
|
+
* closingClass: 'closing',
|
|
74
|
+
* openingClass: 'opening',
|
|
75
|
+
* timeout: 1000,
|
|
76
|
+
* cookieName: 'myOverlayCookie',
|
|
77
|
+
* cookieDays: 30
|
|
78
|
+
* });
|
|
79
|
+
*
|
|
80
|
+
*/
|
|
81
|
+
class Madj2kBanner {
|
|
82
|
+
|
|
83
|
+
config = {
|
|
84
|
+
'overlayId' : 'overlay',
|
|
85
|
+
'overlayCloseId' : 'overlay-close',
|
|
86
|
+
'activeClass': 'active',
|
|
87
|
+
'openClass': 'open',
|
|
88
|
+
'closingClass': 'closing',
|
|
89
|
+
'openingClass': 'opening',
|
|
90
|
+
'timeout': '1000',
|
|
91
|
+
'cookieName': 'overlay',
|
|
92
|
+
'cookieDays': '365'
|
|
93
|
+
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Constructor
|
|
98
|
+
* @param config
|
|
99
|
+
*/
|
|
100
|
+
constructor(config) {
|
|
101
|
+
this.config = {...this.config, ...config }
|
|
102
|
+
this.initOverlay();
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Init overlay if no cookie is set!
|
|
107
|
+
*/
|
|
108
|
+
initOverlay () {
|
|
109
|
+
const overlay = document.getElementById(this.config.overlayId);
|
|
110
|
+
const self = this;
|
|
111
|
+
|
|
112
|
+
if (overlay && ! this.getCookie()) {
|
|
113
|
+
|
|
114
|
+
overlay.classList.add(self.config.activeClass);
|
|
115
|
+
setTimeout(function(){
|
|
116
|
+
overlay.classList.add(self.config.openingClass);
|
|
117
|
+
setTimeout(function(){
|
|
118
|
+
overlay.classList.add(self.config.openClass);
|
|
119
|
+
overlay.classList.remove(self.config.openingClass);
|
|
120
|
+
}, self.config.timeout);
|
|
121
|
+
}, 1 ); // minimum timeout for transitions!
|
|
122
|
+
|
|
123
|
+
const overlayClose = document.getElementById(this.config.overlayCloseId);
|
|
124
|
+
if (overlayClose) {
|
|
125
|
+
overlayClose.addEventListener('click', (ee) => {
|
|
126
|
+
|
|
127
|
+
this.setCookie();
|
|
128
|
+
|
|
129
|
+
overlay.classList.add(self.config.closingClass);
|
|
130
|
+
overlay.classList.remove(self.config.openClass);
|
|
131
|
+
setTimeout(function(){
|
|
132
|
+
overlay.classList.remove(self.config.closingClass);
|
|
133
|
+
overlay.classList.remove(self.config.activeClass);
|
|
134
|
+
}, self.config.timeout);
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Sets cookie
|
|
143
|
+
*/
|
|
144
|
+
setCookie() {
|
|
145
|
+
let d = new Date();
|
|
146
|
+
d.setTime(d.getTime() + (this.config.cookieDays * 24 * 60 * 60 * 1000));
|
|
147
|
+
let expires = "expires=" + d.toUTCString();
|
|
148
|
+
document.cookie = (this.config.cookieName + '=1;' + expires + ';path=/' + '; SameSite=Strict');
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Gets cookie values
|
|
154
|
+
* @returns {string}
|
|
155
|
+
*/
|
|
156
|
+
getCookie() {
|
|
157
|
+
let name = this.config.cookieName + "=";
|
|
158
|
+
let ca = document.cookie.split(';');
|
|
159
|
+
|
|
160
|
+
for (let i = 0; i < ca.length; i++) {
|
|
161
|
+
let c = ca[i];
|
|
162
|
+
while (c.charAt(0) === ' ') {
|
|
163
|
+
c = c.substring(1);
|
|
164
|
+
}
|
|
165
|
+
if (c.indexOf(name) === 0) {
|
|
166
|
+
return c.substring(name.length, c.length);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
return '';
|
|
171
|
+
}
|
|
172
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
.my-banner {
|
|
2
|
+
position: fixed;
|
|
3
|
+
top: 0;
|
|
4
|
+
left: 0;
|
|
5
|
+
width: 100%;
|
|
6
|
+
height: 100%;
|
|
7
|
+
background: rgba(0, 0, 0, 0.8);
|
|
8
|
+
opacity: 0;
|
|
9
|
+
visibility: hidden;
|
|
10
|
+
transition: opacity 0.5s ease, visibility 0.5s ease;
|
|
11
|
+
z-index: 9999;
|
|
12
|
+
|
|
13
|
+
&.active {
|
|
14
|
+
visibility: visible;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
&.open {
|
|
18
|
+
opacity: 1;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
&.closing {
|
|
22
|
+
opacity: 0;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
@forward './banner-2.0.0';
|