1/** 2 * @file 3 * Contains JavaScript making the eleements stick. 4 */ 5 6(function ($, Drupal, drupalSettings) { 7 'use strict'; 8 9 /** 10 * Attach the stickiness to the element in selector. 11 * 12 * @type {Drupal~behavior} 13 * 14 * @prop {Drupal~behaviorAttach} attach 15 * Make the element in selector sticky. 16 */ 17 Drupal.behaviors.stickynav = { 18 breakpoint: 0, 19 compensation: 0, 20 originalPadding: 0, 21 attach: function (context) { 22 var selector = drupalSettings.stickynav.selector; 23 // Only getting the first elmenet in the dom. 24 var $menu = $(selector).once('stickynav').eq(0); 25 var offset = 0; 26 if ($menu.length) { 27 // Save original padding on top. 0 timeout to get correct padding. 28 setTimeout(function () { 29 Drupal.behaviors.stickynav.originalPadding = $('body').css('paddingTop'); 30 }, 100); 31 offset += parseInt(drupalSettings.stickynav.offsets.custom_offset); 32 offset = offset || 0; 33 $(drupalSettings.stickynav.offsets.selector).each(function () { 34 offset += $(this).outerHeight(); 35 }); 36 Drupal.behaviors.stickynav.breakpoint = $menu.offset().top - offset; 37 // We need to compensate the element so that the content does not jump up. 38 Drupal.behaviors.stickynav.compensation = $menu.outerHeight(); 39 $(window).scroll(function () { 40 if ($(window).scrollTop() > Drupal.behaviors.stickynav.breakpoint) { 41 $menu.addClass('stickynav-active'); 42 if (offset) { 43 $menu.css({top: offset + 'px'}); 44 } 45 $('body').css('padding-top', Drupal.behaviors.stickynav.compensation); 46 } 47 else { 48 $menu.removeClass('stickynav-active'); 49 $menu.css({top: ''}); 50 $('body').css('padding-top', Drupal.behaviors.stickynav.originalPadding); 51 } 52 }); 53 } 54 } 55 }; 56})(jQuery, Drupal, drupalSettings);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.