/*-----------------------------------------------------------*/ // Scripts for Layout Gallery Components /*-----------------------------------------------------------*/ jQuery(document).ready(function() { jQuery('.placeholder-controls a').on('click', function(event) { event.preventDefault(); }); }); /** * Masthead Gallery */ jQuery(window).load(function() { //center Masthead Images centerMastheadImages(); setTimeout(function() { jQuery(window).resize(function() { centerMastheadImages(); }); }, 1000); var mastheadSliders = jQuery('.masthead-slider'); mastheadSliders.each(function() { var currentSlider = jQuery(this); var currentSliderID = currentSlider.attr('data-slider-id'); var currentSliderContentData = currentSlider.data('sliderContent'); var currentSliderAuto = currentSlider.attr('data-slider-auto'); //if first slide is a video, init slider var slideVideo = currentSlider.find('.video'); //trigger load slider event if (Modernizr.touch) { currentSlider.on('touchstart.loadSlider', function() { currentSlider.off('touchstart.loadSlider'); currentSlider.prepend(currentSliderContentData); var currentViewport = jQuery('body').attr('data-view'); ADimageSwap(currentViewport); currentSlider.imagesLoaded(function() { currentSlider.trigger('adLayoutSliderReady', currentSliderID); }); }); currentSlider.trigger('touchstart.loadSlider'); } else { currentSlider.on('mouseenter.loadSlider', function() { currentSlider.off('mouseenter.loadSlider'); currentSlider.prepend(currentSliderContentData); var currentViewport = jQuery('body').attr('data-view'); ADimageSwap(currentViewport); currentSlider.imagesLoaded(function() { currentSlider.trigger('adLayoutSliderReady', currentSliderID); }); }); if (currentSliderAuto != undefined || slideVideo.length > 0) { currentSlider.trigger('mouseenter.loadSlider'); } } }); }); jQuery(document).ready(function() { //initialize slider jQuery('.masthead-slider').on('adLayoutSliderReady', function(event, sliderID) { var currentSliderID = sliderID; var currentSlider = jQuery('.masthead-slider[data-slider-id="'+ currentSliderID +'"]'); var currentSliderAuto = currentSlider.attr('data-slider-auto'); var currentSliderSpeed = currentSlider.attr('data-slider-speed'); var currentSliderPlaceholder = currentSlider.find('.masthead-placeholder-container'); var currentSliderPlaceholderControls = currentSlider.find('.placeholder-controls'); currentSliderPlaceholderControls.remove(); var sliderAuto = currentSliderAuto == undefined ? false : true; var sliderSpeed = currentSliderSpeed == undefined ? 7000 : parseInt(currentSliderSpeed); currentSlider.flexslider({ animation: 'fade', slideshow: sliderAuto, slideshowSpeed: sliderSpeed, multipleKeyboard: true, controlsContainer: '.controls-'+ currentSliderID, controlNav: false, start: function(slider) { setTimeout(function() { currentSliderPlaceholder.remove(); currentSlider.trigger('adLayoutSliderInitialized', currentSliderID); }, 400); var incomingSlide = slider.find('.slide').eq(0); var slideVideo = incomingSlide.find('.masthead-slide-video'); if (slideVideo.length > 0) { var videoPlayerElement = slideVideo.find('.video-element').attr('id'); sliderPlayVideo(videoPlayerElement); } centerMastheadImages(); //load next slide image var nextSlide = incomingSlide.next('.slide'); if (nextSlide.length > 0) { var nextSlideVideo = nextSlide.find('.masthead-slide-video'); if (nextSlide.attr('data-lazy-load') != undefined && nextSlideVideo.length == 0) { nextSlide.addClass('loading'); var loadID = nextSlide.attr('data-image-id'); var loadSizeDesktop = nextSlide.attr('data-image-size-desktop'); var loadSizeMobile = nextSlide.attr('data-image-size-mobile'); var viewportMode = jQuery('body').attr('data-view'); jQuery.post( adLayoutGalleryExtAjax.ajaxurl, { action : 'gallery-lazy-load', attachmentID : loadID, imageSizeDesktop : loadSizeDesktop, imageSizeMobile : loadSizeMobile, viewport : viewportMode, classes : 'masthead-image' }, function( response ) { nextSlide.find('.masthead-slide-image').append(response); nextSlide.removeAttr('data-lazy-load data-image-id'); nextSlide.imagesLoaded(function() { centerMastheadImages(); nextSlide.removeClass('loading'); nextSlide.find('.preloader').remove(); }); } ); } } }, before: function(slider) { //incoming slide var incomingSlide = slider.find('.slide').eq(slider.animatingTo); var slideVideo = incomingSlide.find('.masthead-slide-video'); if (slideVideo.length > 0) { var videoPlayerElement = slideVideo.find('.video-element').attr('id'); sliderPlayVideo(videoPlayerElement); } //load incoming slide if not already loaded if (incomingSlide.attr('data-lazy-load') != undefined && incomingSlide.hasClass('loading') == false && slideVideo.length == 0) { incomingSlide.addClass('loading'); var loadID = incomingSlide.attr('data-image-id'); var loadSizeDesktop = incomingSlide.attr('data-image-size-desktop'); var loadSizeMobile = incomingSlide.attr('data-image-size-mobile'); var viewportMode = jQuery('body').attr('data-view'); jQuery.post( adLayoutGalleryExtAjax.ajaxurl, { action : 'gallery-lazy-load', attachmentID : loadID, imageSizeDesktop : loadSizeDesktop, imageSizeMobile : loadSizeMobile, viewport : viewportMode, classes : 'masthead-image' }, function( response ) { incomingSlide.find('.masthead-slide-image').append(response); incomingSlide.removeAttr('data-lazy-load data-image-id'); incomingSlide.imagesLoaded(function() { centerMastheadImages(); incomingSlide.removeClass('loading'); incomingSlide.find('.preloader').remove(); }); } ); } //ensure slide is ready if (incomingSlide.hasClass('loading')) { var activeSlide = slider.find('.flex-active-slide'); activeSlide.addClass('waiting'); var slideInterval = setInterval(function() { if (incomingSlide.hasClass('loading') === false) { clearInterval(slideInterval); setTimeout(function() { activeSlide.removeClass('waiting'); }, 600); } }, 250); } //load next slide image if (slider.direction == 'prev') { var nextSlide = incomingSlide.prev('.slide'); } else { var nextSlide = incomingSlide.next('.slide'); } if (nextSlide.length > 0) { var nextSlideVideo = nextSlide.find('.masthead-slide-video'); if (nextSlide.attr('data-lazy-load') != undefined && nextSlideVideo.length == 0) { nextSlide.addClass('loading'); var loadID = nextSlide.attr('data-image-id'); var loadSizeDesktop = nextSlide.attr('data-image-size-desktop'); var loadSizeMobile = nextSlide.attr('data-image-size-mobile'); var viewportMode = jQuery('body').attr('data-view'); jQuery.post( adLayoutGalleryExtAjax.ajaxurl, { action : 'gallery-lazy-load', attachmentID : loadID, imageSizeDesktop : loadSizeDesktop, imageSizeMobile : loadSizeMobile, viewport : viewportMode, classes : 'masthead-image' }, function( response ) { nextSlide.find('.masthead-slide-image').append(response); nextSlide.removeAttr('data-lazy-load data-image-id'); nextSlide.imagesLoaded(function() { centerMastheadImages(); nextSlide.removeClass('loading'); nextSlide.find('.preloader').remove(); }); } ); } } }, after: function(slider) { nonActiveSlides = slider.find('.slide').not('.flex-active-slide'); nonActiveSlides.each(function() { var nonActiveSlide = jQuery(this); var slideVideo = nonActiveSlide.find('.masthead-slide-video'); if (slideVideo.length > 0) { var videoPlayerElement = slideVideo.find('.video-element').attr('id'); sliderPauseVideo(videoPlayerElement); } }); } }); }); //center images on swap jQuery('body').on('imagesSwapped.adLayout', function() { centerMastheadImages(); }); }); //image centering function centerMastheadImages() { var containerWidth = jQuery(window).width(); jQuery('.masthead-slider').each(function() { var slideImages = jQuery(this).find('img.masthead-image'); slideImages.each(function() { var slideImg = jQuery(this); var containerHeight = slideImg.parent().height(); //use attributes so it works on invisible images and fix ajax load var slideImgWidth = slideImg.attr('width'); var slideImgHeight = slideImg.attr('height'); //if image is stretched var slideImgForcedWidth = slideImg.width(); if (slideImgForcedWidth != slideImgWidth) { slideImgWidth = slideImgForcedWidth; var difference = slideImgForcedWidth / slideImg.attr('width'); slideImgHeight = Math.round(slideImg.attr('height') * difference); } //console.log('imgwidth: '+ slideImgWidth +' imgheight: '+ slideImgHeight +' contwidth: '+ containerWidth +' contheight: '+ containerHeight +' '); //width if (slideImgWidth >= containerWidth) { var imgOffset = -((slideImgWidth - containerWidth)/2); slideImg.css('left', imgOffset); } else { slideImg.css('left', 0); } //height if (slideImgHeight >= containerHeight) { var imgOffset = -((slideImgHeight - containerHeight)/2); slideImg.css('top', imgOffset); } else { slideImg.css('top', 0); } }); }); } /** * Full Width Masthead Gallery */ jQuery(window).load(function() { //center Masthead Images centerMastheadFullImages(); setTimeout(function() { jQuery(window).resize(function() { centerMastheadFullImages(); }); }, 1000); var mastheadFullSliders = jQuery('.masthead-full-slider'); mastheadFullSliders.each(function() { var currentSlider = jQuery(this); var currentSliderID = currentSlider.attr('data-slider-id'); var currentSliderContentData = currentSlider.data('sliderFullContent'); var currentSliderParams = currentSlider.data('sliderFullParams'); var currentSliderAuto = currentSliderParams['slider_auto']; //if first slide is a video, init slider var slideVideo = currentSlider.find('.video'); //trigger load slider event if (Modernizr.touch) { currentSlider.on('touchstart.loadSlider', function() { currentSlider.off('touchstart.loadSlider'); currentSlider.prepend(currentSliderContentData); var currentViewport = jQuery('body').attr('data-view'); ADimageSwap(currentViewport); currentSlider.imagesLoaded(function() { currentSlider.trigger('adLayoutSliderFullReady', currentSliderID); }); }); currentSlider.trigger('touchstart.loadSlider'); } else { currentSlider.on('mouseenter.loadSlider', function() { currentSlider.off('mouseenter.loadSlider'); currentSlider.prepend(currentSliderContentData); var currentViewport = jQuery('body').attr('data-view'); ADimageSwap(currentViewport); currentSlider.imagesLoaded(function() { currentSlider.trigger('adLayoutSliderFullReady', currentSliderID); }); }); if (currentSliderAuto != undefined || slideVideo.length > 0) { currentSlider.trigger('mouseenter.loadSlider'); } } }); }); jQuery(document).ready(function() { //initialize slider jQuery('.masthead-full-slider').on('adLayoutSliderFullReady', function(event, sliderID) { var currentSliderID = sliderID; var currentSlider = jQuery('.masthead-full-slider[data-slider-id="'+ currentSliderID +'"]'); var currentSliderPlaceholder = currentSlider.find('.masthead-full-placeholder-container'); var currentSliderPlaceholderControls = currentSlider.find('.placeholder-controls'); currentSliderPlaceholderControls.remove(); var currentSliderParams = currentSlider.data('sliderFullParams'); var currentSliderAuto = currentSliderParams['slider_auto']; var currentSliderSpeed = currentSliderParams['slider_speed']; var sliderAuto = currentSliderAuto == undefined ? false : true; var sliderSpeed = currentSliderSpeed == undefined ? 7000 : parseInt(currentSliderSpeed); currentSlider.flexslider({ animation: 'fade', slideshow: sliderAuto, slideshowSpeed: sliderSpeed, multipleKeyboard: true, controlsContainer: '.controls-'+ currentSliderID, controlNav: false, start: function(slider) { setTimeout(function() { currentSliderPlaceholder.remove(); currentSlider.trigger('adLayoutSliderFullInitialized', currentSliderID); }, 400); var incomingSlide = slider.find('.slide').eq(0); var slideVideo = incomingSlide.find('.masthead-slide-video'); if (slideVideo.length > 0) { var videoPlayerElement = slideVideo.find('.video-element').attr('id'); sliderPlayVideo(videoPlayerElement); } centerMastheadFullImages(); //load next slide image var nextSlide = incomingSlide.next('.slide'); if (nextSlide.length > 0) { var nextSlideVideo = nextSlide.find('.masthead-slide-video'); if (nextSlide.attr('data-lazy-load') != undefined && nextSlideVideo.length == 0) { nextSlide.addClass('loading'); var loadID = nextSlide.attr('data-image-id'); var loadSizeDesktop = nextSlide.attr('data-image-size-desktop'); var loadSizeMobile = nextSlide.attr('data-image-size-mobile'); var viewportMode = jQuery('body').attr('data-view'); jQuery.post( adLayoutGalleryExtAjax.ajaxurl, { action : 'gallery-lazy-load', attachmentID : loadID, imageSizeDesktop : loadSizeDesktop, imageSizeMobile : loadSizeMobile, viewport : viewportMode, classes : 'masthead-full-image' }, function( response ) { nextSlide.find('.masthead-full-slide-image').append(response); nextSlide.removeAttr('data-lazy-load data-image-id'); nextSlide.imagesLoaded(function() { centerMastheadFullImages(); nextSlide.removeClass('loading'); nextSlide.find('.preloader').remove(); }); } ); } } }, before: function(slider) { var incomingSlide = slider.find('.slide').eq(slider.animatingTo); var slideVideo = incomingSlide.find('.masthead-slide-video'); if (slideVideo.length > 0) { var videoPlayerElement = slideVideo.find('.video-element').attr('id'); sliderPlayVideo(videoPlayerElement); } //load incoming slide if not already loaded if (incomingSlide.attr('data-lazy-load') != undefined && incomingSlide.hasClass('loading') == false && slideVideo.length == 0) { incomingSlide.addClass('loading'); var loadID = incomingSlide.attr('data-image-id'); var loadSizeDesktop = incomingSlide.attr('data-image-size-desktop'); var loadSizeMobile = incomingSlide.attr('data-image-size-mobile'); var viewportMode = jQuery('body').attr('data-view'); jQuery.post( adLayoutGalleryExtAjax.ajaxurl, { action : 'gallery-lazy-load', attachmentID : loadID, imageSizeDesktop : loadSizeDesktop, imageSizeMobile : loadSizeMobile, viewport : viewportMode, classes : 'masthead-full-image' }, function( response ) { incomingSlide.find('.masthead-full-slide-image').append(response); incomingSlide.removeAttr('data-lazy-load data-image-id'); incomingSlide.imagesLoaded(function() { centerMastheadFullImages(); incomingSlide.removeClass('loading'); incomingSlide.find('.preloader').remove(); }); } ); } //ensure slide is ready if (incomingSlide.hasClass('loading')) { var activeSlide = slider.find('.flex-active-slide'); activeSlide.addClass('waiting'); var slideInterval = setInterval(function() { if (incomingSlide.hasClass('loading') === false) { clearInterval(slideInterval); setTimeout(function() { activeSlide.removeClass('waiting'); }, 600); } }, 250); } //load next slide image if (slider.direction == 'prev') { var nextSlide = incomingSlide.prev('.slide'); } else { var nextSlide = incomingSlide.next('.slide'); } if (nextSlide.length > 0) { var nextSlideVideo = nextSlide.find('.masthead-slide-video'); if (nextSlide.attr('data-lazy-load') != undefined && nextSlideVideo.length == 0) { nextSlide.addClass('loading'); var loadID = nextSlide.attr('data-image-id'); var loadSizeDesktop = nextSlide.attr('data-image-size-desktop'); var loadSizeMobile = nextSlide.attr('data-image-size-mobile'); var viewportMode = jQuery('body').attr('data-view'); jQuery.post( adLayoutGalleryExtAjax.ajaxurl, { action : 'gallery-lazy-load', attachmentID : loadID, imageSizeDesktop : loadSizeDesktop, imageSizeMobile : loadSizeMobile, viewport : viewportMode, classes : 'masthead-full-image' }, function( response ) { nextSlide.find('.masthead-full-slide-image').append(response); nextSlide.removeAttr('data-lazy-load data-image-id'); nextSlide.imagesLoaded(function() { centerMastheadFullImages(); nextSlide.removeClass('loading'); nextSlide.find('.preloader').remove(); }); } ); } } }, after: function(slider) { nonActiveSlides = slider.find('.slide').not('.flex-active-slide'); nonActiveSlides.each(function() { var nonActiveSlide = jQuery(this); var slideVideo = nonActiveSlide.find('.masthead-slide-video'); if (slideVideo.length > 0) { var videoPlayerElement = slideVideo.find('.video-element').attr('id'); sliderPauseVideo(videoPlayerElement); } }); } }); }); //center images on swap jQuery('body').on('imagesSwapped.adLayout', function() { centerMastheadFullImages(); }); }); //image centering function centerMastheadFullImages() { var containerWidth = jQuery(window).width(); jQuery('.masthead-full-slider').each(function() { var slideImages = jQuery(this).find('img.masthead-full-image'); slideImages.each(function() { var slideImg = jQuery(this); var containerHeight = slideImg.closest('.masthead-full-slider').height(); //use attributes so it works on invisible images and fix ajax load var slideImgWidth = slideImg.attr('width'); var slideImgHeight = slideImg.attr('height'); //if image is stretched var slideImgForcedWidth = slideImg.width(); if (slideImgForcedWidth != slideImgWidth) { slideImgWidth = slideImgForcedWidth; var difference = slideImgForcedWidth / slideImg.attr('width'); slideImgHeight = Math.round(slideImg.attr('height') * difference); } //console.log('imgwidth: '+ slideImgWidth +' imgheight: '+ slideImgHeight +' contwidth: '+ containerWidth +' contheight: '+ containerHeight +' '); //width if (slideImgWidth >= containerWidth) { var imgOffset = -((slideImgWidth - containerWidth)/2); slideImg.css('left', imgOffset); } else { slideImg.css('left', 0); } slideImgHeight = slideImg.height(); //height if (slideImgHeight > containerHeight) { var imgOffset = -((slideImgHeight - containerHeight)/2); slideImg.css('top', imgOffset); } else { slideImg.css('top', 0); } }); }); } //Dynamic Masthead Height jQuery(document).ready(function() { if (!Modernizr.touch) { jQuery(window).load(function() { setMastheadFullHeight(); }); jQuery(window).on('resize', function() { setMastheadFullHeight(); }); jQuery('.masthead-slider').on('adLayoutSliderFullReady', function() { setMastheadFullHeight(); }); } }); function setMastheadFullHeight() { var mastheads = jQuery('.masthead-full-slider'); var viewportHeight = jQuery(window).height(); mastheads.each(function() { var masthead = jQuery(this); //get params var mastheadParams = masthead.data('sliderFullParams'); var viewportPercentage = mastheadParams.slider_dynamic_height.viewport_percentage; var maxHeight = mastheadParams.slider_dynamic_height.max_height; var minHeight = mastheadParams.slider_dynamic_height.min_height; var mastheadHeight = viewportHeight * (viewportPercentage / 100); if (mastheadHeight > maxHeight) { mastheadHeight = maxHeight; } else if (mastheadHeight < minHeight) { mastheadHeight = minHeight; } //set masthead height masthead.height(mastheadHeight); }); } /** * Inline Slider */ //inline slider jQuery(window).load(function() { var inlineSliders = jQuery('.inline-slider'); inlineSliders.each(function() { //trigger load slider event var currentSlider = jQuery(this); var currentSliderID = currentSlider.attr('data-slider-id'); var currentSliderContentData = currentSlider.data('sliderContent'); var currentSliderPlaceholder = currentSlider.find('.inline-slider-placeholder-container'); var currentSliderAuto = currentSlider.attr('data-slider-auto'); if (Modernizr.touch) { currentSlider.on('touchstart.loadSlider', function() { currentSlider.off('touchstart.loadSlider'); var currentSliderPlaceholderHeight = currentSliderPlaceholder.outerHeight(); currentSlider.css('height', currentSliderPlaceholderHeight+'px'); currentSliderPlaceholder.addClass('loading'); currentSlider.prepend(currentSliderContentData); var currentViewport = jQuery('body').attr('data-view'); ADimageSwap(currentViewport); currentSlider.imagesLoaded(function() { currentSlider.trigger('adLayoutInlineSliderReady', currentSliderID); }); }); currentSlider.trigger('touchstart.loadSlider'); } else { currentSlider.on('mouseenter.loadSlider', function() { currentSlider.off('mouseenter.loadSlider'); var currentSliderPlaceholderHeight = currentSliderPlaceholder.outerHeight(); currentSlider.css('height', currentSliderPlaceholderHeight+'px'); currentSliderPlaceholder.addClass('loading'); currentSlider.prepend(currentSliderContentData); var currentViewport = jQuery('body').attr('data-view'); ADimageSwap(currentViewport); currentSlider.imagesLoaded(function() { currentSlider.trigger('adLayoutInlineSliderReady', currentSliderID); }); }); if (currentSliderAuto != undefined) { currentSlider.trigger('mouseenter.loadSlider'); } } }); }); jQuery(document).ready(function() { jQuery('.inline-slider').on('adLayoutInlineSliderReady', function(event, sliderID) { var currentSliderID = sliderID; var currentSlider = jQuery('.inline-slider[data-slider-id="'+ currentSliderID +'"]'); var currentSliderPlaceholder = currentSlider.find('.inline-slider-placeholder-container'); var currentSliderPlaceholderControls = currentSlider.find('.placeholder-controls'); currentSliderPlaceholderControls.remove(); var currentSliderAuto = currentSlider.attr('data-slider-auto'); var currentSliderSpeed = currentSlider.attr('data-slider-speed'); var sliderAuto = currentSliderAuto == undefined ? false : true; var sliderSpeed = currentSliderSpeed == undefined ? 7000 : parseInt(currentSliderSpeed); currentSlider.flexslider({ animation: 'fade', slideshow: sliderAuto, slideshowSpeed: sliderSpeed, multipleKeyboard: true, controlsContainer: '.controls-'+ currentSliderID, controlNav: false, start: function(slider) { setTimeout(function() { currentSliderPlaceholder.remove(); currentSlider.css('height','auto'); currentSlider.trigger('adLayoutInlineSliderInitialized', currentSliderID); }, 400); //load next slide image var incomingSlide = slider.find('.slide').eq(0); var nextSlide = incomingSlide.next('.slide'); if (nextSlide.length > 0) { if (nextSlide.attr('data-lazy-load') != undefined) { nextSlide.addClass('loading'); var loadID = nextSlide.attr('data-image-id'); var loadSizeDesktop = nextSlide.attr('data-image-size-desktop'); var loadSizeMobile = nextSlide.attr('data-image-size-mobile'); var slideImageContainer = nextSlide.find('.inline-slide-image'); var sliderHeight = slider.outerHeight(); var viewportMode = jQuery('body').attr('data-view'); slideImageContainer.css('height', sliderHeight+'px'); jQuery.post( adLayoutGalleryExtAjax.ajaxurl, { action : 'gallery-lazy-load', attachmentID : loadID, imageSizeDesktop : loadSizeDesktop, imageSizeMobile : loadSizeMobile, viewport : viewportMode }, function( response ) { nextSlide.find('.inline-slide-image').append(response); nextSlide.removeAttr('data-lazy-load data-image-id'); nextSlide.imagesLoaded(function() { nextSlide.removeClass('loading'); nextSlide.find('.preloader').remove(); slideImageContainer.css('height', 'auto'); }); } ); } } }, before: function(slider) { var incomingSlide = slider.find('.slide').eq(slider.animatingTo); //load incoming slide if not already loaded if (incomingSlide.attr('data-lazy-load') != undefined && incomingSlide.hasClass('loading') == false) { incomingSlide.addClass('loading'); var loadID = incomingSlide.attr('data-image-id'); var loadSizeDesktop = incomingSlide.attr('data-image-size-desktop'); var loadSizeMobile = incomingSlide.attr('data-image-size-mobile'); var slideImageContainer = incomingSlide.find('.inline-slide-image'); var sliderHeight = slider.outerHeight(); var viewportMode = jQuery('body').attr('data-view'); slideImageContainer.css('height', sliderHeight+'px'); jQuery.post( adLayoutGalleryExtAjax.ajaxurl, { action : 'gallery-lazy-load', attachmentID : loadID, imageSizeDesktop : loadSizeDesktop, imageSizeMobile : loadSizeMobile, viewport : viewportMode }, function( response ) { incomingSlide.find('.inline-slide-image').append(response); incomingSlide.removeAttr('data-lazy-load data-image-id'); incomingSlide.imagesLoaded(function() { incomingSlide.removeClass('loading'); incomingSlide.find('.preloader').remove(); slideImageContainer.css('height', 'auto'); }); } ); } //ensure slide is ready if (incomingSlide.hasClass('loading')) { var activeSlide = slider.find('.flex-active-slide'); activeSlide.addClass('waiting'); var slideInterval = setInterval(function() { if (incomingSlide.hasClass('loading') === false) { clearInterval(slideInterval); setTimeout(function() { activeSlide.removeClass('waiting'); }, 600); } }, 250); } //load next slide image if (slider.direction == 'prev') { var nextSlide = incomingSlide.prev('.slide'); } else { var nextSlide = incomingSlide.next('.slide'); } if (nextSlide.length > 0) { if (nextSlide.attr('data-lazy-load') != undefined) { nextSlide.addClass('loading'); var loadID = nextSlide.attr('data-image-id'); var loadSizeDesktop = nextSlide.attr('data-image-size-desktop'); var loadSizeMobile = nextSlide.attr('data-image-size-mobile'); var slideImageContainer = nextSlide.find('.inline-slide-image'); var sliderHeight = slider.outerHeight(); var viewportMode = jQuery('body').attr('data-view'); slideImageContainer.css('height', sliderHeight+'px'); jQuery.post( adLayoutGalleryExtAjax.ajaxurl, { action : 'gallery-lazy-load', attachmentID : loadID, imageSizeDesktop : loadSizeDesktop, imageSizeMobile : loadSizeMobile, viewport : viewportMode }, function( response ) { nextSlide.find('.inline-slide-image').append(response); nextSlide.removeAttr('data-lazy-load data-image-id'); nextSlide.imagesLoaded(function() { nextSlide.removeClass('loading'); nextSlide.find('.preloader').remove(); slideImageContainer.css('height', 'auto'); }); } ); } } } }); }); }); /** * Image Gallery with Thumbnails */ jQuery(window).load(function() { //center Gallery Images centerGalleryImages(); setTimeout(function() { jQuery(window).resize(function() { centerGalleryImages(); }); }, 1000); var galleryWithThumbnails = jQuery('.gallery-thumbs'); galleryWithThumbnails.each(function() { //trigger load slider event var currentSlider = jQuery(this); var currentSliderID = currentSlider.attr('data-slider-id'); var currentSliderContentData = currentSlider.data('sliderContent'); var currentSliderContainer = currentSlider.closest('.gallery-thumbs-container'); var currentSliderAuto = currentSlider.attr('data-slider-auto'); if (Modernizr.touch) { currentSliderContainer.on('touchstart.loadSlider', function() { currentSliderContainer.off('touchstart.loadSlider'); currentSlider.prepend(currentSliderContentData); var currentViewport = jQuery('body').attr('data-view'); ADimageSwap(currentViewport); currentSlider.imagesLoaded(function() { currentSlider.trigger('adLayoutGalleryThumbsReady', currentSliderID); }); }); jQuery('a[data-toggle="tab"]').on('show.bs.tab', function (e) { jQuery(e.target).find('.gallery-thumbs').trigger('touchstart.loadSlider'); setTimeout(function() { jQuery(window).trigger('resize'); }, 100); }); currentSliderContainer.trigger('touchstart.loadSlider'); } else { currentSliderContainer.on('mouseenter.loadSlider', function() { currentSliderContainer.off('mouseenter.loadSlider'); currentSlider.prepend(currentSliderContentData); var currentViewport = jQuery('body').attr('data-view'); ADimageSwap(currentViewport); currentSlider.imagesLoaded(function() { currentSlider.trigger('adLayoutGalleryThumbsReady', currentSliderID); }); }); jQuery('a[data-toggle="tab"]').on('show.bs.tab', function (e) { jQuery(e.target).find('.gallery-thumbs').trigger('mouseenter.loadSlider'); setTimeout(function() { jQuery(window).trigger('resize'); }, 100); }); if (currentSliderAuto != undefined) { currentSliderContainer.trigger('mouseenter.loadSlider'); } } }); }); jQuery(document).ready(function() { //initialize slider jQuery('.gallery-thumbs').on('adLayoutGalleryThumbsReady', function(event, sliderID) { var currentSliderID = sliderID; var currentSlider = jQuery('.gallery-thumbs[data-slider-id="'+ currentSliderID +'"]'); var currentSliderPlaceholder = currentSlider.find('.gallery-thumbs-placeholder-container'); var currentSliderPlaceholderControls = currentSlider.find('.placeholder-controls'); currentSliderPlaceholderControls.remove(); var currentSliderAuto = currentSlider.attr('data-slider-auto'); var currentSliderSpeed = currentSlider.attr('data-slider-speed'); var sliderAuto = currentSliderAuto == undefined ? false : true; var sliderSpeed = currentSliderSpeed == undefined ? 7000 : parseInt(currentSliderSpeed); currentSlider.flexslider({ animation: 'fade', slideshow: sliderAuto, slideshowSpeed: sliderSpeed, multipleKeyboard: true, controlNav: false, controlsContainer: '.controls-'+ currentSliderID, sync: '.gallery-thumbs-nav[data-slider-id="'+ currentSliderID +'"]', start: function(slider) { setTimeout(function() { currentSliderPlaceholder.remove(); currentSlider.trigger('adLayoutGalleryThumbsInitialized', currentSliderID); }, 400); centerGalleryImages(slider); //load next slide image var incomingSlide = slider.find('.slide').eq(0); var nextSlide = incomingSlide.next('.slide'); if (nextSlide.length > 0) { if (nextSlide.attr('data-lazy-load') != undefined) { nextSlide.addClass('loading'); var loadID = nextSlide.attr('data-image-id'); var loadSizeDesktop = nextSlide.attr('data-image-size-desktop'); var loadSizeMobile = nextSlide.attr('data-image-size-mobile'); var viewportMode = jQuery('body').attr('data-view'); jQuery.post( adLayoutGalleryExtAjax.ajaxurl, { action : 'gallery-lazy-load', attachmentID : loadID, imageSizeDesktop : loadSizeDesktop, imageSizeMobile : loadSizeMobile, viewport : viewportMode, classes : 'gallery-thumbs-image' }, function( response ) { nextSlide.prepend(response).removeAttr('data-lazy-load data-image-id'); nextSlide.imagesLoaded(function() { centerGalleryImages(slider); nextSlide.removeClass('loading'); nextSlide.find('.preloader').remove(); }); } ); } } }, before: function(slider) { var incomingSlide = slider.find('.slide').eq(slider.animatingTo); //load incoming slide if not already loaded if (incomingSlide.attr('data-lazy-load') != undefined && incomingSlide.hasClass('loading') == false) { incomingSlide.addClass('loading'); var loadID = incomingSlide.attr('data-image-id'); var loadSizeDesktop = incomingSlide.attr('data-image-size-desktop'); var loadSizeMobile = incomingSlide.attr('data-image-size-mobile'); var viewportMode = jQuery('body').attr('data-view'); jQuery.post( adLayoutGalleryExtAjax.ajaxurl, { action : 'gallery-lazy-load', attachmentID : loadID, imageSizeDesktop : loadSizeDesktop, imageSizeMobile : loadSizeMobile, viewport : viewportMode, classes : 'gallery-thumbs-image' }, function( response ) { incomingSlide.prepend(response).removeAttr('data-lazy-load data-image-id'); incomingSlide.imagesLoaded(function() { centerGalleryImages(slider); incomingSlide.removeClass('loading'); incomingSlide.find('.preloader').remove(); }); } ); } //ensure slide is ready if (incomingSlide.hasClass('loading')) { var activeSlide = slider.find('.flex-active-slide'); activeSlide.addClass('waiting'); var slideInterval = setInterval(function() { if (incomingSlide.hasClass('loading') === false) { clearInterval(slideInterval); setTimeout(function() { activeSlide.removeClass('waiting'); }, 600); } }, 250); } //load next slide image if (slider.direction == 'prev') { var nextSlide = incomingSlide.prev('.slide'); } else { var nextSlide = incomingSlide.next('.slide'); } if (nextSlide.length > 0) { if (nextSlide.attr('data-lazy-load') != undefined) { nextSlide.addClass('loading'); var loadID = nextSlide.attr('data-image-id'); var loadSizeDesktop = nextSlide.attr('data-image-size-desktop'); var loadSizeMobile = nextSlide.attr('data-image-size-mobile'); var viewportMode = jQuery('body').attr('data-view'); jQuery.post( adLayoutGalleryExtAjax.ajaxurl, { action : 'gallery-lazy-load', attachmentID : loadID, imageSizeDesktop : loadSizeDesktop, imageSizeMobile : loadSizeMobile, viewport : viewportMode, classes : 'gallery-thumbs-image' }, function( response ) { nextSlide.prepend(response).removeAttr('data-lazy-load data-image-id'); nextSlide.imagesLoaded(function() { centerGalleryImages(slider); nextSlide.removeClass('loading'); nextSlide.find('.preloader').remove(); }); } ); } } } }); }); var galleryWithThumbnailsNav = jQuery('.gallery-thumbs-nav'); galleryWithThumbnailsNav.each(function() { // store the slider in a local variable var $window = jQuery(window), flexslider; var currentSlider = jQuery(this); var currentSliderID = jQuery(this).attr('data-slider-id'); currentSlider.flexslider({ animation: 'slide', slideshow: false, controlNav: false, animationLoop: false, itemWidth: 172, itemMargin: 5, asNavFor: '.gallery-thumbs[data-slider-id="'+ currentSliderID +'"]', }); var viewportWidth = $window.width(); if (viewportWidth < 768) { currentSlider.data('flexslider').vars.itemWidth = 100; } else { currentSlider.data('flexslider').vars.itemWidth = 172; } $window.resize(function() { var viewportWidth = $window.width(); if (viewportWidth < 768) { currentSlider.data('flexslider').vars.itemWidth = 100; } else { currentSlider.data('flexslider').vars.itemWidth = 172; } }); }); //center images on swap jQuery('body').on('imagesSwapped.adLayout', function() { centerGalleryImages(); }); }); function centerGalleryImages() { jQuery('.gallery-thumbs').each(function() { var slideImages = jQuery(this).find('img.gallery-thumbs-image'); slideImages.each(function() { var slideImg = jQuery(this); var containerWidth = slideImg.parent().width(); var containerHeight = slideImg.parent().height(); //use attributes so it works on invisible images and fix ajax load var slideImgWidth = slideImg.attr('width'); var slideImgHeight = slideImg.attr('height'); //if image is stretched var slideImgForcedHeight = slideImg.height(); if (slideImgForcedHeight < slideImgHeight) { slideImgHeight = slideImgForcedHeight; var difference = slideImgForcedHeight / slideImg.attr('height'); slideImgWidth = slideImg.attr('width') * difference; } //console.log('imgwidth: '+ slideImgWidth +' imgheight: '+ slideImgHeight +' contwidth: '+ containerWidth +' contheight: '+ containerHeight +' '); //width if (slideImgWidth >= containerWidth) { var imgOffset = -((slideImgWidth - containerWidth)/2); slideImg.css('left', imgOffset); } else { slideImg.css('left', 0); } //height if (slideImgHeight >= containerHeight) { var imgOffset = -((slideImgHeight - containerHeight)/2); slideImg.css('top', imgOffset); } else { slideImg.css('top', 0); } }); }); } /** * Carousels */ jQuery(window).load(function() { //desktop carousels var carousels = jQuery('.carousel-slider-layout'); carousels.each(function() { var carousel = jQuery(this); var carouselID = carousel.attr('data-slider-id'); var itemsPerPage = parseInt(carousel.attr('data-pager')); var carouselControls = carousel.attr('data-controls'); var carouselControlNav = true; var carouselDirectionNav = false; var carouselSlideshow = carousel.attr('data-slideshow'); if (carouselSlideshow !== undefined) { carouselSlideshow = true; } else { carouselSlideshow = false; } switch(carouselControls) { case 'paging': carouselControlNav = true; carouselDirectionNav = false; break; case 'direction': carouselControlNav = false; carouselDirectionNav = true; break; case 'both': carouselControlNav = true; carouselDirectionNav = true; break; case 'none': carouselControlNav = false; carouselDirectionNav = false; break; } if (carousel.parents('.tab-pane').not(':visible').length > 0) { var slideWidth = Math.floor((carousel.closest('.tab-content').width() * 0.8290598291 ) / itemsPerPage); } else { var slideWidth = Math.floor((carousel.closest('.row').width() * 0.8290598291 ) / itemsPerPage); } //init slider carousel.flexslider({ animation: 'slide', animationLoop: false, multipleKeyboard: true, itemWidth: slideWidth, itemMargin: 0, maxItems: itemsPerPage, move: 1, slideshow: carouselSlideshow, controlsContainer: '.controls-'+ carouselID, directionNav: carouselDirectionNav, controlNav: carouselControlNav, start: function(slider) { slider.resize(); //fixes slide width bug var controls = carousel.find('.carousel-controls'); var controlsOffset = controls.outerWidth() / 2; controls.css('margin-left','-'+ controlsOffset +'px').removeClass('loading'); if (carousel.parents('.tab-pane').not(':visible').length > 0) { jQuery('a[data-toggle="tab"]').on('shown.bs.tab', function (e) { var controlsOffset = controls.outerWidth() / 2; controls.css('margin-left','-'+ controlsOffset +'px').removeClass('loading'); }); } } }); }); //mobile carousels var mobileCarousels = jQuery('.carousel-slider-mobile-layout'); mobileCarousels.each(function() { var mobileCarousel = jQuery(this); var carouselControls = mobileCarousel.attr('data-controls'); var carouselControlNav = true; var carouselDirectionNav = false; switch(carouselControls) { case 'paging': carouselControlNav = true; carouselDirectionNav = false; break; case 'direction': carouselControlNav = false; carouselDirectionNav = true; break; case 'both': carouselControlNav = true; carouselDirectionNav = true; break; case 'none': carouselControlNav = false; carouselDirectionNav = false; break; } var slideWidth = Math.floor((mobileCarousel.closest('.row').width() * 0.8290598291 ) / 1); //init slider mobileCarousel.flexslider({ animation: 'slide', animationLoop: false, multipleKeyboard: true, itemWidth: slideWidth, itemMargin: 0, maxItems: 1, move: 1, slideshow: false, directionNav: carouselDirectionNav, controlNav: carouselControlNav, start: function(slider) { slider.resize(); //fixes slide width bug } }); }); }); //videos function sliderPlayVideo(video) { if (!Modernizr.video) { var videoContainer = jQuery('#' + video).closest('.slide'); videoContainer.find('.video-fallback').css('display','block'); videoContainer.find('.masthead-slide-video').remove(); videoContainer.removeClass('video'); return false; } var videoPlayer = document.getElementById(video); videoPlayer.onerror = function() { var videoContainer = jQuery('#' + video).closest('.slide'); videoContainer.find('.video-fallback').css('display','block'); videoContainer.find('.masthead-slide-video').remove(); videoContainer.removeClass('video'); }; centerSliderVideos(); videoPlayer.play(); } function sliderPauseVideo(video) { if (!Modernizr.video) { return false; } var videoPlayer = document.getElementById(video); videoPlayer.currentTime = 0; videoPlayer.pause(); } //video centering jQuery(window).load(function() { centerSliderVideos(); setTimeout(function() { jQuery(window).resize(function() { centerSliderVideos(); }); }, 1000); }); function centerSliderVideos() { jQuery('.flexslider').each(function() { var slideVideos = jQuery(this).find('.video-element'); slideVideos.each(function() { var slideVideo = jQuery(this); var containerWidth = slideVideo.parent().width(); var containerHeight = slideVideo.parent().height(); //use attributes so it works on invisible videos and fix ajax load var slideVideoWidth = slideVideo.attr('width'); var slideVideoHeight = slideVideo.attr('height'); //if video is stretched var slideVideoForcedWidth = containerWidth; if (slideVideoForcedWidth > slideVideoWidth) { slideVideoWidth = slideVideoForcedWidth; var difference = slideVideoForcedWidth / slideVideo.attr('width'); slideVideoHeight = slideVideo.attr('height') * difference; } if (slideVideoHeight < containerHeight) { slideVideoHeight = containerHeight; var difference = slideVideoHeight / slideVideo.attr('height'); slideVideoWidth = slideVideo.attr('width') * difference; } //console.log('videowidth: '+ slideVideoWidth +' videoheight: '+ slideVideoHeight +' contwidth: '+ containerWidth +' contheight: '+ containerHeight +' '); //width if (slideVideoWidth >= containerWidth) { var videoOffset = -((slideVideoWidth - containerWidth)/2); slideVideo.css('left', videoOffset); } else { slideVideo.css('left', 0); } //height if (slideVideoHeight >= containerHeight) { var videoOffset = -((slideVideoHeight - containerHeight)/2); slideVideo.css('top', videoOffset); } else { slideVideo.css('top', 0); } }); }); } //Gallery : Grid jQuery(document).ready(function() { var gridGalleries = jQuery('.ad-layout-grid-gallery .grid'); gridGalleries.each(function() { var gridGallery = jQuery(this); gridGallery.imagesLoaded(function() { gridGallery.isotope({ itemSelector: '.grid-item', layoutMode: 'masonry', percentPosition: true, horizontalOrder: true, transitionDuration: 0 }); }); }); }); jQuery('a[data-toggle="tab"]').on('shown.bs.tab', function (e) { var targetPanel = jQuery(e.target.hash); var targetGallery = targetPanel.find('.ad-layout-grid-gallery .grid'); if (targetGallery.length > 0) { targetGallery.isotope('layout'); } }); //Responsive functions //initialize enquire.js and necessary polyfills jQuery(document).ready(function() { Modernizr.load([ //load matchmedia polyfill if needed { test: Modernizr.matchmedia, nope: adLayoutGalleryExtAjax.pluginurl + "includes/js/media.match.min.js", complete: function() { adLayoutGalleryExtInitEnquireJS(); } } ]); }); function adLayoutGalleryExtInitEnquireJS() { if (typeof enquire != 'function') { /*! * enquire.js v2.1.0 - Awesome Media Queries in JavaScript * Copyright (c) 2013 Nick Williams - http://wicky.nillia.ms/enquire.js * License: MIT (http://www.opensource.org/licenses/mit-license.php) */ (function(t,i,n){var e=i.matchMedia;"undefined"!=typeof module&&module.exports?module.exports=n(e):"function"==typeof define&&define.amd?define(function(){return i[t]=n(e)}):i[t]=n(e)})("enquire",this,function(t){"use strict";function i(t,i){var n,e=0,s=t.length;for(e;s>e&&(n=i(t[e],e),n!==!1);e++);}function n(t){return"[object Array]"===Object.prototype.toString.apply(t)}function e(t){return"function"==typeof t}function s(t){this.options=t,!t.deferSetup&&this.setup()}function o(i,n){this.query=i,this.isUnconditional=n,this.handlers=[],this.mql=t(i);var e=this;this.listener=function(t){e.mql=t,e.assess()},this.mql.addListener(this.listener)}function r(){if(!t)throw Error("matchMedia not present, legacy browsers require a polyfill");this.queries={},this.browserIsIncapable=!t("only all").matches}return s.prototype={setup:function(){this.options.setup&&this.options.setup(),this.initialised=!0},on:function(){!this.initialised&&this.setup(),this.options.match&&this.options.match()},off:function(){this.options.unmatch&&this.options.unmatch()},destroy:function(){this.options.destroy?this.options.destroy():this.off()},equals:function(t){return this.options===t||this.options.match===t}},o.prototype={addHandler:function(t){var i=new s(t);this.handlers.push(i),this.matches()&&i.on()},removeHandler:function(t){var n=this.handlers;i(n,function(i,e){return i.equals(t)?(i.destroy(),!n.splice(e,1)):void 0})},matches:function(){return this.mql.matches||this.isUnconditional},clear:function(){i(this.handlers,function(t){t.destroy()}),this.mql.removeListener(this.listener),this.handlers.length=0},assess:function(){var t=this.matches()?"on":"off";i(this.handlers,function(i){i[t]()})}},r.prototype={register:function(t,s,r){var h=this.queries,u=r&&this.browserIsIncapable;return h[t]||(h[t]=new o(t,u)),e(s)&&(s={match:s}),n(s)||(s=[s]),i(s,function(i){h[t].addHandler(i)}),this},unregister:function(t,i){var n=this.queries[t];return n&&(i?n.removeHandler(i):(n.clear(),delete this.queries[t])),this}},new r}); } //desktop version enquire.register("screen and (min-width: 768px)", { match : function() { //desktop functions go here }, unmatch : function() { //mobile functions go here } }); }