diff --git a/modules/customdevslider/js/front.js b/modules/customdevslider/js/front.js index e6f234df..33769ba7 100644 --- a/modules/customdevslider/js/front.js +++ b/modules/customdevslider/js/front.js @@ -17,10 +17,14 @@ $(function () { if ( !$container.length || !$paginationEl.length || + !$textBox.length || typeof Swiper === 'undefined' ) return + // ----------------------------- + // TITLES + // ----------------------------- var titles = [] try { titles = JSON.parse($root.attr('data-titles') || '[]') @@ -28,23 +32,61 @@ $(function () { titles = [] } + // ----------------------------- + // SET SLIDE HTML BY INDEX + // ----------------------------- function setHtmlByIndex(idx) { var $slide = $container.find('.swiper-slide').eq(idx) var html = - $slide.find('.customdevslider-swiper__slide-html').first().html() || '' + $slide + .find('.customdevslider-swiper__slide-html') + .first() + .html() || '' + $textBox.html(html) } + // ----------------------------- + // CALC MAX TEXT HEIGHT + // ----------------------------- + function setMaxTextHeight() { + var maxHeight = 0 + var originalHtml = $textBox.html() + + $container.find('.swiper-slide').each(function () { + var html = $(this) + .find('.customdevslider-swiper__slide-html') + .first() + .html() + + if (!html) return + + $textBox.html(html) + $textBox.css('height', 'auto') + + var h = $textBox.outerHeight(true) + if (h > maxHeight) maxHeight = h + }) + + $textBox.html(originalHtml) + $textBox.height(maxHeight) + } + + // ----------------------------- + // INIT SWIPER + // ----------------------------- var swiper = new Swiper($container[0], { loop: true, speed: 600, + autoplay: { delay: 5000, }, - // fade effect: 'fade', - fadeEffect: { crossFade: true }, + fadeEffect: { + crossFade: true, + }, pagination: { el: $paginationEl[0], @@ -70,29 +112,7 @@ $(function () { }, }) + // fallback setHtmlByIndex(0) }) - - function setMaxTextHeight() { - var maxHeight = 0 - var originalHtml = $textBox.html() - - $container.find('.swiper-slide').each(function () { - var html = $(this) - .find('.customdevslider-swiper__slide-html') - .first() - .html() - - if (!html) return - - $textBox.html(html) - $textBox.css('height', 'auto') - - var h = $textBox.outerHeight(true) - if (h > maxHeight) maxHeight = h - }) - - $textBox.html(originalHtml) - $textBox.height(maxHeight) - } }) diff --git a/modules/customdevslider/views/templates/hook/slider.tpl b/modules/customdevslider/views/templates/hook/slider.tpl index c9e21b63..993fecc3 100644 --- a/modules/customdevslider/views/templates/hook/slider.tpl +++ b/modules/customdevslider/views/templates/hook/slider.tpl @@ -26,7 +26,6 @@ {/if} - {* ВАЖЛИВО: зберігаємо HTML структуру тексту *} @@ -34,7 +33,6 @@ {/foreach} - {* ОДИН overlay content на весь слайдер *}