Skip to content

Commit d40ce02

Browse files
committed
v1.4.0 with unique-er automatic submenu IDs
1 parent 64032d5 commit d40ce02

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

clicky-menus.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Clicky Menus v1.3.0
2+
* Clicky Menus v1.4.0
33
*/
44

55
/**

clicky-menus.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/**
2-
* Clicky Menus v1.3.0
2+
* Clicky Menus v1.4.0
33
*/
44

55
( function() {
66
'use strict';
77

8-
const ClickyMenus = function( menu ) {
8+
const ClickyMenus = function( menu, menuIndex ) {
99
// DOM element(s)
1010
const container = menu.parentElement;
1111
let currentMenuItem,
@@ -141,11 +141,12 @@
141141
const submenuId = submenu.getAttribute( 'id' );
142142

143143
let id;
144+
const idSuffix = `-submenu-${menuIndex}-${i}`;
144145
if ( null === submenuId ) {
145-
id = button.textContent.trim().replace( /\s+/g, '-' ).replace(/^[^a-zA-Z]+|[^\w:.-]+/g, "").toLowerCase() + `-submenu-${i}`;
146+
id = button.textContent.trim().replace( /\s+/g, '-' ).replace(/^[^a-zA-Z]+|[^\w:.-]+/g, "").toLowerCase() + idSuffix;
146147
i++;
147148
} else {
148-
id = `${submenuId}-submenu-${i}`;
149+
id = submenuId + idSuffix;
149150
i++;
150151
}
151152

@@ -162,10 +163,11 @@
162163
/* Create a ClickMenus object and initiate menu for any menu with .clicky-menu class */
163164
document.addEventListener( 'DOMContentLoaded', function() {
164165
const menus = document.querySelectorAll( '.clicky-menu' );
165-
166+
let i = 1;
166167
menus.forEach( ( menu ) => {
167-
const clickyMenu = new ClickyMenus( menu );
168+
const clickyMenu = new ClickyMenus( menu, i );
168169
clickyMenu.init();
170+
i++;
169171
} );
170172
} );
171173

readme.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Clicky Menus
22

3-
Version 1.3.0
3+
Version 1.4.0
44

55
Jump to: [About](#about), [Features](#features), [Setup & Configuration](#setup--configuration), [Browser Support](#browser-support) [Changelog](#changelog)
66

@@ -157,6 +157,10 @@ Internet Explorer 11 support is possible if you include polyfills for [`closest`
157157
158158
## Changelog
159159
160+
### 1.4.0 (April 29, 2025)
161+
162+
- Further differentiate automatically-generated submenu IDs by including a unique ID for each clicky-menu.
163+
160164
### 1.3.0 (April 25, 2025)
161165
162166
- NEW! Use the `data-clicky-menus-close` attribute on any element to automatically close the open submenu. It should be set to the ID of the element with the `clicky-menu` class. Fixes #21.

0 commit comments

Comments
 (0)