/** * @file * Placeholder file for custom sub-theme behaviors. * */ (function ($, Drupal) { /** * Set the hero size on load and resize. */ function setTitleBlockHeight() { if (window.innerWidth > 639) { var heroHeight = Math.round($('.hero-wrapper').outerHeight() - 40); // The ranging here prevents excessive padding if (heroHeight > 660 && window.innerWidth < 1024) { heroHeight = 660; } $('.nav-header').css('padding-bottom', heroHeight + 'px'); } else { $('.nav-header').css('padding-bottom', '10px'); } } /** * Use this behavior as a template for custom Javascript. */ Drupal.behaviors.titleBlock = { attach: function (context, settings) { setTitleBlockHeight(); $( window ).resize(function() { setTitleBlockHeight(); }); } }; Drupal.behaviors.stickySchedule = { attach: function (context, settings) { var stickyHeaders = (function() { var $window = $(window), $stickies; var load = function(stickies) { if (typeof stickies === "object" && stickies instanceof jQuery && stickies.length > 0) { $stickies = stickies.each(function() { var date = $(this).parents('.component-schedule-day').find('.component-schedule-day__title').html(); var time = $(this).html(); $(this).html(date + ' - ' + time); var $thisSticky = $(this).wrap('
'); $thisSticky .data('originalPosition', $thisSticky.offset().top) .data('originalHeight', $thisSticky.outerHeight()) .parent() .height($thisSticky.outerHeight()); }); $window.off("scroll.stickies").on("scroll.stickies", function() { _whenScrolling(); }); } }; var _whenScrolling = function() { $stickies.each(function(i) { var $thisSticky = $(this), $stickyPosition = $thisSticky.data('originalPosition'); if ($stickyPosition <= $window.scrollTop()) { var $nextSticky = $stickies.eq(i + 1), $nextStickyPosition = $nextSticky.data('originalPosition') - $thisSticky.data('originalHeight'); $thisSticky.addClass("fixed"); if ($nextSticky.length > 0 && $thisSticky.offset().top >= $nextStickyPosition) { $thisSticky.addClass("absolute").css("top", $nextStickyPosition); } } else { var $prevSticky = $stickies.eq(i - 1); $thisSticky.removeClass("fixed"); if ($prevSticky.length > 0 && $window.scrollTop() <= $thisSticky.data('originalPosition') - $thisSticky.data('originalHeight')) { $prevSticky.removeClass("absolute").removeAttr("style"); } } }); }; return { load: load }; })(); $(window).resize(function() { if ($(window).width() <= 640 && !$('body').hasClass('scroll-stickies')) { $('body').addClass('scroll-stickies'); stickyHeaders.load($(".component-schedule-time__title")); $(window).on('scroll.stickies'); } else if ($(window).width() >= 640 && $('body').hasClass('scroll-stickies')) { $(window).off('scroll.stickies'); } }); $(window).trigger('resize'); } }; })(jQuery, Drupal);