@openeuropa/bcl-theme-joinup 1.10.0 → 1.10.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.
@@ -1702,7 +1702,7 @@ const EVENT_HIDDEN$5 = `hidden${EVENT_KEY$8}`;
1702
1702
  const EVENT_SHOW$5 = `show${EVENT_KEY$8}`;
1703
1703
  const EVENT_SHOWN$5 = `shown${EVENT_KEY$8}`;
1704
1704
  const EVENT_CLICK_DATA_API$4 = `click${EVENT_KEY$8}${DATA_API_KEY$5}`;
1705
- const EVENT_KEYDOWN_DATA_API = `keydown${EVENT_KEY$8}${DATA_API_KEY$5}`;
1705
+ const EVENT_KEYDOWN_DATA_API$1 = `keydown${EVENT_KEY$8}${DATA_API_KEY$5}`;
1706
1706
  const EVENT_KEYUP_DATA_API = `keyup${EVENT_KEY$8}${DATA_API_KEY$5}`;
1707
1707
  const CLASS_NAME_SHOW$6 = 'show';
1708
1708
  const CLASS_NAME_DROPUP = 'dropup';
@@ -2028,8 +2028,8 @@ class Dropdown extends BaseComponent {
2028
2028
  * Data API implementation
2029
2029
  */
2030
2030
 
2031
- EventHandler.on(document, EVENT_KEYDOWN_DATA_API, SELECTOR_DATA_TOGGLE$3, Dropdown.dataApiKeydownHandler);
2032
- EventHandler.on(document, EVENT_KEYDOWN_DATA_API, SELECTOR_MENU, Dropdown.dataApiKeydownHandler);
2031
+ EventHandler.on(document, EVENT_KEYDOWN_DATA_API$1, SELECTOR_DATA_TOGGLE$3, Dropdown.dataApiKeydownHandler);
2032
+ EventHandler.on(document, EVENT_KEYDOWN_DATA_API$1, SELECTOR_MENU, Dropdown.dataApiKeydownHandler);
2033
2033
  EventHandler.on(document, EVENT_CLICK_DATA_API$4, Dropdown.clearMenus);
2034
2034
  EventHandler.on(document, EVENT_KEYUP_DATA_API, Dropdown.clearMenus);
2035
2035
  EventHandler.on(document, EVENT_CLICK_DATA_API$4, SELECTOR_DATA_TOGGLE$3, function (event) {
@@ -2045,23 +2045,16 @@ defineJQueryPlugin$1(Dropdown);
2045
2045
 
2046
2046
  /**
2047
2047
  * --------------------------------------------------------------------------
2048
- * Bootstrap (v5.1.3): gallery.js
2048
+ * Bootstrap (v5.1.3): gallery.js (Refactored)
2049
2049
  * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
2050
2050
  * --------------------------------------------------------------------------
2051
2051
  */
2052
2052
 
2053
-
2054
- /**
2055
- * ------------------------------------------------------------------------
2056
- * Constants
2057
- * ------------------------------------------------------------------------
2058
- */
2059
-
2060
- const Default$a = {};
2061
2053
  const NAME$b = 'gallery';
2062
2054
  const DATA_KEY$7 = 'bs.gallery';
2063
2055
  const EVENT_KEY$7 = `.${DATA_KEY$7}`;
2064
2056
  const DATA_API_KEY$4 = '.data-api';
2057
+ const Default$a = {};
2065
2058
  const CAROUSEL_SELECTOR = '.carousel';
2066
2059
  const CAROUSEL_PAGER_SELECTOR = '.carousel-pager span';
2067
2060
  const CAROUSEL_ACTIVE_SELECTOR = '.carousel-item.active';
@@ -2071,72 +2064,115 @@ const MODAL_SELECTOR = '.modal';
2071
2064
  const EVENT_MODAL_HIDE$1 = 'hide.bs.modal';
2072
2065
  const CAROUSEL_EVENT = 'slide.bs.carousel';
2073
2066
  const EVENT_CLICK_DATA_API$3 = `click${EVENT_KEY$7}${DATA_API_KEY$4}`;
2074
-
2075
- /**
2076
- * ------------------------------------------------------------------------
2077
- * Class Definition
2078
- * ------------------------------------------------------------------------
2079
- */
2080
-
2067
+ const EVENT_KEYDOWN_DATA_API = `keydown${EVENT_KEY$7}${DATA_API_KEY$4}`;
2081
2068
  class Gallery extends BaseComponent {
2082
2069
  constructor(element, config) {
2083
2070
  super(element, config);
2084
- /* eslint no-underscore-dangle: ["error", { "allow": ["_element"] }] */
2085
2071
  this.carousel = SelectorEngine.findOne(CAROUSEL_SELECTOR, this._element);
2086
2072
  this.carouselPager = SelectorEngine.findOne(CAROUSEL_PAGER_SELECTOR, this._element);
2087
- this.carouselStartIndex = element.getAttribute('data-gallery-start');
2088
- this.carouselActiveItem = SelectorEngine.find(CAROUSEL_ITEM_SELECTOR, this.carousel)[this.carouselStartIndex];
2089
- this.carouselPager.textContent = Number(this.carouselStartIndex) + 1;
2090
2073
  this.modal = SelectorEngine.findOne(MODAL_SELECTOR, this._element);
2091
- this.addEventListeners();
2092
- this.carouselLazyLoad(this.carouselActiveItem);
2074
+ this.carouselStartIndex = element.getAttribute('data-gallery-start') || 0;
2075
+ const allCarouselItems = SelectorEngine.find(CAROUSEL_ITEM_SELECTOR, this.carousel);
2076
+ const startIndexNum = Math.max(0, Math.min(Number(this.carouselStartIndex), allCarouselItems.length - 1));
2077
+ this.carouselPager.textContent = startIndexNum + 1;
2078
+ this.carouselActiveItem = allCarouselItems[startIndexNum];
2079
+ this._carouselLazyLoad(this.carouselActiveItem);
2080
+ EventHandler.on(this.carousel, CAROUSEL_EVENT, event => this._handleCarouselSlide(event));
2081
+ EventHandler.on(this.modal, EVENT_MODAL_HIDE$1, () => this._stopSlide());
2093
2082
  }
2094
2083
 
2095
2084
  // Getters
2096
2085
  static get NAME() {
2097
2086
  return NAME$b;
2098
2087
  }
2088
+ static get Default() {
2089
+ return Default$a;
2090
+ }
2099
2091
 
2100
- // Public
2101
- setSlide(event) {
2102
- const slideFrom = SelectorEngine.findOne(CAROUSEL_ACTIVE_SELECTOR, this.carousel);
2103
- const slideTo = event.relatedTarget;
2104
- this.carouselLazyLoad(slideTo);
2092
+ /**
2093
+ * Handle the carousel "slide.bs.carousel" event
2094
+ * @param {Event} event
2095
+ */
2096
+ _handleCarouselSlide(event) {
2097
+ const previousSlide = SelectorEngine.findOne(CAROUSEL_ACTIVE_SELECTOR, this.carousel);
2098
+ const currentSlide = event.relatedTarget;
2099
+ this._carouselLazyLoad(currentSlide);
2105
2100
  this.carouselPager.textContent = event.to + 1;
2106
- this.stopVideo(slideFrom);
2101
+ this._stopVideo(previousSlide);
2107
2102
  }
2108
- stopSlide() {
2103
+
2104
+ /**
2105
+ * Stop the current carousel slide (when modal hides or component is disposed)
2106
+ */
2107
+ _stopSlide() {
2109
2108
  const currentSlide = SelectorEngine.findOne(CAROUSEL_ACTIVE_SELECTOR, this.carousel);
2110
- this.stopVideo(currentSlide);
2109
+ this._stopVideo(currentSlide);
2111
2110
  }
2112
- stopVideo(slide) {
2111
+
2112
+ /**
2113
+ * Stop any video or iframe in the given slide
2114
+ * @param {HTMLElement} slide
2115
+ */
2116
+ _stopVideo(slide) {
2117
+ if (!slide) {
2118
+ return;
2119
+ }
2113
2120
  const iframe = SelectorEngine.findOne('iframe', slide);
2114
2121
  const video = SelectorEngine.findOne('video', slide);
2115
- if (iframe) {
2122
+ if (iframe && iframe.dataset.src) {
2116
2123
  iframe.src = iframe.dataset.src;
2117
2124
  } else if (video) {
2118
2125
  video.pause();
2119
2126
  }
2120
2127
  }
2121
2128
 
2122
- // Private
2123
- carouselLazyLoad(slide) {
2129
+ /**
2130
+ * Lazy load media (img, iframe, video, etc.) by copying data-src into src
2131
+ * @param {HTMLElement} slide
2132
+ */
2133
+ _carouselLazyLoad(slide) {
2134
+ if (!slide) {
2135
+ return;
2136
+ }
2124
2137
  const media = SelectorEngine.findOne('[data-src]', slide);
2125
2138
  if (media && !media.src) {
2126
2139
  media.src = media.dataset.src;
2127
2140
  }
2128
2141
  }
2129
- addEventListeners() {
2130
- EventHandler.on(this.carousel, CAROUSEL_EVENT, event => this.setSlide(event));
2131
- EventHandler.on(this.modal, EVENT_MODAL_HIDE$1, event => this.stopSlide(event));
2132
- }
2133
2142
 
2134
- // Static
2135
- static get Default() {
2136
- return Default$a;
2143
+ /**
2144
+ * Internal helper to open the modal and jump to a specific slide
2145
+ * @param {HTMLElement} gallery
2146
+ * @param {HTMLElement} targetLink
2147
+ */
2148
+ static _openModalAndShowSlide(gallery, targetLink) {
2149
+ if (!gallery || !targetLink) {
2150
+ return;
2151
+ }
2152
+ const firstSlide = Number(targetLink.getAttribute('data-bs-slide-to') || 0);
2153
+ gallery.dataset.galleryStart = firstSlide;
2154
+ const instance = Gallery.getOrCreateInstance(gallery);
2155
+ const overlay = SelectorEngine.findOne('.bcl-gallery__item-overlay', targetLink);
2156
+ if (overlay) {
2157
+ const modalId = overlay.getAttribute('data-bs-target');
2158
+ const modalElement = document.querySelector(modalId);
2159
+ if (modalElement) {
2160
+ const modal = bootstrap.Modal.getOrCreateInstance(modalElement);
2161
+ modal.show();
2162
+ }
2163
+ }
2164
+ setTimeout(() => {
2165
+ const carousel = SelectorEngine.findOne(CAROUSEL_SELECTOR, instance._element);
2166
+ const carouselInstance = bootstrap.Carousel.getOrCreateInstance(carousel);
2167
+ carouselInstance.to(firstSlide);
2168
+ const pager = SelectorEngine.findOne(CAROUSEL_PAGER_SELECTOR, instance._element);
2169
+ if (pager) {
2170
+ pager.textContent = firstSlide + 1;
2171
+ }
2172
+ }, 50);
2137
2173
  }
2138
2174
  static jQueryInterface(config) {
2139
- return this.each(function jInterface() {
2175
+ return this.each(function () {
2140
2176
  const data = Gallery.getOrCreateInstance(this);
2141
2177
  if (typeof config !== 'string') {
2142
2178
  return;
@@ -2151,24 +2187,28 @@ class Gallery extends BaseComponent {
2151
2187
 
2152
2188
  /**
2153
2189
  * ------------------------------------------------------------------------
2154
- * Data Api implementation
2190
+ * Data API implementation
2155
2191
  * ------------------------------------------------------------------------
2156
2192
  */
2157
2193
 
2194
+ const isEnterOrSpace = event => {
2195
+ return event.key === 'Enter' || event.key === ' ';
2196
+ };
2158
2197
  EventHandler.on(document, EVENT_CLICK_DATA_API$3, THUMBNAIL_SELECTOR, event => {
2198
+ event.preventDefault();
2199
+ const targetLink = event.target.closest('a');
2159
2200
  const gallery = event.target.closest('div.bcl-gallery');
2160
- const firstSlide = event.target.parentNode.getAttribute('data-bs-slide-to');
2161
- gallery.dataset.galleryStart = firstSlide;
2162
- Gallery.getOrCreateInstance(gallery);
2201
+ Gallery._openModalAndShowSlide(gallery, targetLink);
2202
+ });
2203
+ EventHandler.on(document, EVENT_KEYDOWN_DATA_API, THUMBNAIL_SELECTOR, event => {
2204
+ if (!isEnterOrSpace(event)) {
2205
+ return;
2206
+ }
2207
+ event.preventDefault();
2208
+ const targetLink = event.target.closest('a');
2209
+ const gallery = event.target.closest('div.bcl-gallery');
2210
+ Gallery._openModalAndShowSlide(gallery, targetLink);
2163
2211
  });
2164
-
2165
- /**
2166
- * ------------------------------------------------------------------------
2167
- * jQuery
2168
- * ------------------------------------------------------------------------
2169
- * add .gallery to jQuery only if jQuery is present
2170
- */
2171
-
2172
2212
  defineJQueryPlugin$1(Gallery);
2173
2213
 
2174
2214
  /**
@@ -3054,9 +3094,16 @@ class AccessibleToggle {
3054
3094
  this.addEventListeners();
3055
3095
  }
3056
3096
  addAriaAttributes() {
3057
- if (this.triggerElement) {
3058
- this.triggerElement.setAttribute("aria-haspopup", "true");
3059
- this.triggerElement.setAttribute("aria-expanded", "false");
3097
+ if (this.type === 'modal') {
3098
+ if (this.triggerElement) {
3099
+ this.triggerElement.setAttribute('aria-haspopup', 'dialog');
3100
+ }
3101
+ }
3102
+ if (this.type === 'offcanvas') {
3103
+ if (this.triggerElement) {
3104
+ this.triggerElement.setAttribute('aria-haspopup', 'dialog');
3105
+ this.triggerElement.setAttribute('aria-expanded', 'false');
3106
+ }
3060
3107
  }
3061
3108
  }
3062
3109
  addEventListeners() {