(function($) { if (typeof loadAdContent !== 'function') { function loadAdContent(parentDiv, url, link, timer) { var xhr = new XMLHttpRequest(); xhr.onreadystatechange = function() { if (xhr.readyState === XMLHttpRequest.DONE) { if (xhr.status === 200) { parentDiv.innerHTML = xhr.responseText; $('.slider').each(function() { if (!$(this).attr('slide')) { $(this).attr('slide',1); $('a', this ).attr('href', link); initializeAdSlider($(this), timer); } }); } } }; xhr.open('GET', url); xhr.send(); } function initializeAdSlider(slider, timer) { var sliderWidth = slider.width(); var slides = slider.find('.slides'); var totalSlides = slides.find('.slide').length; var autoSlideInterval = timer * 1000; var currentSlide = 0; $(window).on('resize', function() { sliderWidth = slider.width(); slides.width(sliderWidth * totalSlides); goToSlide(currentSlide); }); slides.width(sliderWidth * totalSlides); function goToSlide(index) { currentSlide = index; slides.css('transform', 'translateX(-' + (currentSlide * sliderWidth) + 'px)'); } function nextSlide() { currentSlide = (currentSlide + 1) % totalSlides; goToSlide(currentSlide); } var autoSlide = setInterval(nextSlide, autoSlideInterval); } } var thisScript = document.currentScript; var parentDiv = thisScript.parentElement; $(document).ready(function() { if (parentDiv) { var link = '#'; if (typeof thisScript.attributes['link'] !== 'undefined' ) { link = thisScript.attributes['link'].value; } var timer = 3; if (typeof thisScript.attributes['timer'] !== 'undefined' ) { timer = thisScript.attributes['timer'].value; } if (typeof thisScript.attributes['size'] !== 'undefined' ) { var url = '/loads/' + thisScript.attributes['size'].value; loadAdContent(parentDiv, url, link, timer); } } }); })(jQuery);