@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.
@@ -3369,7 +3369,7 @@
3369
3369
  const EVENT_SHOW$5 = `show${EVENT_KEY$8}`;
3370
3370
  const EVENT_SHOWN$5 = `shown${EVENT_KEY$8}`;
3371
3371
  const EVENT_CLICK_DATA_API$4 = `click${EVENT_KEY$8}${DATA_API_KEY$5}`;
3372
- const EVENT_KEYDOWN_DATA_API = `keydown${EVENT_KEY$8}${DATA_API_KEY$5}`;
3372
+ const EVENT_KEYDOWN_DATA_API$1 = `keydown${EVENT_KEY$8}${DATA_API_KEY$5}`;
3373
3373
  const EVENT_KEYUP_DATA_API = `keyup${EVENT_KEY$8}${DATA_API_KEY$5}`;
3374
3374
  const CLASS_NAME_SHOW$6 = 'show';
3375
3375
  const CLASS_NAME_DROPUP = 'dropup';
@@ -3695,8 +3695,8 @@
3695
3695
  * Data API implementation
3696
3696
  */
3697
3697
 
3698
- EventHandler.on(document, EVENT_KEYDOWN_DATA_API, SELECTOR_DATA_TOGGLE$3, Dropdown.dataApiKeydownHandler);
3699
- EventHandler.on(document, EVENT_KEYDOWN_DATA_API, SELECTOR_MENU, Dropdown.dataApiKeydownHandler);
3698
+ EventHandler.on(document, EVENT_KEYDOWN_DATA_API$1, SELECTOR_DATA_TOGGLE$3, Dropdown.dataApiKeydownHandler);
3699
+ EventHandler.on(document, EVENT_KEYDOWN_DATA_API$1, SELECTOR_MENU, Dropdown.dataApiKeydownHandler);
3700
3700
  EventHandler.on(document, EVENT_CLICK_DATA_API$4, Dropdown.clearMenus);
3701
3701
  EventHandler.on(document, EVENT_KEYUP_DATA_API, Dropdown.clearMenus);
3702
3702
  EventHandler.on(document, EVENT_CLICK_DATA_API$4, SELECTOR_DATA_TOGGLE$3, function (event) {
@@ -3712,23 +3712,16 @@
3712
3712
 
3713
3713
  /**
3714
3714
  * --------------------------------------------------------------------------
3715
- * Bootstrap (v5.1.3): gallery.js
3715
+ * Bootstrap (v5.1.3): gallery.js (Refactored)
3716
3716
  * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
3717
3717
  * --------------------------------------------------------------------------
3718
3718
  */
3719
3719
 
3720
-
3721
- /**
3722
- * ------------------------------------------------------------------------
3723
- * Constants
3724
- * ------------------------------------------------------------------------
3725
- */
3726
-
3727
- const Default$a = {};
3728
3720
  const NAME$b = 'gallery';
3729
3721
  const DATA_KEY$7 = 'bs.gallery';
3730
3722
  const EVENT_KEY$7 = `.${DATA_KEY$7}`;
3731
3723
  const DATA_API_KEY$4 = '.data-api';
3724
+ const Default$a = {};
3732
3725
  const CAROUSEL_SELECTOR = '.carousel';
3733
3726
  const CAROUSEL_PAGER_SELECTOR = '.carousel-pager span';
3734
3727
  const CAROUSEL_ACTIVE_SELECTOR = '.carousel-item.active';
@@ -3738,72 +3731,115 @@
3738
3731
  const EVENT_MODAL_HIDE$1 = 'hide.bs.modal';
3739
3732
  const CAROUSEL_EVENT = 'slide.bs.carousel';
3740
3733
  const EVENT_CLICK_DATA_API$3 = `click${EVENT_KEY$7}${DATA_API_KEY$4}`;
3741
-
3742
- /**
3743
- * ------------------------------------------------------------------------
3744
- * Class Definition
3745
- * ------------------------------------------------------------------------
3746
- */
3747
-
3734
+ const EVENT_KEYDOWN_DATA_API = `keydown${EVENT_KEY$7}${DATA_API_KEY$4}`;
3748
3735
  class Gallery extends BaseComponent {
3749
3736
  constructor(element, config) {
3750
3737
  super(element, config);
3751
- /* eslint no-underscore-dangle: ["error", { "allow": ["_element"] }] */
3752
3738
  this.carousel = SelectorEngine.findOne(CAROUSEL_SELECTOR, this._element);
3753
3739
  this.carouselPager = SelectorEngine.findOne(CAROUSEL_PAGER_SELECTOR, this._element);
3754
- this.carouselStartIndex = element.getAttribute('data-gallery-start');
3755
- this.carouselActiveItem = SelectorEngine.find(CAROUSEL_ITEM_SELECTOR, this.carousel)[this.carouselStartIndex];
3756
- this.carouselPager.textContent = Number(this.carouselStartIndex) + 1;
3757
3740
  this.modal = SelectorEngine.findOne(MODAL_SELECTOR, this._element);
3758
- this.addEventListeners();
3759
- this.carouselLazyLoad(this.carouselActiveItem);
3741
+ this.carouselStartIndex = element.getAttribute('data-gallery-start') || 0;
3742
+ const allCarouselItems = SelectorEngine.find(CAROUSEL_ITEM_SELECTOR, this.carousel);
3743
+ const startIndexNum = Math.max(0, Math.min(Number(this.carouselStartIndex), allCarouselItems.length - 1));
3744
+ this.carouselPager.textContent = startIndexNum + 1;
3745
+ this.carouselActiveItem = allCarouselItems[startIndexNum];
3746
+ this._carouselLazyLoad(this.carouselActiveItem);
3747
+ EventHandler.on(this.carousel, CAROUSEL_EVENT, event => this._handleCarouselSlide(event));
3748
+ EventHandler.on(this.modal, EVENT_MODAL_HIDE$1, () => this._stopSlide());
3760
3749
  }
3761
3750
 
3762
3751
  // Getters
3763
3752
  static get NAME() {
3764
3753
  return NAME$b;
3765
3754
  }
3755
+ static get Default() {
3756
+ return Default$a;
3757
+ }
3766
3758
 
3767
- // Public
3768
- setSlide(event) {
3769
- const slideFrom = SelectorEngine.findOne(CAROUSEL_ACTIVE_SELECTOR, this.carousel);
3770
- const slideTo = event.relatedTarget;
3771
- this.carouselLazyLoad(slideTo);
3759
+ /**
3760
+ * Handle the carousel "slide.bs.carousel" event
3761
+ * @param {Event} event
3762
+ */
3763
+ _handleCarouselSlide(event) {
3764
+ const previousSlide = SelectorEngine.findOne(CAROUSEL_ACTIVE_SELECTOR, this.carousel);
3765
+ const currentSlide = event.relatedTarget;
3766
+ this._carouselLazyLoad(currentSlide);
3772
3767
  this.carouselPager.textContent = event.to + 1;
3773
- this.stopVideo(slideFrom);
3768
+ this._stopVideo(previousSlide);
3774
3769
  }
3775
- stopSlide() {
3770
+
3771
+ /**
3772
+ * Stop the current carousel slide (when modal hides or component is disposed)
3773
+ */
3774
+ _stopSlide() {
3776
3775
  const currentSlide = SelectorEngine.findOne(CAROUSEL_ACTIVE_SELECTOR, this.carousel);
3777
- this.stopVideo(currentSlide);
3776
+ this._stopVideo(currentSlide);
3778
3777
  }
3779
- stopVideo(slide) {
3778
+
3779
+ /**
3780
+ * Stop any video or iframe in the given slide
3781
+ * @param {HTMLElement} slide
3782
+ */
3783
+ _stopVideo(slide) {
3784
+ if (!slide) {
3785
+ return;
3786
+ }
3780
3787
  const iframe = SelectorEngine.findOne('iframe', slide);
3781
3788
  const video = SelectorEngine.findOne('video', slide);
3782
- if (iframe) {
3789
+ if (iframe && iframe.dataset.src) {
3783
3790
  iframe.src = iframe.dataset.src;
3784
3791
  } else if (video) {
3785
3792
  video.pause();
3786
3793
  }
3787
3794
  }
3788
3795
 
3789
- // Private
3790
- carouselLazyLoad(slide) {
3796
+ /**
3797
+ * Lazy load media (img, iframe, video, etc.) by copying data-src into src
3798
+ * @param {HTMLElement} slide
3799
+ */
3800
+ _carouselLazyLoad(slide) {
3801
+ if (!slide) {
3802
+ return;
3803
+ }
3791
3804
  const media = SelectorEngine.findOne('[data-src]', slide);
3792
3805
  if (media && !media.src) {
3793
3806
  media.src = media.dataset.src;
3794
3807
  }
3795
3808
  }
3796
- addEventListeners() {
3797
- EventHandler.on(this.carousel, CAROUSEL_EVENT, event => this.setSlide(event));
3798
- EventHandler.on(this.modal, EVENT_MODAL_HIDE$1, event => this.stopSlide(event));
3799
- }
3800
3809
 
3801
- // Static
3802
- static get Default() {
3803
- return Default$a;
3810
+ /**
3811
+ * Internal helper to open the modal and jump to a specific slide
3812
+ * @param {HTMLElement} gallery
3813
+ * @param {HTMLElement} targetLink
3814
+ */
3815
+ static _openModalAndShowSlide(gallery, targetLink) {
3816
+ if (!gallery || !targetLink) {
3817
+ return;
3818
+ }
3819
+ const firstSlide = Number(targetLink.getAttribute('data-bs-slide-to') || 0);
3820
+ gallery.dataset.galleryStart = firstSlide;
3821
+ const instance = Gallery.getOrCreateInstance(gallery);
3822
+ const overlay = SelectorEngine.findOne('.bcl-gallery__item-overlay', targetLink);
3823
+ if (overlay) {
3824
+ const modalId = overlay.getAttribute('data-bs-target');
3825
+ const modalElement = document.querySelector(modalId);
3826
+ if (modalElement) {
3827
+ const modal = bootstrap.Modal.getOrCreateInstance(modalElement);
3828
+ modal.show();
3829
+ }
3830
+ }
3831
+ setTimeout(() => {
3832
+ const carousel = SelectorEngine.findOne(CAROUSEL_SELECTOR, instance._element);
3833
+ const carouselInstance = bootstrap.Carousel.getOrCreateInstance(carousel);
3834
+ carouselInstance.to(firstSlide);
3835
+ const pager = SelectorEngine.findOne(CAROUSEL_PAGER_SELECTOR, instance._element);
3836
+ if (pager) {
3837
+ pager.textContent = firstSlide + 1;
3838
+ }
3839
+ }, 50);
3804
3840
  }
3805
3841
  static jQueryInterface(config) {
3806
- return this.each(function jInterface() {
3842
+ return this.each(function () {
3807
3843
  const data = Gallery.getOrCreateInstance(this);
3808
3844
  if (typeof config !== 'string') {
3809
3845
  return;
@@ -3818,24 +3854,28 @@
3818
3854
 
3819
3855
  /**
3820
3856
  * ------------------------------------------------------------------------
3821
- * Data Api implementation
3857
+ * Data API implementation
3822
3858
  * ------------------------------------------------------------------------
3823
3859
  */
3824
3860
 
3861
+ const isEnterOrSpace = event => {
3862
+ return event.key === 'Enter' || event.key === ' ';
3863
+ };
3825
3864
  EventHandler.on(document, EVENT_CLICK_DATA_API$3, THUMBNAIL_SELECTOR, event => {
3865
+ event.preventDefault();
3866
+ const targetLink = event.target.closest('a');
3826
3867
  const gallery = event.target.closest('div.bcl-gallery');
3827
- const firstSlide = event.target.parentNode.getAttribute('data-bs-slide-to');
3828
- gallery.dataset.galleryStart = firstSlide;
3829
- Gallery.getOrCreateInstance(gallery);
3868
+ Gallery._openModalAndShowSlide(gallery, targetLink);
3869
+ });
3870
+ EventHandler.on(document, EVENT_KEYDOWN_DATA_API, THUMBNAIL_SELECTOR, event => {
3871
+ if (!isEnterOrSpace(event)) {
3872
+ return;
3873
+ }
3874
+ event.preventDefault();
3875
+ const targetLink = event.target.closest('a');
3876
+ const gallery = event.target.closest('div.bcl-gallery');
3877
+ Gallery._openModalAndShowSlide(gallery, targetLink);
3830
3878
  });
3831
-
3832
- /**
3833
- * ------------------------------------------------------------------------
3834
- * jQuery
3835
- * ------------------------------------------------------------------------
3836
- * add .gallery to jQuery only if jQuery is present
3837
- */
3838
-
3839
3879
  defineJQueryPlugin$1(Gallery);
3840
3880
 
3841
3881
  /**
@@ -4721,9 +4761,16 @@
4721
4761
  this.addEventListeners();
4722
4762
  }
4723
4763
  addAriaAttributes() {
4724
- if (this.triggerElement) {
4725
- this.triggerElement.setAttribute("aria-haspopup", "true");
4726
- this.triggerElement.setAttribute("aria-expanded", "false");
4764
+ if (this.type === 'modal') {
4765
+ if (this.triggerElement) {
4766
+ this.triggerElement.setAttribute('aria-haspopup', 'dialog');
4767
+ }
4768
+ }
4769
+ if (this.type === 'offcanvas') {
4770
+ if (this.triggerElement) {
4771
+ this.triggerElement.setAttribute('aria-haspopup', 'dialog');
4772
+ this.triggerElement.setAttribute('aria-expanded', 'false');
4773
+ }
4727
4774
  }
4728
4775
  }
4729
4776
  addEventListeners() {