import $ from 'jquery'; import Hammer from 'hammerjs'; require('jquery.easing'); class IHKSlider { constructor(section) { this.section = section.addClass('initiated'); this.slides = section.children(); this.slideOverflow = $('
').appendTo(section); this.slideWrapper = $('
').appendTo(this.slideOverflow).append(this.slides); this.currentSlide = 0; this.autoplayTimeout = 0; this.isHovered = false; this.sectionInitialClicked = false; this.dragging = false; this.inViewport = false; this.positionAnimation = { x: 0 } this.settings = { loop: false, autoplay: this.section.data('autoplay'), infinite: true, autoplaySpeed: this.section.data('autoplay-speed') ? this.section.data('autoplay-speed') : 5000, animationSpeed: 600, startSlide: 0 }; this.initSlides(); if (this.settings.infinite) { this.initInfinity(); } this.initUI(); this.checkSize(); if (this.slides.length > 1) { this.initHammerDragging(); this.initTabbing(); } this.changeSlide(this.settings.startSlide); this.initAutoplay(); this.checkSize(); if (this.section.closest('.steps').length) { this.setupSteps(); } $(window).on('resize', () => { this.checkSize(); }) } initSlides() { this.slides.each(function (i) { const slide = $(this).attr('data-index', i); const h3 = slide.find('h3, .like-h2, .like-h3').first(); const p = h3.next('p'); const dotsString = '…' if (!slide.find('.image-box').length) { slide.addClass('text-only'); } else { if (h3.text().length > 48) { h3.html(h3.text().substring(0, 48) + dotsString); } if (p.text().length > 148) { p.html(p.text().substring(0, 148) + dotsString); } } }) } checkSize() { if (this.controls.find('.tabs').width() > this.slideOverflow.width() * 0.6) { this.section.addClass('many-slides'); } else { this.section.removeClass('many-slides'); } } initInfinity() { this.nextWrapper = this.slideWrapper.clone(); this.prevWrapper = this.slideWrapper.clone(); this.nextWrapper .removeClass('slide-wrapper') .addClass('next-clone') .appendTo(this.slideWrapper) .css({'left': this.slides.length + '%'}); this.prevWrapper .removeClass('slide-wrapper') .addClass('prev-clone') .appendTo(this.slideWrapper); this.nextWrapper.find('a, button, input, select, textarea').attr('tabindex', -1); this.prevWrapper.find('a, button, input, select, textarea').attr('tabindex', -1); this.nextWrapper.find('img').removeClass('loading'); this.prevWrapper.find('img').removeClass('loading'); } initUI() { this.count = $(''); this.prevButton = $('