(function($, Drupal){ Drupal.behaviors.heroBehaviours = { attach: function (context, settings) { $('.hero-wrapper').once('heroLoadBehaviour').each(function() { var bgColor = $(this).children('.hero-content').data('bg-color'); $(this).css({'background-color': bgColor}); if ($('#block-hero-content').length) { var bgImage = $(this).children('.hero-content').data('bg-image'); $(this).css({'background-image': 'url(' + bgImage + ')'}); } }); $('.hero-content h2').once('heroHeadBehaviour').each(function() { var headColor = $(this).data('headline-color'); if (headColor) { $(this).css({color:headColor}); } }); $('.hero-content p').once('heroHeadBehaviour').each(function() { var textColor = $(this).data('text-color'); if (textColor) { $(this).css({color:textColor}); } }); $(window).once('owlStopBehaviour').on('load', function() { var owl = $('.owl-carousel'); if ($('.owl-item').length <= 1) { $(owl).trigger('owl.stop'); } else { $(owl).trigger('owl.play',[7500]); } }); $('.cta > a').once('ctaScrollBehaviour').click(function(e) { if ($(window).width() > 991) { var headerCompensation = 150; } else if ($(window).width() > 767) { var headerCompensation = 110; } else { var headerCompensation = 0; } var href = $(this).attr('href'); if (href.indexOf("#") >= 0) { var elementID = href.substr(href.indexOf("#")); if ( $(elementID).length ) { $('html, body').animate({ scrollTop: ($(elementID).offset().top - headerCompensation) }, 1000); e.preventDefault(); } } // if (href.slice(0,1) == '#') { // $('html, body').animate({ // scrollTop: ($(href).offset().top - headerCompensation) // }, 1000); // e.preventDefault(); // } }); // $('#hero .scroll-down').once('heroScrollDownBehaviour').click(function() { // if ($(window).width() > 991) { // var headerCompensation = $(window).width() / 12; // } else { // var headerCompensation = $(window).width() / 10; // } // $('html, body').animate({ // scrollTop: ($('#hero').offset().top + $('#hero').outerHeight(true) - headerCompensation) // }, 1000); // }); $('#block-hero-content .scroll-down, #block-home-hero-content .scroll-down').once('owlScrollDownBehaviour').click(function() { if ($(window).width() > 991) { var headerCompensation = 150; } else { var headerCompensation = 110; } if ($('#block-hero-content').length) { var hero = $('#block-hero-content'); } else { var hero = $('#block-home-hero-content'); } $('html, body').animate({ scrollTop: (hero.offset().top + hero.outerHeight(true) - headerCompensation) }, 1000); }); } } })(jQuery, Drupal);