@madj2k/fe-frontend-kit 2.0.18 → 2.0.20

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@madj2k/fe-frontend-kit",
3
- "version": "2.0.18",
3
+ "version": "2.0.20",
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
@@ -168,7 +168,7 @@ Init with available options:
168
168
  import { Madj2kScrolling } from '@madj2k/frontend-kit/tools/scrolling';
169
169
  const scrolling = new Madj2kScrolling({
170
170
  anchorScrolling: {
171
- selector: ['a[href^="#"]'],
171
+ selector: ['a[href^="#"]', 'a[href*="#"]'],
172
172
  offsetSelector: null,
173
173
  disableSelector: '.js-no-scroll',
174
174
  collapsibleSelector: ['.collapse'],
@@ -12,7 +12,7 @@
12
12
  *
13
13
  * @author Steffen Kroggel <developer@steffenkroggel.de>
14
14
  * @copyright 2025 Steffen Kroggel
15
- * @version 2.0.2
15
+ * @version 2.0.4
16
16
  * @license GNU General Public License v3.0
17
17
  * @see https://www.gnu.org/licenses/gpl-3.0.en.html
18
18
  *
@@ -24,7 +24,7 @@
24
24
  * // Initialize with custom config
25
25
  * const scrolling = new Madj2kScrolling({
26
26
  * anchorScrolling: {
27
- * selector: ['a[href*="#"]'],
27
+ * selector: ['a[href^="#"]', 'a[href*="#"]'],
28
28
  * offsetSelector: null,
29
29
  * disableSelector: '.js-no-scroll',
30
30
  * collapsibleSelector: ['.collapse'],
@@ -73,7 +73,7 @@
73
73
  class Madj2kScrolling {
74
74
  config = {
75
75
  anchorScrolling: {
76
- selector: ['a[href*="#"]'],
76
+ selector: ['a[href^="#"]', 'a[href*="#"]'],
77
77
  offsetSelector: null,
78
78
  disableSelector: '.js-no-scroll',
79
79
  collapsibleSelector: ['.collapse'],
@@ -235,17 +235,12 @@ class Madj2kScrolling {
235
235
  const href = event.currentTarget.getAttribute('href');
236
236
  if (!href) return;
237
237
 
238
- // check if link is to the same page - with or without path
239
- const [linkPath, hash] = href.split('#');
240
- const currentUrl = window.location.origin + window.location.pathname;
241
- const isSamePage = (
242
- href.startsWith('#') ||
243
- (window.location.origin + linkPath) === currentUrl
244
- );
238
+ const url = new URL(href, window.location.origin); // also converts relative URLs correctly
239
+ const isSamePage = (url.pathname === window.location.pathname || href.startsWith("#"));
245
240
 
246
- if (isSamePage && hash) {
241
+ if (isSamePage && url.hash) {
247
242
  event.preventDefault();
248
- const anchor = document.getElementById(hash);
243
+ const anchor = document.getElementById(url.hash.substring(1));
249
244
  if (anchor) scrollToElement(anchor);
250
245
  }
251
246
  };