@openeuropa/bcl-theme-joinup 1.10.5 → 1.10.6
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/css/oe-bcl-joinup.css +581 -91
- package/css/oe-bcl-joinup.css.map +1 -1
- package/css/oe-bcl-joinup.min.css +1 -1
- package/css/oe-bcl-joinup.min.css.map +1 -1
- package/js/oe-bcl-joinup.bundle.js +187 -0
- package/js/oe-bcl-joinup.bundle.js.map +1 -1
- package/js/oe-bcl-joinup.bundle.min.js +1 -1
- package/js/oe-bcl-joinup.bundle.min.js.map +1 -1
- package/js/oe-bcl-joinup.esm.js +186 -1
- package/js/oe-bcl-joinup.esm.js.map +1 -1
- package/js/oe-bcl-joinup.esm.min.js +1 -1
- package/js/oe-bcl-joinup.esm.min.js.map +1 -1
- package/js/oe-bcl-joinup.umd.js +187 -0
- package/js/oe-bcl-joinup.umd.js.map +1 -1
- package/js/oe-bcl-joinup.umd.min.js +1 -1
- package/js/oe-bcl-joinup.umd.min.js.map +1 -1
- package/package.json +6 -6
- package/src/js/index.esm.js +4 -0
- package/src/js/index.umd.js +4 -0
- package/src/scss/oe-bcl-joinup.scss +1 -0
- package/templates/bcl-button/button.html.twig +3 -2
- package/templates/bcl-header/header.html.twig +37 -6
- package/templates/bcl-mega-menu/mega-menu-items.html.twig +35 -0
- package/templates/bcl-mega-menu/mega-menu-submenu.html.twig +65 -0
- package/templates/bcl-mega-menu/mega-menu.html.twig +115 -0
- package/templates/bcl-navigation/navigation.html.twig +3 -1
- package/templates/bcl-offcanvas/offcanvas.html.twig +9 -6
package/js/oe-bcl-joinup.esm.js
CHANGED
|
@@ -3167,6 +3167,191 @@ class AccordionToggle {
|
|
|
3167
3167
|
}
|
|
3168
3168
|
}
|
|
3169
3169
|
|
|
3170
|
+
class MainNavigation {
|
|
3171
|
+
constructor(toggler) {
|
|
3172
|
+
this.toggler = toggler;
|
|
3173
|
+
this.top = 0;
|
|
3174
|
+
this.target = this.getTargetFromToggler(toggler);
|
|
3175
|
+
if (!this.target) return;
|
|
3176
|
+
this.addListeners();
|
|
3177
|
+
}
|
|
3178
|
+
getTargetFromToggler(toggler) {
|
|
3179
|
+
const selector = toggler.getAttribute("data-bs-target");
|
|
3180
|
+
if (!selector) return null;
|
|
3181
|
+
try {
|
|
3182
|
+
return document.querySelector(selector);
|
|
3183
|
+
} catch {
|
|
3184
|
+
return null;
|
|
3185
|
+
}
|
|
3186
|
+
}
|
|
3187
|
+
addListeners() {
|
|
3188
|
+
EventHandler.on(this.target, "show.bs.collapse", () => {
|
|
3189
|
+
window.scrollTo(0, this.top);
|
|
3190
|
+
});
|
|
3191
|
+
}
|
|
3192
|
+
static init(selector = ".bcl-toggler", options) {
|
|
3193
|
+
const togglers = SelectorEngine.find(selector);
|
|
3194
|
+
togglers.forEach(toggler => new MainNavigation(toggler, options));
|
|
3195
|
+
}
|
|
3196
|
+
}
|
|
3197
|
+
document.addEventListener("DOMContentLoaded", () => {
|
|
3198
|
+
// Run for all .bcl-toggler buttons
|
|
3199
|
+
MainNavigation.init(".bcl-navbar-toggler");
|
|
3200
|
+
});
|
|
3201
|
+
|
|
3202
|
+
class MegaMenu {
|
|
3203
|
+
constructor(root) {
|
|
3204
|
+
this.root = root;
|
|
3205
|
+
this.backButton = SelectorEngine.findOne(".back-button", this.root);
|
|
3206
|
+
this.trigger = SelectorEngine.findOne(':scope > .dropdown-toggle[data-bs-toggle="dropdown"]', this.root);
|
|
3207
|
+
this.ul = SelectorEngine.findOne('.bcl-mega-menu__items.__level-1', this.root);
|
|
3208
|
+
this.addSubmenuTriggerListeners();
|
|
3209
|
+
this.addBackButtonListener();
|
|
3210
|
+
this.addTriggerListeners();
|
|
3211
|
+
this.addEscapeKeyHandler();
|
|
3212
|
+
}
|
|
3213
|
+
getPanelForTrigger(trigger) {
|
|
3214
|
+
const id = trigger.getAttribute('aria-controls');
|
|
3215
|
+
return id ? document.getElementById(id) : null;
|
|
3216
|
+
}
|
|
3217
|
+
getFocusableChildren(container) {
|
|
3218
|
+
if (!container) return [];
|
|
3219
|
+
return Array.from(container.querySelectorAll('a[href], button:not([disabled]):not(.back-button), [tabindex]:not([tabindex="-1"])')).filter(el => !el.hasAttribute('disabled') && el.tabIndex !== -1);
|
|
3220
|
+
}
|
|
3221
|
+
focusFirstItemInPanel(trigger) {
|
|
3222
|
+
const panel = this.getPanelForTrigger(trigger);
|
|
3223
|
+
if (!panel) return;
|
|
3224
|
+
const list = SelectorEngine.findOne('ul.bcl-mega-menu__items', panel);
|
|
3225
|
+
if (!list) return;
|
|
3226
|
+
const first = this.getFocusableChildren(list)[0];
|
|
3227
|
+
if (first) first.focus();
|
|
3228
|
+
}
|
|
3229
|
+
addEscapeKeyHandler() {
|
|
3230
|
+
// Bootstrap attaches its dropdown keydown listener on `document` in the capture phase.
|
|
3231
|
+
// By listening on `window` in the capture phase, our handler runs *before* Bootstrap’s.
|
|
3232
|
+
// This lets us intercept Esc inside mega menu submenus and stop Bootstrap from closing
|
|
3233
|
+
// the entire dropdown.
|
|
3234
|
+
window.addEventListener('keydown', e => {
|
|
3235
|
+
if (e.key !== 'Escape') return;
|
|
3236
|
+
|
|
3237
|
+
// Only act if Esc originated inside THIS mega menu's open submenu
|
|
3238
|
+
const panel = e.target.closest('.bcl-mega-menu__submenu');
|
|
3239
|
+
if (!panel || panel.hidden || !this.root.contains(panel)) {
|
|
3240
|
+
// Not our submenu: let Bootstrap handle it normally
|
|
3241
|
+
return;
|
|
3242
|
+
}
|
|
3243
|
+
|
|
3244
|
+
// Stop the event BEFORE it reaches Bootstrap's document-capture handler
|
|
3245
|
+
e.preventDefault();
|
|
3246
|
+
e.stopImmediatePropagation();
|
|
3247
|
+
e.stopPropagation();
|
|
3248
|
+
|
|
3249
|
+
// Close only this submenu and focus its trigger
|
|
3250
|
+
const triggerId = panel.getAttribute('aria-labelledby');
|
|
3251
|
+
const trigger = triggerId ? document.getElementById(triggerId) : null;
|
|
3252
|
+
if (trigger) {
|
|
3253
|
+
this.closeSubmenu(trigger);
|
|
3254
|
+
trigger.focus();
|
|
3255
|
+
}
|
|
3256
|
+
}, true);
|
|
3257
|
+
}
|
|
3258
|
+
addTriggerListeners() {
|
|
3259
|
+
if (!this.trigger) return;
|
|
3260
|
+
|
|
3261
|
+
// When the mega menu is opened, focus the first item in the menu.
|
|
3262
|
+
EventHandler.on(this.trigger, 'shown.bs.dropdown', () => {
|
|
3263
|
+
const panelId = this.trigger.getAttribute('aria-controls');
|
|
3264
|
+
const panel = panelId ? document.getElementById(panelId) : null;
|
|
3265
|
+
const firstFocusable = panel ? this.getFocusableChildren(panel)[0] : null;
|
|
3266
|
+
if (firstFocusable) firstFocusable.focus();
|
|
3267
|
+
});
|
|
3268
|
+
|
|
3269
|
+
// When the mega menu is closed, close all submenus.
|
|
3270
|
+
EventHandler.on(this.trigger, 'hide.bs.dropdown', () => {
|
|
3271
|
+
this.closeAllSubmenus();
|
|
3272
|
+
});
|
|
3273
|
+
}
|
|
3274
|
+
addSubmenuTriggerListeners() {
|
|
3275
|
+
// Clicking/activating a parent item button toggles the submenu.
|
|
3276
|
+
SelectorEngine.find(':scope li > button[aria-expanded]', this.root).forEach(trigger => {
|
|
3277
|
+
EventHandler.on(trigger, "click", () => {
|
|
3278
|
+
const expanded = trigger.getAttribute('aria-expanded') === 'true';
|
|
3279
|
+
if (expanded) {
|
|
3280
|
+
// Close this submenu.
|
|
3281
|
+
this.closeSubmenu(trigger);
|
|
3282
|
+
} else {
|
|
3283
|
+
this.openSubmenu(trigger);
|
|
3284
|
+
// The back button is only visible in mobile / narrow viewport.
|
|
3285
|
+
if (this.backButton && this.backButton.offsetParent !== null) {
|
|
3286
|
+
this.backButton.focus();
|
|
3287
|
+
} else {
|
|
3288
|
+
this.focusFirstItemInPanel(trigger);
|
|
3289
|
+
}
|
|
3290
|
+
}
|
|
3291
|
+
});
|
|
3292
|
+
});
|
|
3293
|
+
}
|
|
3294
|
+
addBackButtonListener() {
|
|
3295
|
+
// Clicking a back button closes the submenu or the menu itself.
|
|
3296
|
+
if (!this.backButton) {
|
|
3297
|
+
return;
|
|
3298
|
+
}
|
|
3299
|
+
EventHandler.on(this.backButton, "click", () => {
|
|
3300
|
+
const submenusThatWereOpen = this.closeAllSubmenus();
|
|
3301
|
+
if (submenusThatWereOpen.length > 0) {
|
|
3302
|
+
// Focus the submenu trigger, to allow quick reopen by keystroke.
|
|
3303
|
+
submenusThatWereOpen[0].focus();
|
|
3304
|
+
return;
|
|
3305
|
+
}
|
|
3306
|
+
// Close the mega menu itself.
|
|
3307
|
+
if (this.trigger) {
|
|
3308
|
+
// Close using the Bootstrap dropdown API.
|
|
3309
|
+
Dropdown.getOrCreateInstance(this.trigger).hide();
|
|
3310
|
+
// Focus the main trigger, to allow quick reopen by keystroke.
|
|
3311
|
+
this.trigger.focus();
|
|
3312
|
+
}
|
|
3313
|
+
});
|
|
3314
|
+
}
|
|
3315
|
+
openSubmenu(trigger) {
|
|
3316
|
+
// Close all submenus, then open the current submenu.
|
|
3317
|
+
this.closeAllSubmenus();
|
|
3318
|
+
trigger.setAttribute('aria-expanded', 'true');
|
|
3319
|
+
const panel = this.getPanelForTrigger(trigger);
|
|
3320
|
+
if (panel) panel.hidden = false;
|
|
3321
|
+
}
|
|
3322
|
+
|
|
3323
|
+
/**
|
|
3324
|
+
* Closes all submenus.
|
|
3325
|
+
*
|
|
3326
|
+
* This is simple while there is only one submenu level.
|
|
3327
|
+
*
|
|
3328
|
+
* @returns {HTMLElement[]}
|
|
3329
|
+
* Triggers for submenus that were closed.
|
|
3330
|
+
* Usually this is either exactly one, or none.
|
|
3331
|
+
*/
|
|
3332
|
+
closeAllSubmenus() {
|
|
3333
|
+
if (!this.ul) {
|
|
3334
|
+
return;
|
|
3335
|
+
}
|
|
3336
|
+
const triggers = SelectorEngine.find(':scope > li > button[aria-expanded="true"]', this.ul);
|
|
3337
|
+
// Use arrow fn to keep `this` bound.
|
|
3338
|
+
triggers.forEach(t => this.closeSubmenu(t));
|
|
3339
|
+
return triggers;
|
|
3340
|
+
}
|
|
3341
|
+
closeSubmenu(trigger) {
|
|
3342
|
+
trigger.setAttribute('aria-expanded', 'false');
|
|
3343
|
+
const panel = this.getPanelForTrigger(trigger);
|
|
3344
|
+
if (panel) panel.hidden = true;
|
|
3345
|
+
}
|
|
3346
|
+
static init(selector = ".bcl-mega-menu") {
|
|
3347
|
+
const megaMenus = SelectorEngine.find(selector);
|
|
3348
|
+
megaMenus.forEach(menuEl => new MegaMenu(menuEl));
|
|
3349
|
+
}
|
|
3350
|
+
}
|
|
3351
|
+
document.addEventListener("DOMContentLoaded", () => {
|
|
3352
|
+
MegaMenu.init();
|
|
3353
|
+
});
|
|
3354
|
+
|
|
3170
3355
|
/**
|
|
3171
3356
|
* --------------------------------------------------------------------------
|
|
3172
3357
|
* Bootstrap util/sanitizer.js
|
|
@@ -5066,5 +5251,5 @@ enableDismissTrigger(Toast);
|
|
|
5066
5251
|
|
|
5067
5252
|
defineJQueryPlugin$1(Toast);
|
|
5068
5253
|
|
|
5069
|
-
export { AccessibleToggle, AccordionToggle, Alert, Button, Carousel, Collapse, Dropdown, Gallery, Modal, Offcanvas, Popover, ScrollSpy, ScrollSpy$1 as ScrollSpyV2, Tab, Toast, Tooltip };
|
|
5254
|
+
export { AccessibleToggle, AccordionToggle, Alert, Button, Carousel, Collapse, Dropdown, Gallery, MainNavigation, MegaMenu, Modal, Offcanvas, Popover, ScrollSpy, ScrollSpy$1 as ScrollSpyV2, Tab, Toast, Tooltip };
|
|
5070
5255
|
//# sourceMappingURL=oe-bcl-joinup.esm.js.map
|