@madj2k/fe-frontend-kit 2.0.35 → 2.0.37

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.
@@ -7,7 +7,7 @@
7
7
  *
8
8
  * @author Steffen Kroggel <developer@steffenkroggel.de>
9
9
  * @copyright 2025 Steffen Kroggel
10
- * @version 2.0.1
10
+ * @version 2.0.2
11
11
  * @license GNU General Public License v3.0
12
12
  * @see https://www.gnu.org/licenses/gpl-3.0.en.html
13
13
  *
@@ -51,9 +51,13 @@ class Madj2kFlyoutMenu {
51
51
  menuInnerClass: "js-flyout-inner",
52
52
  heightCalculationClass: 'calculate',
53
53
  heightMode: 'full',
54
+ eventMode: 'click',
55
+ eventModeOpen: '',
56
+ eventModeClose: '',
54
57
  paddingBehavior: 0,
55
58
  paddingViewPortMinWidth: 0,
56
- animationDuration: 500
59
+ animationDuration: 500,
60
+ scrollHelper: true,
57
61
  };
58
62
 
59
63
  this.settings = Object.assign({}, defaults, options);
@@ -116,11 +120,26 @@ class Madj2kFlyoutMenu {
116
120
  */
117
121
  bindEvents() {
118
122
  if (this.settings.$closeBtn) {
119
- this.settings.$closeBtn.addEventListener('click', e => this.closeEvent(e));
123
+
124
+ if (this.settings.eventModeClose) {
125
+ this.settings.$closeBtn.addEventListener(this.settings.eventModeClose, e => this.closeEvent(e));
126
+ } else {
127
+ this.settings.$closeBtn.addEventListener(this.settings.eventMode, e => this.closeEvent(e));
128
+ }
120
129
  this.settings.$closeBtn.addEventListener('keydown', e => this.keyboardEvent(e));
121
130
  }
122
131
 
123
- this.$element.addEventListener('click', e => this.toggleEvent(e));
132
+ if (this.settings.eventModeOpen || this.settings.eventModeClose) {
133
+ if (this.settings.eventModeOpen) {
134
+ this.$element.addEventListener(this.settings.eventModeOpen, e => this.openEvent(e));
135
+ }
136
+ if (this.settings.eventModeClose) {
137
+ this.$element.addEventListener(this.settings.eventModeClose, e => this.closeEvent(e));
138
+ }
139
+ } else {
140
+ this.$element.addEventListener(this.settings.eventMode, e => this.toggleEvent(e));
141
+ }
142
+
124
143
  this.$element.addEventListener('keydown', e => this.keyboardEvent(e));
125
144
 
126
145
  this.settings.$menu.querySelectorAll('a,button,input,textarea,select')
@@ -158,11 +177,24 @@ class Madj2kFlyoutMenu {
158
177
  */
159
178
  destroyEvents() {
160
179
  if (this.settings.$closeBtn) {
161
- this.settings.$closeBtn.removeEventListener('click', e => this.closeEvent(e));
180
+ if (this.settings.eventModeClose) {
181
+ this.settings.$closeBtn.removeEventListener(this.settings.eventModeClose, e => this.closeEvent(e));
182
+ } else {
183
+ this.settings.$closeBtn.removeEventListener(this.settings.eventMode, e => this.closeEvent(e));
184
+ }
162
185
  this.settings.$closeBtn.removeEventListener('keydown', e => this.keyboardEvent(e));
163
186
  }
164
187
 
165
- this.$element.removeEventListener('click', e => this.toggleEvent(e));
188
+ if (this.settings.eventModeOpen || this.settings.eventModeClose) {
189
+ if (this.settings.eventModeOpen) {
190
+ this.$element.removeEventListener(this.settings.eventModeOpen, e => this.openEvent(e));
191
+ }
192
+ if (this.settings.eventModeClose) {
193
+ this.$element.removeEventListener(this.settings.eventModeClose, e => this.closeEvent(e));
194
+ }
195
+ } else {
196
+ this.$element.removeEventListener(this.settings.eventMode, e => this.toggleEvent(e));
197
+ }
166
198
  this.$element.removeEventListener('keydown', e => this.keyboardEvent(e));
167
199
 
168
200
  this.settings.$menu.querySelectorAll('a,button,input,textarea,select')
@@ -227,6 +259,16 @@ class Madj2kFlyoutMenu {
227
259
  }
228
260
 
229
261
 
262
+ /**
263
+ * Handles close event
264
+ * @param {Event} e - The close event
265
+ */
266
+ openEvent(e) {
267
+ e.preventDefault();
268
+ this.open();
269
+ }
270
+
271
+
230
272
  /**
231
273
  * Opens the flyout menu
232
274
  */
@@ -408,15 +450,19 @@ class Madj2kFlyoutMenu {
408
450
  * Initializes the no-scroll helper elements
409
451
  */
410
452
  initNoScrollHelper() {
411
- const body = document.body;
412
- let helper = body.querySelector('.no-scroll-helper');
413
- const content = document.querySelector(`.${this.settings.contentSectionClass}`);
414
453
 
415
- if (!helper) {
416
- if (content) {
417
- content.innerHTML = `<div class="no-scroll-helper"><div class="no-scroll-helper-inner">${content.innerHTML}</div></div>`;
418
- } else {
419
- body.innerHTML = `<div class="no-scroll-helper"><div class="no-scroll-helper-inner">${body.innerHTML}</div></div>`;
454
+ // heightMode "full" with deprecated fullHeight-setting as fallback
455
+ if (this.settings.scrollHelper) {
456
+ const body = document.body;
457
+ let helper = body.querySelector('.no-scroll-helper');
458
+ const content = document.querySelector(`.${this.settings.contentSectionClass}`);
459
+
460
+ if (!helper) {
461
+ if (content) {
462
+ content.innerHTML = `<div class="no-scroll-helper"><div class="no-scroll-helper-inner">${content.innerHTML}</div></div>`;
463
+ } else {
464
+ body.innerHTML = `<div class="no-scroll-helper"><div class="no-scroll-helper-inner">${body.innerHTML}</div></div>`;
465
+ }
420
466
  }
421
467
  }
422
468
  }
@@ -451,7 +497,6 @@ class Madj2kFlyoutMenu {
451
497
  body.classList.remove(this.settings.openStatusBodyClassOverflow);
452
498
  window.scrollTo({top: scrollTop, behavior: 'instant'});
453
499
  }
454
-
455
500
  }
456
501
  }
457
502
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@madj2k/fe-frontend-kit",
3
- "version": "2.0.35",
3
+ "version": "2.0.37",
4
4
  "description": "Shared frontend utilities, menus and mixins for projects",
5
5
  "main": "index.js",
6
6
  "style": "index.scss",
package/readme.md CHANGED
@@ -79,7 +79,7 @@ CSS:
79
79
  </nav>
80
80
  </div>
81
81
  ```
82
- IMPORTANT: If the siteheader is positioned with ```position:fixed```, you have to switch that to ```position:absolute``` when the menu is opened.
82
+ IMPORTANT: If the siteheader is positioned with ```position:fixed``` and you are using full-height-mode (which is the default) you have to switch that to ```position:absolute``` when the menu is opened.
83
83
  Otherwise in the opened menu the scrolling won't work.
84
84
  ```
85
85
  .flyout-open {
@@ -88,6 +88,58 @@ Otherwise in the opened menu the scrolling won't work.
88
88
  }
89
89
  }
90
90
  ```
91
+
92
+
93
+ ## Options Reference
94
+
95
+ ### State & Animation Classes
96
+
97
+ | Option | Type | Default | Description |
98
+ |--------|------|---------|-------------|
99
+ | openStatusClass | string | 'open' | Applied to trigger and menu when open. |
100
+ | animationOpenStatusClass | string | 'opening' | Applied during opening animation. |
101
+ | animationCloseStatusClass | string | 'closing' | Applied during closing animation. |
102
+ | animationBodyClassPrefix | string | 'flyout' | Prefix for body animation classes like `flyout-opening`. |
103
+ | openStatusBodyClass | string | 'flyout-open' | Applied to `body` when the flyout is open. |
104
+ | openStatusBodyClassOverflow | string | 'flyout-open-overflow' | Applied when page height exceeds viewport (used in scroll-locking). |
105
+
106
+ ### CSS Class Selectors
107
+
108
+ | Option | Type | Default | Description |
109
+ |--------|------|---------|-------------|
110
+ | contentSectionClass | string | 'js-main-content' | Content wrapper used when creating no-scroll helper. |
111
+ | menuClass | string | 'js-flyout' | Menu root element class. |
112
+ | menuToggleClass | string | 'js-flyout-toggle' | Class for toggle buttons. |
113
+ | menuCloseClass | string | 'js-flyout-close' | Class for close buttons inside the flyout. |
114
+ | menuContainerClass | string | 'js-flyout-container' | Container used for slide animations (`top` transition). |
115
+ | menuInnerClass | string | 'js-flyout-inner' | Inner content wrapper. Observed via ResizeObserver. |
116
+ | heightCalculationClass | string | 'calculate' | Temporary class used during height determination. |
117
+
118
+ ### Height & Size Behavior
119
+
120
+ | Option | Type | Default | Description |
121
+ |--------|------|---------|-------------|
122
+ | heightMode | 'full' \| 'maxContent' | 'full' | Determines height behavior of the flyout. |
123
+ | animationDuration | number | 500 | Animation duration in milliseconds. |
124
+
125
+ ### Padding & Layout Behavior
126
+
127
+ | Option | Type | Default | Description |
128
+ |--------|------|---------|-------------|
129
+ | paddingBehavior | number | 0 | Controls dynamic horizontal padding. |
130
+ | paddingViewPortMinWidth | number | 0 | Minimum viewport width required before padding applies. |
131
+ | scrollHelper | boolean | true | Creates additional wrapper structure to enable scroll-locking. |
132
+
133
+
134
+ ### Event Handling
135
+
136
+ | Option | Type | Default | Description |
137
+ |--------|------|-------------|
138
+ | `eventMode` | `string` | `'click'` | Default event used for toggling the menu. Replaced if `eventModeOpen` or `eventModeClose` are set. |
139
+ | `eventModeOpen` | `string` | `''` | Defines a custom event for opening the menu. |
140
+ | `eventModeClose` | `string` | `''` | Defines a custom event for closing the menu. |
141
+
142
+
91
143
  ## Special: blur/gray effect for background
92
144
  * In order to achieve a blur/gray-effect for the background we add the following DIV to the main-content section:
93
145
  ```
@@ -199,6 +251,36 @@ CSS:
199
251
  ```
200
252
 
201
253
 
254
+ ## Options Reference
255
+
256
+ ### State & Structural Classes
257
+
258
+ | Option | Type | Default | Description |
259
+ |--------|------|---------|-------------|
260
+ | **openStatusClass** | `string` | `'open'` | Applied to menu, wrapper, and toggle when the pulldown is open. |
261
+ | **menuClass** | `string` | `'js-pulldown'` | Root class of the pulldown menu. Must match your HTML structure. |
262
+ | **menuToggleClass** | `string` | `'js-pulldown-toggle'` | Toggle buttons that control pulldown menus and also close others. |
263
+ | **menuWrapClass** | `string` | `'js-pulldown-wrap'` | Optional wrapper container that receives open/closed states. |
264
+
265
+
266
+ ### Animation & Timing
267
+
268
+ | Option | Type | Default | Description |
269
+ |--------|------|---------|-------------|
270
+ | **animationDuration** | `number` | `500` | Reserved for future open/close animation timing. Currently no CSS transition is applied by JavaScript. |
271
+
272
+
273
+ ### Internal Element References
274
+
275
+ These are automatically detected:
276
+
277
+ | Property | Description |
278
+ |----------|-------------|
279
+ | **menu** | The menu element referenced via `aria-controls`. |
280
+ | **menuWrap** | Closest parent using `menuWrapClass`. |
281
+ | **toggleElement** | The trigger element passed to the constructor. |
282
+
283
+
202
284
  # JS: Banner
203
285
  A lightweight class to show a full-page overlay (banner, popup, hint or cookie layer),
204
286
  with opening and closing animation and optional cookie persistence.
@@ -6,6 +6,15 @@
6
6
  * 2. Smooth anchor scrolling with optional offset
7
7
  * 3. Automatic scrolling when collapsible elements (like Bootstrap .collapse) open
8
8
  * 4. Appear-on-scroll animations for elements
9
+ * 5. Wrapper-based smooth scrolling with easing (BETA-VERSION)
10
+ *
11
+ * New in 2.0.4:
12
+ * - Support for wrapper-based smooth scrolling (config.smoothScroll)
13
+ * - Nested config normalization for flat CMS field names
14
+ * - Improved config merging with `enabled` toggles per feature
15
+ * - Collapse scroll behavior can now be selectively disabled
16
+ * - Configurable offset via selector for anchor scroll
17
+ * - Script-controlled blocking of scroll direction classes during auto-scrolling
9
18
  *
10
19
  * The class is fully configurable via options and is designed to be used in CMS contexts
11
20
  * where elements can be added, removed or re-ordered dynamically.
@@ -38,6 +47,12 @@
38
47
  * timeout: 500,
39
48
  * threshold: 25
40
49
  * },
50
+ * smoothScroll: {
51
+ * enabled: true,
52
+ * wrapperClass: '.js-smooth-scroll-wrapper',
53
+ * contentClass: '.js-smooth-scroll-content',
54
+ * easing: 0.075
55
+ * },
41
56
  * debug: false
42
57
  * });
43
58
  *
@@ -57,22 +72,20 @@
57
72
  * </div>
58
73
  *
59
74
  * @example
60
- * // Suggested SCSS for appear on scroll:
61
- * .js-appear-on-scroll {
62
- * opacity: 0;
63
- * transition: opacity 0.5s ease-out, transform 0.5s ease-out;
64
- * transform: translateY(1rem);
65
- *
66
- * &[data-appear-on-scroll="0"] {
67
- * opacity: 1;
68
- * transform: translateY(0);
69
- * }
70
- * }
75
+ * // Example HTML for smooth scroll wrapper:
76
+ * <div class="js-smooth-scroll-wrapper">
77
+ * <div class="js-smooth-scroll-content">
78
+ * <section>Section 1</section>
79
+ * <section>Section 2</section>
80
+ * <section>Section 3</section>
81
+ * </div>
82
+ * </div>
71
83
  */
72
84
 
73
85
  class Madj2kScrolling {
74
86
  config = {
75
87
  anchorScrolling: {
88
+ enabled: true,
76
89
  selector: ['a[href^="#"]', 'a[href*="#"]'],
77
90
  offsetSelector: null,
78
91
  disableSelector: '.js-no-scroll',
@@ -83,10 +96,20 @@ class Madj2kScrolling {
83
96
  threshold: 40
84
97
  },
85
98
  appearOnScroll: {
99
+ enabled: true,
86
100
  selector: ['.js-appear-on-scroll'],
87
101
  timeout: 500,
88
102
  threshold: 25
89
103
  },
104
+ scrollClasses: {
105
+ enabled: true,
106
+ },
107
+ smoothScroll: {
108
+ enabled: false,
109
+ easing: 0.075,
110
+ wrapperClass: '.js-smooth-scroll-wrapper',
111
+ contentClass: '.js-smooth-scroll-content'
112
+ },
90
113
  debug: false
91
114
  };
92
115
 
@@ -100,6 +123,8 @@ class Madj2kScrolling {
100
123
  // backwards compatibility
101
124
  this._normalizeNestedConfig(config, 'anchorScrolling', 'anchorScrolling');
102
125
  this._normalizeNestedConfig(config, 'appearOnScroll', 'appearOnScroll');
126
+ this._normalizeNestedConfig(config, 'scrollClasses', 'scrollClasses');
127
+ this._normalizeNestedConfig(config, 'smoothScroll', 'smoothScroll');
103
128
 
104
129
  this.config = {
105
130
  ...this.config,
@@ -111,6 +136,14 @@ class Madj2kScrolling {
111
136
  appearOnScroll: {
112
137
  ...this.config.appearOnScroll,
113
138
  ...config.appearOnScroll
139
+ },
140
+ scrollClasses: {
141
+ ...this.config.scrollClasses,
142
+ ...config.scrollClasses
143
+ },
144
+ smoothScroll: {
145
+ ...this.config.smoothScroll,
146
+ ...config.smoothScroll
114
147
  }
115
148
  };
116
149
 
@@ -119,9 +152,18 @@ class Madj2kScrolling {
119
152
 
120
153
  this._log('Initialized with config:', this.config);
121
154
 
122
- this.initScrollClassesForBody();
123
- this.initAnchorScrolling();
124
- this.initAppearOnScroll();
155
+ if (this.config.anchorScrolling.enabled) {
156
+ this.initAnchorScrolling();
157
+ }
158
+ if (this.config.appearOnScroll.enabled) {
159
+ this.initAppearOnScroll();
160
+ }
161
+ if (this.config.scrollClasses.enabled) {
162
+ this.initScrollClassesForBody();
163
+ }
164
+ if (this.config.smoothScroll.enabled) {
165
+ this.initSmoothScroll();
166
+ }
125
167
  }
126
168
 
127
169
  /**
@@ -319,6 +361,57 @@ class Madj2kScrolling {
319
361
  window.addEventListener('scroll', updateOnScroll);
320
362
  }
321
363
 
364
+ /**
365
+ * Initializes wrapper-based smoothScroll scrolling
366
+ */
367
+ initSmoothScroll() {
368
+ const wrapper = document.querySelector(this.config.smoothScroll.wrapperClass);
369
+ const content = document.querySelector(this.config.smoothScroll.contentClass);
370
+
371
+ if (!wrapper || !content) {
372
+ this._log('Smooth Scroll wrapper or content element missing.');
373
+ return;
374
+ }
375
+
376
+ const body = document.body;
377
+ const html = document.documentElement;
378
+
379
+ const height = content.offsetHeight;
380
+ body.style.height = `${height}px`;
381
+
382
+ this._smoothScroll = {
383
+ wrapper,
384
+ content,
385
+ current: 0,
386
+ target: 0,
387
+ ease: this.config.smoothScroll.easing
388
+ };
389
+
390
+ window.addEventListener('scroll', () => {
391
+ this._smoothScroll.target = window.scrollY;
392
+ });
393
+
394
+ const animate = () => {
395
+ this._smoothScroll.current += (this._smoothScroll.target - this._smoothScroll.current) * this._smoothScroll.ease;
396
+ this._smoothScroll.wrapper.style.transform = `translateY(-${this._smoothScroll.current}px)`;
397
+ requestAnimationFrame(animate);
398
+ };
399
+
400
+ requestAnimationFrame(animate);
401
+ this._log('Smooth Scroll Scroll activated');
402
+ }
403
+
404
+ /**
405
+ * Sets the target scroll position for smoothScroll-based scrolling
406
+ * @param {Number} position - The vertical scroll target in px
407
+ * @private
408
+ */
409
+ _setSmoothScrollTarget(position) {
410
+ if (this._smoothScroll) {
411
+ this._smoothScroll.target = position;
412
+ }
413
+ }
414
+
322
415
  /**
323
416
  * Debug logging helper
324
417
  * @private
@@ -8,3 +8,11 @@
8
8
  transform: translateY(0);
9
9
  }
10
10
  }
11
+
12
+ .js-smooth-scroll-wrapper {
13
+ position: fixed;
14
+ top: 0;
15
+ left: 0;
16
+ width: 100%;
17
+ will-change: transform;
18
+ }