PageSourceSearch

https://www.hologic.es/themes/custom/hologic/global/js/timeline.js?tm4wcr

js hologic.es collected 2026-10-08 20:33:03 UTC 14,395 bytes, 436 lines download raw bytes

1(function ($) {
2  'use strict';
3
4  if ($(".page-node-type-timeline").length) {
5
6    // enableSmoothScrolling();
7    enableOrDisableParallax();
8    scrollToLearnMore();
9    slickTimeline();
10    addBackgroundImage(".slick-timeline .timeline__section");
11    addBackgroundImage(".youtube-wrapper");
12    yearSmoothScroll();
13    scrollToSection();
14    addClassToFirstYearOnLoad();
15    backToTop();
16    showYears();
17    splitYearsInRows();
18    hasBgColor();
19    video();
20    playVideoOnScroll();
21    playYoutubeVideo();
22    pauseYVOnSlideChange();
23    yearID();
24    yearSidebarFixed();
25    hideSidebar();
26    useSameBgImgPerSection();
27  }
28
29  $(window).scroll();
30
31  function enableSmoothScrolling() {
32    var Scrollbar = window.Scrollbar;
33    Scrollbar.init(document.querySelector('.view-timeline-layout'));
34  }
35
36  // - - - Enable parallax effect only on desktop - - -
37  function enableOrDisableParallax() {
38    $(window).on("resize", function() {
39      if ($(window).width() >= 769) {
40        if (navigator.userAgent.indexOf('MSIE') !== -1 || navigator.appVersion.indexOf('Trident/') > 0) {
41          console.log("is IE")
42        } else {
43          if (!$(".view-timeline-layout").hasClass("no-parallax")) {
44            parallax();
45          }
46        }
47      }
48    })
49  }
50
51  // - - - Scroll to the next section when clicking to the scroll to learn more button - - -
52  function scrollToLearnMore() {
53    $(".scroll-indicator").on("click", function () {
54      $("html, body").animate({
55        scrollTop: 170 + ($(".timeline-parallax").height() / 2) // -170 because of the sticky header
56      }, 400);
57      return false;
58    })
59  }
60
61  // - - - Init parallax - - -
62  function parallax() {
63    var selector = ".timeline-parallax";
64    var maxHeight = [];
65
66    $(selector).each(function () {
67      maxHeight.push($(this).height());
68    })
69
70    $(window).on("resize scroll", function (e) {
71
72      if($(window).width() >= 768) {
73
74        // Show or hide the scroll text indicator
75        if ($(window).scrollTop() >= 100) {
76          $(".scroll-indicator").fadeOut(500);
77        } else {
78          $(".scroll-indicator").fadeIn(500);
79        }
80
81        $(selector).each(function (index) {
82
83          if (index == 0) { return; }
84          var offsetY = $(selector).first().offset().top;
85          var scrollY = $(window).scrollTop() - offsetY;
86          var sectionH = $(this).height();
87          var maxTranslateH = sectionH / 2;
88          var transform = $(this).prev(selector).css('transform');
89          var prevTranslate = (transform == "none") ? 0 : parseInt(transform.split(',')[5]);
90
91          var start = (index * sectionH / 2) - sectionH / 4;
92          var end = (index * sectionH / 2);
93          var calc = -(Math.max(Math.min((scrollY - start) / (end - start), 1), 0) * maxTranslateH) + prevTranslate;
94
95          $(this).css("transform", "translateY(" + calc + "px)")
96        });
97
98        // Remove big white space a the bottom of the page because of the parallax
99        var maxTranslateValue = $(selector).last().attr("style");
100        maxTranslateValue = maxTranslateValue.match(/\((.*)\)/).pop(); // Get value between two parenthenses
101        $(".view-timeline-layout").find(".view-content").first().css("margin-bottom", maxTranslateValue);
102
103      } else {
104        $(selector).each(function (index) {
105          $(this).css("transform", "none")
106        })
107      }
108
109    }).trigger("scroll");
110  }
111
112  // - - - Add background iamge according the element - - -
113  function addBackgroundImage(elem) {
114    $(elem).each(function () {
115      if ($(this).data("src") != undefined) {
116        var imgUlr = $(this).data("src");
117        $(this).css("background-image", "url(" + imgUlr + ")")
118      }
119    })
120  }
121
122  // - - - Init Slick - - -
123  function slickTimeline() {
124
125    // if (!$(".view-timeline-layout").hasClass("corporate-hero-video")) {
126      // Slick slider configuration
127      $('.slick-timeline').slick({
128        nextArrow: '<i class="slick-next"></i>',
129        prevArrow: '<i class="slick-prev"></i>',
130        dots: true,
131        autoplay: $(".field--name-field-template").text() === "corporate-hero-slider" ? true : false,
132        autoplaySpeed: 5000,
133        responsive: [
134          {
135            breakpoint: 769,
136            settings: {
137              dots: true,
138              // arrows: false
139            }
140          },
141        ]
142      })
143    // }
144  }
145
146  // - - - Append video html5 tag in timeline__video div because we can add this tag in the drupal custom text from the view
147  function video() {
148    $(".timeline__video").each(function() {
149      var videoSrc = $(this).data("src");
150      if (videoSrc != "") {
151        $(this).append('<video preload="auto" autoplay loop muted playsinline><source src="'+videoSrc+'"></video>');
152        $(this).closest(".slick-timeline").addClass("has-video");
153      } else {
154        $(this).hide();
155      }
156    })
157  }
158
159  // - - - Play video when it's visible on the viewport - - -
160  function playVideoOnScroll() {
161    $(window).on("scroll", function () {
162
163      $(".has-video video").each(function () {
164        if (isInViewport($(this))) {
165          $(this)[0].play();
166        } else {
167          $(this)[0].pause();
168        }
169      })
170    });
171  }
172
173  // - - - Play video when clicking on thumbnail video - - -
174  function playYoutubeVideo() {
175    $(document).find(".youtube-wrapper").click(function () {
176      var $container = $(this);
177      var $iframe = $container.find('iframe');
178      var src = $iframe.attr('src').replace(/&autoplay=\d/, '');
179      src += '&autoplay=1';
180      $iframe.attr('src', src);
181      $container.addClass('youtube-playing');
182    });
183  }
184
185  // - - - Pause video and put back youtube thumbnail when changing slide - - -
186  function pauseYVOnSlideChange() {
187    $('.slick-timeline').on('afterChange', function (event, slick, direction) {
188      if ($(this).find(".youtube-wrapper").hasClass("youtube-playing")) {
189        var $container = $(this).find(".youtube-wrapper");
190        var $iframe = $container.find('iframe');
191        var src = $iframe.attr('src').replace(/&autoplay=\d/, '');
192        src += '&autoplay=0';
193        $iframe.attr('src', src);
194        $container.removeClass('youtube-playing');
195      }
196    });
197  }
198
199  // - - - Add Smooth scroll to the section when clicking to a year - - -
200  function yearSmoothScroll() {
201
202    $(document).on("click", ".year-link[href^='#']", function () {
203
204      $(".year-link").removeClass("active");
205      $("body").removeClass("open");
206      $(this).addClass("active");
207
208      var sectionNumber = $(this).data("id");
209
210      var sectionHeight;
211      if (sectionNumber == 2 || sectionNumber == 3) {
212        sectionHeight = ($(".timeline-parallax").height() / 2) + 2;
213      } else {
214        sectionHeight = ($(".timeline-parallax").height() + 3) / 2;
215      }
216
217      // var sectionHeight = ($(".timeline-parallax").height() + 3) / 2
218      var $page = $(this).attr("href");
219      var timelineTitle = $(".timeline__title-wrapper").length ? $(".timeline__title-wrapper").outerHeight() : 0;
220      console.log(timelineTitle)
221      if ($(window).width() > 768) {
222        $("html, body").animate({
223          scrollTop: sectionNumber == 1 ? $($page).offset().top - $(".navbar").height() : (sectionNumber * sectionHeight) - $(".navbar").height() - 40 + timelineTitle
224        }, 400);
225        return false;
226      } else {
227        $("html, body").animate({
228          scrollTop: $($page).offset().top - $(".navbar").height()
229        }, 400);
230        return false;
231      }
232    })
233  }
234
235  // - - - Add year data id for acnhor scroll calcul - - -
236  function yearID() {
237    var i = 1;
238    $(".year-link").each(function() {
239      $(this).attr("data-id", i);
240      i++;
241    })
242    $(".year-link").last().addClass("last-year")
243  }
244
245  // - - - Add class to the first year - - -
246  function addClassToFirstYearOnLoad() {
247    $(".timeline__sidebar .view-content .year-link").first().addClass("active");
248  }
249
250  // - - - Add class if the slide is with a background color - - -
251  function hasBgColor() {
252    $(".timeline__section").each(function() {
253      if ($(this).is("[class*=bg_color_img]")) {
254        $(this).closest(".slick-timeline").addClass("bg-color");
255      }
256    })
257  }
258
259  // - - - Add class active to year according section in the viewport visible on scroll - - -
260  function scrollToSection() {
261    $("body").trigger("click");
262    var lastScrollTop = 0;
263
264    $(window).on('scroll', function () {
265
266      var viewportTop = $(window).scrollTop();
267      var viewportBottom = viewportTop + $(window).height();
268
269      // Scroll down
270      if (viewportTop > lastScrollTop) {
271        $('.timeline-parallax').each(function () {
272
273          var elementTop = $(this).offset().top;
274          var activeYear = $(this).attr('id');
275
276          if ((elementTop - 400) < viewportTop) {
277            $(".year-link").removeClass("active");
278            $(".year-link").each(function () {
279              if ($(this).text() == activeYear) {
280                $(".active-year").text($(this).text());
281                $(this).addClass("active")
282              }
283            })
284          }
285        });
286
287        // Scroll up
288      } else {
289        $('.timeline-parallax').each(function () {
290
291          var elementTop = $(this).offset().top;
292          var elementBottom = elementTop + $(this).outerHeight();
293          var activeYear = $(this).attr('id');
294
295          if ((elementBottom - 100) < viewportBottom) {
296            $(".year-link").removeClass("active");
297            $(".year-link").each(function () {
298              if ($(this).text() == activeYear) {
299                $(".active-year").text($(this).text());
300                $(this).addClass("active")
301              }
302            })
303          }
304        });
305      }
306
307      lastScrollTop = viewportTop;
308    }).trigger("scroll");
309  }
310
311  // - - - Scroll to top when clicking to back to top btn - - -
312  function backToTop() {
313    $(".js-back-to-top").on("click", function () {
314      $("html, body").animate({
315        scrollTop: $("body").offset().top - $(".navbar").height()
316      }, 400);
317
318      if ($(this).hasClass("top-header-btn")) {
319        // $(".timeline__sidebar").removeClass("open");
320        $(".view-timeline-layout .attachment").removeClass("open");
321        $("body").removeClass("open");
322      }
323
324      return false;
325    })
326  }
327
328  // - - - Display years panel on mobile when clicking on Year label - - -
329  function showYears() {
330    $(".timeline__sidebar").on("click", function() {
331      $(this).closest(".attachment").toggleClass("open");
332
333      // Prevent scrolling when years sidebar is open (only when the sidebar has position set to absolue)
334      $("body").toggleClass("open");
335    })
336  }
337
338  // - - - Split years in three rows and having them one below the other - - -
339  function splitYearsInRows() {
340    var $years = $(".timeline--sidebar .views-field");
341    for (var i = 0; i < $years.length; i += 7) {
342      $years.slice(i, i + 7).wrapAll("<div class='year-column'></div>");
343    }
344  }
345
346  // - - - Function to check if an element is visible on the viewport - - -
347  function isInViewport(elem) {
348    var elementTop = elem.offset().top;
349    var elementBottom = elementTop + elem.outerHeight();
350    var viewportTop = $(window).scrollTop();
351    var viewportBottom = viewportTop + $(window).height();
352    return elementBottom > viewportTop && elementTop < viewportBottom;
353  };
354
355  // - - - Set sidebar position to absolute when arriving to the footer - - -
356  function yearSidebarFixed() {
357
358    $(".timeline-parallax").last().addClass("last");
359
360    $(window).on("resize scroll", function() {
361
362      if (window.innerWidth <= 768) {
363        $(".timeline__sidebar").removeClass("fixed");
364        var $timelineLayout = $(".view-timeline-layout");
365        var layoutTimeline = $timelineLayout.offset().top;
366        var layoutTimelineBottom = layoutTimeline + $timelineLayout.outerHeight() - $(".timeline__sidebar").height();
367        var bottomViewport = $(window).scrollTop() + $(window).height()
368
369        if (bottomViewport >= layoutTimelineBottom) {
370          $(".view-timeline-layout .attachment").addClass("not-fixed")
371        } else {
372          $(".view-timeline-layout .attachment").removeClass("not-fixed")
373        }
374      } else {
375
376        // Fix years sidebar to the top of the timeline layout
377        if ($(window).scrollTop() >= 38) {
378          $(".timeline__sidebar").addClass("fixed");
379        } else {
380          $(".timeline__sidebar").removeClass("fixed");
381        }
382
383        // Fix years sidebar to the bottom of the timeline layout when the sidebar touch the footer
384        var $sidebar = $(".timeline__sidebar");
385        var sidebarTop = $sidebar.offset().top;
386        var sidebarBottom = sidebarTop + $sidebar.outerHeight();
387
388        var $timelineContent = $(".view-timeline-layout .view-content");
389        var timelineContentTop = $timelineContent.offset().top;
390        var timelineContentBottom = timelineContentTop + $timelineContent.outerHeight();
391
392        var maxTranslateValue = $timelineContent.attr("style");
393
394        if (maxTranslateValue != undefined) {
395          maxTranslateValue = maxTranslateValue.split(" ")[1];
396
397          if (maxTranslateValue.match(/\-(.*)\p/) != null) {
398            maxTranslateValue = maxTranslateValue.match(/\-(.*)\p/).pop(); // Get value between a dash and the p letter
399
400            var calc = sidebarBottom + parseInt(maxTranslateValue);
401            if (calc >= timelineContentBottom) {
402              $sidebar.addClass("stop");
403            }
404
405            if ($(window).scrollTop() <= ($sidebar.offset().top - $(".navbar").height())) {
406              $sidebar.removeClass("stop");
407            }
408          }
409        }
410      }
411    }).trigger("scroll");
412  }
413
414  function hideSidebar() {
415    if ($(".field--name-field-hide-timeline-sidebar").length) {
416      if ($(".field--name-field-hide-timeline-sidebar").text() === "1") {
417        $(".view-timeline-layout").find(".attachment").addClass("hide");
418      }
419    }
420  }
421
422  function useSameBgImgPerSection() {
423    $(".timeline-parallax").each(function() {
424      if ($(this).find(".js-texts-slider").length) {
425
426        var $firstSlide = $(this).find(".slick-slide:not('.slick-cloned')").first().find(".js-texts-slider");
427
428        if ($firstSlide.data("src") != undefined) {
429          var bgImgUrl = $firstSlide.data("src");
430          $(this).find(".slick-timeline").addClass("-texts-slider").css("background-image", "url(" + bgImgUrl + ")")
431        }
432      }
433    })
434  }
435
436})(jQuery);

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.