Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Repetition of events #554

Closed
CodeTappert opened this issue Aug 15, 2023 · 4 comments
Closed

Repetition of events #554

CodeTappert opened this issue Aug 15, 2023 · 4 comments
Labels
bug Something isn't working

Comments

@CodeTappert
Copy link

CodeTappert commented Aug 15, 2023

Describe the bug

I recently noticed that the closing of my fancybox gallery takes a lot longer then usual.

So i started to log the events.

And i see this

grafik

It initializes all of the slides (and removes each one of them)

This isnt behaviour i noticed before.

Is there a way to reduce the amount of slides initialized?

Reproduction

Having a gallery with a lot of images and having custom logic in removeSlide Event that takes time

My code:


            removeSlide: (carousel) => {
              
              let idx = carousel.slides[carousel.page].idx;
              // For some reason idx is false when it is supposed to be 0
              if (!idx) {
                idx = 0;
              }
              let examId = carousel.slides[carousel.page].examid;
              const currentSlideVideoId = `video-player-${examId}-${idx}`;

              const videoElements = document.querySelectorAll("[id*='video-player']");
              videoElements.forEach((videoElement) => {
                if (videoElement.id !== currentSlideVideoId) {
                  if (Object.keys(this.hlsObj).length !== 0 && this.hlsIdx !== `${examId}-${idx}`) {
                    try {
                      this.hlsObj.destroy();
                      this.hlsObj = {};
                      this.hlsIdx = "";
                    } catch (error) {
                      // Do nothing. This is just to prevent the error showing up in the console (we force this error)
                    }
                  }

                  videoElement.textContent = "";
                }
              });
              // Remove all elements whose IDs contain the string `jpeg-v-div`,
              // except for the current slide's JPEG video player
              const currentSlideJpegVideoId = `jpeg-v-div-${this.examId}-${idx}`;
              const jpegVideoElements = document.querySelectorAll("[id*='jpeg-v-div']");
              jpegVideoElements.forEach((jpegVideoElement) => {
                if (jpegVideoElement.id.value !== currentSlideJpegVideoId) {
                  eventBus.$emit(`stopInterval`);

                }
              });
            },

Additional context

No response

@CodeTappert CodeTappert added the needs triage This issue has not been triaged by maintainers label Aug 15, 2023
@fancyapps fancyapps changed the title All Slides get initialized Repetition of events Aug 16, 2023
@fancyapps fancyapps added bug Something isn't working and removed needs triage This issue has not been triaged by maintainers labels Aug 16, 2023
@fancyapps
Copy link
Owner

Hi,

Indeed, there is a problem with repeating events (especially Carousel.createSlide and Carousel.removeSlide).
But the Carousel.initSlide event is expected to be fired for each slide. If you want to perform some action when the slide is created in the DOM, then use the Carousel.createSlide event.

@CodeTappert
Copy link
Author

Hello,
maybe there is a missunderstanding. I do nothing on createSlide or initSlide.

But on removeSlide. I basically need something similar to removeSlide but only for the Slides that to be removed from the DOM.

I know there is unselctSlide but this doesnt happen when i close the gallery

@fancyapps
Copy link
Owner

Yes, then use the Carousel.removeSlide event, I will fix the repetition.

@fancyapps
Copy link
Owner

Hi, It should be fixed in the latest release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants