OwlCarousel2/OwlCarousel2

`replace.owl.carousel` should accept an options object to reset the carousels options

Open

#935 aberto em 14 de jul. de 2015

Ver no GitHub
 (5 comments) (6 reactions) (0 assignees)JavaScript (2.315 forks)batch import
approved for developmentfeature requesthelp wanted

Métricas do repositório

Stars
 (7.861 stars)
Métricas de merge de PR
 (Nenhuma PRs mesclada em 30d)

Description

When triggering replace.owl.carousel to change all the content of a carousel, we should be able to an options object that contains new options for the carousel. This could happen two different ways:

  • Adding a third parameter to the trigger call with an options object
$('.owl-carousel').trigger('replace.owl.carousel', '<div class="owl-item">Content</div><div class="item">More Content</div>', { loop: false });
  • Function overloading -- we could use the type of psuedo-function overloading that is common in JavaScript, where we check if the first argument is markup or an object. This would allow us to continue with the current pattern or the newer, more powerful pattern with new options:
// Old pattern
$('.owl-carousel').trigger('replace.owl.carousel', '<div class="owl-item">Content</div><div class="item">More Content</div>');

// New pattern
$('.owl-carousel').trigger('replace.owl.carousel', {
  markup: '<div class="owl-item">Content</div><div class="item">More Content</div>',
  options: { loop: true }
});

In addition, we currently have to manually trigger refresh.owl.carousel. We should change this so that the refresh method is called by the replace method so that we don't have to trigger this additional event.

$('.owl-carousel')
    .trigger('replace.owl.carousel', '<div class="owl-item">Content</div><div class="item">More Content</div>')
    .trigger('refresh.owl.carousel');

to just:

$('.owl-carousel').trigger('replace.owl.carousel', '<div class="owl-item">Content</div><div class="item">More Content</div>');
If you are interested in implementing this, please reply here and let us know!

Guia do colaborador