(function ($) { Drupal.behaviors.tuiReactiveMedia = { attach: function (context, settings) { if (typeof Modernizr != 'undefined' && typeof settings.pathToThemeJS == 'string') { Modernizr.load([ { load: [ settings.pathToThemeJS + 'jquery.cycle2.min.js', settings.pathToThemeJS + 'jquery.cycle2.video.min.js' ], complete: function() { if ($.isFunction($.fn.cycle)) { /***** VideoJS *****/ if(typeof videojs != 'undefined') { videojs.options.flash.swf = "/sites/all/libraries/video-js/video-js.swf"; // Force videojs initialization videojs.autoSetup(); } /***** Media Gallery *****/ function expandMediaGallery(gallery) { gallery.addClass('expand'); gallery._animateAuto("height", 750, function() { $(this).addClass('reveal').removeClass('expand'); $(this).parent().addClass('reveal'); $(this).parents('.field--name-field-pv-media-galleries').addClass('media-gallery-active'); $(this).css("height","auto"); }); var openLink = gallery.siblings('.media-gallery-open-link'); openLink.fadeOut(250).delay(750).fadeIn(250); openLink.find('.media-gallery-open').hide(); openLink.find('.media-gallery-close').show(); // Set open link position var slides = gallery.find('.media-gallery-slideshow-slide'); if(slides.length) { var image = slides.first().find('.media-gallery-image img'); if(image.length) { imgHeight = image[0].height; var galleryOpenLink = gallery.parent('.media-gallery-wrapper').find('.media-gallery-open-link'); setTimeout( function(){ galleryOpenLink.css({ 'top': imgHeight + "px" }); },500); } } // Show video play button var video = gallery.find('.video-js'); if(video.length) { video.find('.vjs-big-play-button').fadeIn(250); } } function collapseMediaGallery(gallery) { gallery.addClass('collapse'); gallery.removeClass('reveal'); gallery.parent().removeClass('reveal'); $(this).parents('.field--name-field-pv-media-galleries').removeClass('media-gallery-active'); gallery._animateInitial("height", 750, function() { gallery.removeClass('collapse'); }); var openLink = gallery.siblings('.media-gallery-open-link'); openLink.fadeOut(250).delay(750).fadeIn(250); openLink.find('.media-gallery-open').show(); openLink.find('.media-gallery-close').hide(); // Set open link position var slides = gallery.find('.media-gallery-slideshow-slide'); if(slides.length) { var image = slides.first().find('.media-gallery-image img'); if(image.length) { imgHeight = image[0].height; var galleryOpenLink = gallery.parent('.media-gallery-wrapper').find('.media-gallery-open-link'); setTimeout( function(){ galleryOpenLink.css({ 'top': "auto" }); },500); } } // Hide video play button var video = gallery.find('.video-js'); if(video.length) { video.find('.vjs-big-play-button').fadeOut(250); } } var mediaGallery = $('.media-gallery'); // Bind expand functionality to media gallery mediaGallery.each(function() { var gallery = $(this); gallery.bind('click', function(e) { galleryItem = $(this); if(!galleryItem.hasClass('reveal')) { expandMediaGallery(galleryItem); } }); }); // Bind expand and collapse functionality to media gallery button $('.media-gallery-open-link').each(function() { var openLink = $(this); openLink.bind('click', function(e) { gallery = $(this).parents('.media-gallery-wrapper').find('.media-gallery'); if(gallery.hasClass('reveal')) { // Pause video var video = gallery.find('.video-js'); if(video.length) { videojs(video.attr('id')).pause(); video.find('.vjs-poster').delay(250).fadeIn(250); } collapseMediaGallery(gallery); } else { expandMediaGallery(gallery); } }); }); mediaGallery.find('.video-js').each(function() { var video = $(this); var videoId = video.attr('id'); videojs(videoId).ready(function() { var myPlayer = this; // Disable click anywhere on video to play myPlayer.posterImage.off('click'); video.find('.vjs-big-play-button').hide(); }); }); function galleryControlHeight() { mediaGallery.each(function() { // Auto height on next & previous based on image height var gallery = $(this); var slides = gallery.find('.media-gallery-slideshow-slide'); if(slides.length) { var image = slides.first().find('.media-gallery-image img'); if(image.length) { imgHeight = image[0].height; var galleryOpenLink = gallery.parent('.media-gallery-wrapper').find('.media-gallery-open-link'); if (gallery.hasClass('reveal')) { galleryOpenLink.css({ 'top': imgHeight + "px" }); } else { galleryOpenLink.css({ 'top': "auto" }); } gallery.find('.previous-slide').css({ 'height': imgHeight + "px" }); gallery.find('.next-slide').css({ 'height': imgHeight + "px" }); } } }); } function _curSlideHeight(optionHash) { var i = optionHash.currSlide; slideHeight = $(optionHash.slides[i]).height(); galleryContainer = $(optionHash.slides[i]).closest('.media-gallery'); galleryContainer.animate({'height': slideHeight + "px"}, 500); } $(document).find('.media-gallery-slideshow').live('cycle-post-initialize', function() { galleryControlHeight(); window.onresize = galleryControlHeight; }); $(document).find('.media-gallery-slideshow').live('cycle-next', function(event, optionHash) { _curSlideHeight(optionHash); }); $(document).find('.media-gallery-slideshow').live('cycle-prev', function(event, optionHash) { _curSlideHeight(optionHash); }); // Create media gallery slideshow var cycleGallery = $('.media-gallery-slideshow').cycle({ 'slides': '> .media-gallery-slideshow-slide', 'timeout': 2000, 'paused': true, 'prev': '> .controls .previous-slide', 'next': '> .controls .next-slide', 'allowWrap': true }); /***** Media Slider *****/ // Create media slider slideshow var cycleSlider = $('.media-slider-slideshow').cycle({ 'slides': '> .media-slider-slideshow-slide', 'timeout': 60000, 'allowWrap': true, 'pager': '> .media-slider-pager', 'fx': 'scrollHorz', 'autoHeight': 'calc', 'youtube': true, 'pause-on-hover': true }); cycleSlider.find('.video-js').each(function() { var video = $(this); var videoId = video.attr('id'); videojs(videoId).ready(function() { var myPlayer = this; // Disable click anywhere on video to play myPlayer.posterImage.off('click'); // On the play event myPlayer.on("play", function() { // Pause the slider $(this.a).parents('.media-slider-slideshow').cycle('pause'); $(this.a).find('.vjs-poster').show().fadeOut(500); // Add video-active class that controls slider height with css $(this.a).parents('.media-slider').addClass('video-active'); // Fade out trip builder, slide details, slider pager $(this.a).parents('.l-region').find('.block--tui-gc-trip-builder') .fadeOut(250); $(this.a).parents('.media-gallery-item').find('.media-gallery-item-details') .fadeOut(250); $(this.a).parents('.media-slider-slideshow').find('.media-slider-pager') .fadeOut(250); }); // On the pause event myPlayer.on("pause", function() { $(this.a).find('.vjs-poster').fadeIn(250); setTimeout(function(){ $('.media-slider').removeClass('video-active'); },500); $(this.a).parents('.l-region').find('.block--tui-gc-trip-builder') .delay(500).fadeIn(250); $(this.a).parents('.media-slider-slideshow').find('.media-slider-pager') .delay(500).fadeIn(250); $(this.a).parent().find('.vjs-big-play-button') .hide().delay(750).fadeIn(250); $(this.a).parents('.media-gallery-item').find('.media-gallery-item-details') .delay(750).fadeIn(250); }); }); }); // When the slider pager is clicked cycleSlider.find('.media-slider-pager').on('click', function() { // Pause all videos cycleSlider.find('.video-js').each(function() { var videoId = $(this).attr('id'); videojs(videoId).pause(); $(this).find('.vjs-poster').fadeIn(250); $(this).find('.vjs-big-play-button').fadeIn(250); }); cycleSlider.parents('.media-slider').removeClass('video-active'); // Resume the slider cycle cycleSlider.cycle('resume'); }); /***** Media Collection *****/ // Create media collection slideshow var cycleCollection = $('.media-collection-slideshow').cycle({ 'slides': '> .media-collection-slideshow-slide', 'timeout': 4000, 'paused': true, 'prev': '> .controls .previous-slide', 'next': '> .controls .next-slide', 'allowWrap': true, 'pager': '+ .media-collection-pager', 'pagerTemplate': '', 'fx': 'scrollHorz', 'autoHeight': 'calc' }); } else { console.log('cycle function does not exist!'); } } } ]); } } }; jQuery.fn._animateAuto = function(prop, speed, callback) { var elem, height, width; return this.each(function(i, el) { var el = jQuery(el); elem = el.clone().css({"height":"auto","width":"auto"}).appendTo("body"); height = elem.css("height"); width = elem.css("width"); elem.remove(); if(prop === "height") el.animate({"height":height}, speed, callback); else if(prop === "width") el.animate({"width":width}, speed, callback); else if(prop === "both") el.animate({"width":width,"height":height}, speed, callback); }); }; jQuery.fn._animateInitial = function(prop, speed, callback) { var elem, height, width; return this.each(function(i, el) { var el = jQuery(el); elem = el.clone().removeAttr("style").appendTo("body"); height = elem.css("height"); width = elem.css("width"); elem.remove(); if(prop === "height") el.animate({"height":height}, speed, callback); else if(prop === "width") el.animate({"width":width}, speed, callback); else if(prop === "both") el.animate({"width":width,"height":height}, speed, callback); }); }; })(jQuery); ; (function($) { Drupal.behaviors.tuiGCTripBuilder = { attach: function (context, settings) { var selectClone = $('select#edit-destination-select',context).html(); $('select#edit-trip-type-select').change(function() { $('select#edit-destination-select option').remove(); $(selectClone).appendTo('select#edit-destination-select'); var optionSelected = $("option:selected", this); var valueSelected = this.value; $('select#edit-destination-select option').each(function() { var value = $(this).val(); if(value != 0 && value != 'idk') { var exploded = value.split('_'); var tid_dest = exploded[0]; if(tid_dest != valueSelected) { $(this).remove(); } } }); $('select#edit-destination-select').change(); if(valueSelected == 0) { $('select#edit-destination-select').hide(); $('form#tui-gc-trip-builder-trip-builder-form .submit-btn').hide(); } else if(valueSelected == 'idk') { $('select#edit-destination-select').hide(); $('form#tui-gc-trip-builder-trip-builder-form .submit-btn').show(); } else { $('select#edit-destination-select').show(); } }); $('select#edit-destination-select').change(function() { var optionSelected = $("option:selected", this); var valueSelected = optionSelected.val(); var isDest = Drupal.settings.tui_gc_trip_builder.is_destination; if(isDest) { if(valueSelected != 0 && valueSelected != 'idk') { var exploded = valueSelected.split('_'); var dest_nid = exploded[1]; var nid = Drupal.settings.tui_gc_trip_builder.nid; var submitText = (nid == dest_nid) ? "Start a Trip" : "Go"; } else { var submitText = "Go"; } $('form#tui-gc-trip-builder-trip-builder-form input#edit-trip-builder-submit').val(submitText); } if(valueSelected == 0) { $('form#tui-gc-trip-builder-trip-builder-form .submit-btn').hide(); } else { $('form#tui-gc-trip-builder-trip-builder-form .submit-btn').show(); } }); $('select#edit-trip-type-select').change(); } } })(jQuery); ;