You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

115 lines
4.4 KiB

2 years ago
  1. jQuery(document).ready(function ($) {
  2. var sliderContainers = $('.cd-slider-wrapper');
  3. if (sliderContainers.length > 0) initBlockSlider(sliderContainers);
  4. var slides;
  5. var sliderPagination;
  6. var counter = 1;
  7. function initBlockSlider(sliderContainers) {
  8. sliderContainers.each(function () {
  9. var sliderContainer = $(this);
  10. slides = sliderContainer.children('.cd-slider').children('li'),
  11. sliderPagination = createSliderPagination(sliderContainer);
  12. sliderPagination.on('click', function (event) {
  13. event.preventDefault();
  14. var selected = $(this),
  15. index = selected.index();
  16. counter = index + 1;
  17. resetAutoSlideNext();
  18. updateSlider(index, sliderPagination, slides);
  19. });
  20. sliderContainer.on('swipeleft', function () {
  21. var bool = enableSwipe(sliderContainer),
  22. visibleSlide = sliderContainer.find('.is-visible').last(),
  23. visibleSlideIndex = visibleSlide.index();
  24. counter = visibleSlideIndex + 2;
  25. resetAutoSlideNext();
  26. if (bool) {
  27. if (!visibleSlide.is(':last-child')) { updateSlider(visibleSlideIndex + 1, sliderPagination, slides); }
  28. else { updateSlider(0, sliderPagination, slides); }
  29. }
  30. });
  31. sliderContainer.on('swiperight', function () {
  32. var bool = enableSwipe(sliderContainer),
  33. visibleSlide = sliderContainer.find('.is-visible').last(),
  34. visibleSlideIndex = visibleSlide.index();
  35. counter = visibleSlideIndex;
  36. resetAutoSlideNext();
  37. if (bool) {
  38. if (!visibleSlide.is(':first-child')) { updateSlider(visibleSlideIndex - 1, sliderPagination, slides); }
  39. else { updateSlider(3, sliderPagination, slides); }
  40. }
  41. });
  42. });
  43. }
  44. var interval = setInterval(function () { autoSlideNext(); }, 7000);
  45. function resetAutoSlideNext() {
  46. clearInterval(interval);
  47. interval = setInterval(function () { autoSlideNext(); }, 7000);
  48. }
  49. function stopAutoSlideNext() {
  50. clearInterval(interval);
  51. }
  52. function autoSlideNext() {
  53. if (counter >= 4) { counter = 0; }
  54. updateSlider(counter, sliderPagination, slides);
  55. counter += 1;
  56. }
  57. function createSliderPagination(container) {
  58. var wrapper = $('<ol class="cd-slider-navigation"></ol>');
  59. container.children('.cd-slider').find('li').each(function (index) {
  60. var dotWrapper = (index == 0) ? $('<li class="selected"></li>') : $('<li></li>'),
  61. dot = $('<a href="#0"></a>').appendTo(dotWrapper);
  62. dotWrapper.appendTo(wrapper);
  63. var dotText = (index + 1 < 10) ? '0' + (index + 1) : index + 1;
  64. dot.text(dotText);
  65. });
  66. wrapper.appendTo(container);
  67. return wrapper.children('li');
  68. }
  69. function updateSlider(n, navigation, slides) {
  70. navigation.removeClass('selected').eq(n).addClass('selected');
  71. slides.eq(n).addClass('is-visible').removeClass('covered').prevAll('li').addClass('is-visible covered').end().nextAll('li').removeClass('is-visible covered');
  72. //fixes a bug on Firefox with ul.cd-slider-navigation z-index
  73. navigation.parent('ul').addClass('slider-animating').on('webkitTransitionEnd otransitionend oTransitionEnd msTransitionEnd transitionend', function () {
  74. $(this).removeClass('slider-animating');
  75. });
  76. }
  77. function enableSwipe(container) {
  78. return (container.parents('.touch').length > 0);
  79. }
  80. $('.popup-link').click(function () {
  81. var items = [];
  82. $($(this).attr('href')).find('.mfp-figure').each(function () {
  83. items.push({
  84. src: $(this)
  85. });
  86. });
  87. $.magnificPopup.open({
  88. items: items,
  89. gallery: {
  90. enabled: true
  91. },
  92. callbacks: {
  93. open: function () {
  94. stopAutoSlideNext();
  95. $('html').css('margin-right', 0);
  96. },
  97. close: function () {
  98. resetAutoSlideNext();
  99. }
  100. }
  101. });
  102. });
  103. });