').html(clonedBackgrounds).insertBefore('#slideshow-' + recordUid); $('#slideshow-' + recordUid + '-background').find('.bh__background').first().addClass('active'); $('#slideshow-' + recordUid).cycle(); function getProgressBarPath() { if (!progressBarPath) { progressBarPath = new ProgressBar.Path(pauseIcon.querySelector(progressSelector), { duration: arrowAnimateTime, }); } return progressBarPath; } var pauseIcon = $('#pause-icon-' + recordUid).get(0), slideshowContainer = $('#slideshow-' + recordUid); $('#slideshow-' + recordUid).waypoint(function(direction) { if (autoplay) { if (pauseIcon && pauseIcon.querySelector(progressSelector)) { var path = getProgressBarPath(); path.animate(1.0, function() { path.set(0); }); } $('#slideshow-' + recordUid).cycle('resume'); } }, { offset: 'bottom-in-view' }) slideshowContainer.on('cycle-before', function( e, opts, outgoingSlideEl, incomingSlideEl, forwardFlag) { $('#slideshow-' + recordUid + '-background').find('.bh__background.active').removeClass('active'); $('#slideshow-' + recordUid + '-background').find('.bh__background').eq(opts.nextSlide).addClass('active'); if ( !(slideshowContainer.is('.cycle-paused')) && $('#pause-icon-' + recordUid).is(':visible') ) { var arrowAnimateTime = {arrowAnimateTime}; if (pauseIcon && pauseIcon.querySelector(progressSelector)) { var path = getProgressBarPath(true); path.set(0); path.animate(1.0, function() { path.set(0); }); } } $video = $('#slideshow-' + recordUid + '-background').find('.bh__background').eq(opts.currSlide).find('video'); if ($video.length) { $video.each(function() { $(this).hide(); this.pause(); }); } $video = $('#slideshow-' + recordUid + '-background').find('.bh__background').eq(opts.nextSlide).find('video'); if ($video.length) { $video.each(function() { $(this).show(); var playPromise = this.play(); if (playPromise !== undefined) { playPromise.then(_ => { $(this).parent().addClass('video-init'); }) .catch(error => { // Auto-play was prevented // Show paused UI. }); } }); } }); slideshowContainer.on('cycle-initialized', function( e, opts) { $video = $('#slideshow-' + recordUid + '-background').find('.bh__background').eq(0).find('video'); if ($video.length) { $video.each(function() { this.play(); }); } }); slideshowContainer.on('cycle-paused', function( e, opts) { $('#pause-' + recordUid).hide(); $('#resume-' + recordUid).show(); }); slideshowContainer.on('cycle-resumed', function( e, opts) { var path = getProgressBarPath(); path.set(0); path.stop(); path.animate(1.0, function() { path.set(0); }); $('#resume-' + recordUid).hide(); $('#pause-' + recordUid).show(); }); slideshowContainer.on('cycle-next cycle-prev', function( e, opts) { $('#slideshow-' + recordUid).cycle('resume'); }); // slideshowContainer.on('cycle-next cycle-prev cycle-pager-activated', function( e, opts ) { slideshowContainer.on('cycle-pager-activated', function( e, opts ) { slideshowContainer.cycle('pause'); // Reset the animation when paused. if (pauseIcon && pauseIcon.querySelector(progressSelector)) { var path = getProgressBarPath(); path.stop(); path.set(0); } }); $('body').on('addtovisit:opening', function() { slideshowContainer.cycle('pause'); // Reset the animation when paused. if (pauseIcon && pauseIcon.querySelector(progressSelector)) { var path = getProgressBarPath(); path.stop(); path.set(0); } }); $('body').on('addtovisit:closed', function() { slideshowContainer.cycle('resume'); var arrowAnimateTime = {arrowAnimateTime}; if (pauseIcon) { var path = getProgressBarPath(); path.stop(); path.set(0); path.animate(1.0, function() { path.set(0); }); } }); // @todo - See if we can get this working without causing problems on all of the non-feature slides on the site slideshowContainer.css('height', slideshowContainer.find('.slide.first').height()).cycle(); setTimeout(function() { slideshowContainer.css('height', 'auto'); }, 500); });