PageSourceSearch

https://learnersdrive.co.uk/wp-content/plugins/header-footer-build…/js/turbo-header-behavior.js?ver=1.2.6

js learnersdrive.co.uk collected 2026-10-06 11:14:19 UTC 4,279 bytes, 104 lines download raw bytes

1jQuery(function ($) {
2  // Skip behavior inside Elementor preview / our CPT editors
3  if (
4    $('body').is('.tahefobu-header-template-editor, .tahefobu-footer-template-editor') ||
5    window.location.search.indexOf('elementor-preview') !== -1
6  ) return;
7
8  // Prefer the new wrapper if present, else fall back to your existing class
9  var $wrap = $('#tahefobu-header');
10  if (!$wrap.length) {
11    $wrap = $('.turbo-header-template').first();
12    if (!$wrap.length) return;
13  }
14  $wrap.addClass('tahefobu-ready');
15
16  // Read sticky/animation flags from data attributes
17  var sticky = $wrap.data('sticky');
18  var anim   = $wrap.data('animation');
19  // Back-compat if data-* not present: infer from classes
20  sticky = String(sticky === undefined ? $wrap.hasClass('ta-sticky-header') : sticky) === '1';
21  anim   = String(anim   === undefined ? $wrap.hasClass('ta-header-scroll-animation') : anim) === '1';
22
23  // WordPress pushes body down by the admin bar height via margin-top on <body>.
24  // For sticky/animated headers we set top = adminBarH so the header sticks
25  // just below the admin bar — no negative margins needed (those cause content overlap).
26  // For plain static headers the body margin-top already handles the spacing correctly.
27  var adminBarH = $('#wpadminbar').length ? $('#wpadminbar').outerHeight() : 0;
28  $wrap.css('--ta-sticky-top', adminBarH + 'px');
29
30  // ── Animation-only mode ──────────────────────────────────────────────────
31  // Needs position:sticky so transform hide/show works without leaving a gap.
32  // top = adminBarH keeps it flush under the admin bar when sticky.
33  if (anim && !sticky) {
34    $wrap.css({
35      position: 'sticky',
36      top: adminBarH + 'px'
37    });
38  }
39
40  // ── Sticky-only or Sticky+Animation mode ─────────────────────────────────
41  // CSS already sets top: var(--ta-sticky-top) which we set above.
42  // The fixed fallback (ta-sticky-active) also uses that var.
43
44  var $spacer = null, headerTop = 0, headerH = 0;
45
46  function recalc() {
47    headerH   = $wrap.outerHeight();
48    headerTop = ($spacer && $spacer.is(':visible')) ? $spacer.offset().top : $wrap.offset().top;
49  }
50
51  function onScrollSticky() {
52    var sc = window.pageYOffset || document.documentElement.scrollTop;
53
54    if (sc > headerTop) {
55      if (!$wrap.hasClass('ta-sticky-active')) {
56        headerH = $wrap.outerHeight();
57        if (!$spacer) $spacer = $('<div class="ta-header-spacer" />').insertBefore($wrap).hide();
58        $spacer.height(headerH).show();   // prevent layout jump
59        $wrap.addClass('ta-sticky-active');
60      }
61    } else {
62      if ($wrap.hasClass('ta-sticky-active')) {
63        $wrap.removeClass('ta-sticky-active');
64        if ($spacer) $spacer.hide();
65      }
66    }
67  }
68
69  if (sticky) {
70    recalc();
71    $(window).on('scroll.taSticky resize.taSticky', function () {
72      recalc();
73      onScrollSticky();
74    });
75    onScrollSticky();
76  }
77
78  // ── Scroll animation ─────────────────────────────────────────────────────
79  if (anim) {
80    var lastY = window.pageYOffset || document.documentElement.scrollTop;
81    var hideThreshold = 80; // px scrolled down before hiding
82
83    // Start fully visible
84    $wrap.removeClass('ta-scroll-down ta-header-hide ta-header-hidden')
85         .addClass('ta-scroll-up ta-header-show');
86
87    $(window).on('scroll.taAnim', function () {
88      var y    = window.pageYOffset || document.documentElement.scrollTop;
89      var diff = y - lastY;
90
91      if (diff > 0 && y > hideThreshold) {
92        // Scrolling DOWN — hide header
93        $wrap.addClass('ta-scroll-down ta-header-hide ta-header-hidden')
94             .removeClass('ta-scroll-up ta-header-show');
95      } else if (diff < 0) {
96        // Scrolling UP — show header
97        $wrap.addClass('ta-scroll-up ta-header-show')
98             .removeClass('ta-scroll-down ta-header-hide ta-header-hidden');
99      }
100
101      lastY = y;
102    });
103  }
104});

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.