PageSourceSearch

https://www.tourismpei.com/themes/custom/tpei/assets/js/scripts.js?v=10.5.1

js tourismpei.com collected 2026-10-02 04:23:38 UTC 21,741 bytes, 646 lines download raw bytes

1(function ($, Drupal, debounce, once) {
2  'use strict';
3
4  // Site Alert
5  Drupal.behaviors.siteAlert = {
6    attach: function (context, settings) {
7      if (document.querySelector('.c-site-alerts')) {
8        document.body.classList.add("site-alert-enabled");
9      }
10    }
11  };
12
13  // Site Alert Close
14  Drupal.behaviors.siteAlertClose = {
15    attach: function (context, settings) {
16      var siteAlertClose = debounce(function() {
17        if ($('.site-alert-enabled').length || $('.site-alert-enabled').length !== 0) {
18          var siteAlertHeight = $('.c-site-alerts').height();
19          if (siteAlertHeight === 0) {
20            if ($(window).width() <= 1024) {
21              if (document.body.classList.contains('no-hero')) {
22                $('#main-nav').css('top', '0');
23                $('.branding').css('top', '0');
24              }
25            }
26          } else {
27            siteAlertClose();
28          }
29        }
30      }, 50);
31      var siteAlertCloseClick = debounce(function () {
32        var siteAlertCloseBtn = context.querySelector('.c-site-alert .c-site-alert__close');
33        if (siteAlertCloseBtn) {
34          siteAlertCloseBtn.addEventListener('click', siteAlertClose);
35        }
36      }, 50);
37      window.addEventListener('load', siteAlertCloseClick);
38    }
39  };
40
41  Drupal.behaviors.consolidateSiteAlerts = {
42    attach: function(context, settings){
43      $(document).ready(function() {
44        if($('.site-alerts').length > 1) {
45          var mainAlertBar = $('.site-alerts')[0];
46          $('.site-alerts').each(function(i) {
47            if(i !== 0) { // Skip the first slider bar since we want to populate this one
48              $(mainAlertBar).find('.slick-track').append($(this).find('.slick-track .slick-slide:not(.slick-cloned)')); // Move the non-cloned slides to the main slider
49              $(mainAlertBar).find('.alerts-slider').slick('slickAdd', $(this).find('.slick-track .slick-slide:not(.slick-cloned)')); // Add the newly positioned slides to Slick
50              $(this).remove(); // Remove extra slider bars
51            }
52          })
53        }
54
55        $('.c-site-alert__close').on('click', function() {
56          $('.site-alerts').slideUp('fast', function() {
57            // Animation complete
58          })
59        });
60      })
61    }
62  };
63
64  // Sticky Header
65  Drupal.behaviors.stickyHeader = {
66    attach: function (context, settings) {
67      window.onscroll = function() {stickyHeader()};
68      var header = document.getElementById("main-nav");
69      var branding = document.getElementsByClassName("branding");
70      var sticky = header.offsetTop + 62;
71
72      function stickyHeader() {
73        var siteAlertHeight = 0;
74        var brandingTop = 0;
75
76        if (window.pageYOffset > sticky) {
77          header.classList.add("sticky");
78          branding[0].classList.add("sticky");
79          document.body.classList.add("sticky");
80
81          if ($(window).width() >= 1920) {
82            var headerOffset = $('header').offset();
83            $('#main-nav').css('right', headerOffset.left + 'px');
84            $('.branding').css('left', headerOffset.left + 'px');
85          }
86
87          // Responsive
88          var viewportChangeSticky = debounce(function() {
89            if ($(window).width() >= 1920) {
90              var headerOffset = $('header').offset();
91              $('#main-nav.sticky').css('right', headerOffset.left + 'px');
92              $('.branding.sticky').css('left', headerOffset.left + 'px');
93            } else {
94              $('#main-nav.sticky').css('right', '0');
95              $('.branding.sticky').css('left', '0');
96            }
97          }, 250);
98
99          window.addEventListener('resize', viewportChangeSticky);
100
101          if ($('.site-alert-enabled').length || $('.site-alert-enabled').length !== 0) {
102            siteAlertHeight = $('.c-site-alerts').height();
103            brandingTop = siteAlertHeight - window.pageYOffset;
104            if (brandingTop < 0) { brandingTop = 0; }
105
106            // Mobile
107            if ($(window).width() <= 1024) {
108              if ($('.nav-toggle').attr('aria-expanded') === 'true') {
109                $('.branding').css('top', '0');
110                $('#main-nav').css('top', '0');
111              } else {
112                $('#main-nav').css('position', '');
113                $('.branding').css('position', '');
114                if (document.body.classList.contains('no-hero')) {
115                  $('.branding').css('top', brandingTop + 'px');
116                  $('#main-nav').css('top', brandingTop + 'px');
117                }
118              }
119            }
120          }
121        } else {
122          if ($('.site-alert-enabled').length || $('.site-alert-enabled').length !== 0) {
123            siteAlertHeight = $('.c-site-alerts').height();
124            brandingTop = siteAlertHeight - window.pageYOffset;
125            if (brandingTop < 0) { brandingTop = 0; }
126
127            if ($(window).width() <= 1024) {
128              if ($('.nav-toggle').attr('aria-expanded') === 'true') {
129                $('.branding').css('top', '0');
130                $('#main-nav').css('top', '0');
131              } else {
132                $('#main-nav').css('position', '');
133                $('.branding').css('position', '');
134                if (document.body.classList.contains('no-hero')) {
135                  $('.branding').css('top', brandingTop + 'px');
136                  $('#main-nav').css('top', brandingTop + 'px');
137                }
138              }
139            }
140          }
141
142          // When there is no hero, we need the sticky nav
143          if (document.body.classList.contains('no-hero') && $(window).width() <= 1024) {
144            return false;
145          }
146
147          header.classList.remove("sticky");
148          branding[0].classList.remove("sticky");
149          document.body.classList.remove("sticky");
150          $('#main-nav').css('right', '0');
151          $('.branding').css('left', '0');
152        }
153      }
154    }
155  };
156
157  // Misc Header
158  Drupal.behaviors.miscHeader = {
159    attach: function (context, settings) {
160      // Add body class from hero
161      if ($('.hero.plain').length || $('.hero').length === 0) {
162        $('body').addClass('no-hero');
163
164        // When there is no hero, we need the sticky nav
165        if ($(window).width() <= 1024) {
166          var header = document.getElementById("main-nav");
167          var branding = document.getElementsByClassName("branding");
168          header.classList.add("sticky");
169          branding[0].classList.add("sticky");
170          document.body.classList.add("sticky");
171
172          if ($('.site-alert-enabled').length || $('.site-alert-enabled').length !== 0) {
173            var siteAlertHeight = $('.c-site-alerts').height();
174            if (window.pageYOffset > siteAlertHeight) { siteAlertHeight = 0; }
175            $('.branding').css('top', siteAlertHeight + 'px');
176            $('#main-nav').css('top', siteAlertHeight + 'px');
177            $('#main-nav').css('position', 'absolute');
178            $('.branding').css('position', 'absolute');
179          }
180        }
181      }
182      // Search toggle
183      $(once('search-toggle', '.search .toggle', context)).on('click', function() {
184        $(this).toggleClass('active');
185        $(this).next().toggleClass('open');
186      });
187
188      // Responsive
189      var viewportChange = debounce(function() {
190        if ($(window).width() <= 1024) {
191        } else {
192          // Mega menu
193          $('header .multi-level .mega-menu > ul > li.dropdown:first-child > a').addClass('active');
194          $('header .multi-level .mega-menu > ul > li.dropdown:first-child > ul').addClass('visible');
195          $(once('mega-menu-open', 'header .multi-level .mega-menu > ul > li.dropdown > a', context)).on('click', function(e) {
196            e.preventDefault();
197            $('header .multi-level .mega-menu > ul > li.dropdown > a').removeClass('active');
198            $(this).addClass('active');
199            $('header .multi-level .mega-menu > ul > li.dropdown > ul').removeClass('visible');
200            $(this).next().addClass('visible');
201          });
202        }
203      }, 250);
204      window.addEventListener('resize', viewportChange);
205      window.addEventListener('load', viewportChange);
206    }
207  };
208
209  // Mobile Menu
210  Drupal.behaviors.mobileMenu = {
211    attach: function (context, settings) {
212      if (!context.querySelector('header .nav-toggle')) {
213        return false;
214      }
215
216      $('header .nav-toggle').on('click', function() {
217        var $this = $(this);
218        if ($this.attr('aria-expanded') === 'true') {
219          $(this).attr('aria-expanded', 'false');
220          if (!document.body.classList.contains('no-hero')) {
221            $('#main-nav').css('position', '');
222            $('.branding').css('position', '');
223          } else {
224            var siteAlertHeight = $('.c-site-alerts').height();
225            var brandingTop = siteAlertHeight - window.pageYOffset;
226            if (brandingTop < 0) { brandingTop = 0; }
227            $('#main-nav').css('top', brandingTop + 'px');
228            $('.branding').css('top', brandingTop + 'px');
229          }
230        } else {
231          $(this).attr('aria-expanded', 'true');
232
233          if ($(window).width() <= 1024) {
234            $('#main-nav').css('top', '0');
235            $('.branding').css('top', '0');
236            if ($('.site-alert-enabled').length || $('.site-alert-enabled').length !== 0) {
237              $('#main-nav').css('position', 'fixed');
238              $('.branding').css('position', 'fixed');
239            }
240
241            var scrollNav = document.querySelector('#main-nav nav');
242            scrollNav.addEventListener("scroll", function () {
243              var brandingHeight = $('.branding').height() - 40;
244              if (this.scrollTop > brandingHeight) {
245                var top = '-' + (this.scrollTop - brandingHeight) + 'px';
246                $('#main-nav').css('top', top);
247                $('.branding').css('top', top);
248              } else {
249                $('#main-nav').css('top', '0');
250                $('.branding').css('top', '0');
251              }
252            });
253          }
254        }
255
256        $('header .navigation nav').toggleClass('open');
257        $('body').toggleClass('mobile-nav-open');
258
259        return false;
260      });
261      // Close drawer
262      $(once('close-drawer', 'header nav .close', context)).on('click', function() {
263        $(this).parent().prev()[0].click();
264      });
265    }
266  };
267
268  // Tables
269  Drupal.behaviors.tables = {
270    attach: function (context, settings) {
271      // Wrap table.
272      $('.body table').each(function() {
273        $(once('table-responsive', this, context)).wrap('<div class="table-responsive">');
274      });
275    }
276  };
277
278  // Anchors
279  Drupal.behaviors.anchors = {
280    attach: function (context, settings) {
281      // On load, go to anchor if applicable
282      var anchor = window.location.hash.substr(1);
283      if (anchor) {
284        var anchorLoad = $("a[href$='#" + anchor + "']");
285        $(document).ready(function() {
286          anchorMove(anchorLoad);
287        });
288      }
289      // On click, go to anchor
290      var anchors = $('.js-anchor');
291      if (anchors.length) {
292        anchors.each(function() {
293          $(this).on('click', function (e) {
294            e.preventDefault();
295            anchorMove($(this));
296          });
297        });
298      }
299    }
300  };
301
302  function anchorMove(el) {
303    // If header is sticky:
304    var headerHeight = $('header').height();
305    var anchorElement = $(el.attr('href'));
306    if (anchorElement.length !== 0){
307      $('html, body').animate({
308        scrollTop: anchorElement.offset().top - headerHeight
309      }, 200);
310    }
311  }
312
313  // Newsletter Popup
314  Drupal.behaviors.newsletterPopupSignup = {
315    attach: function (context, settings) {
316      if (!context.querySelector('#newsletter-signup-form')) {
317        return false;
318      }
319
320      var form = context.querySelector('#newsletter-signup-form');
321      var forms = context.querySelectorAll('#newsletter-signup-form, .newsletter form:not(#mc-embedded-subscribe-form)');
322      var overlay = context.querySelector('.newsletter-popup__overlay');
323      var close = context.querySelector('#close');
324      var subscribeBtn = context.querySelector('#subscribe-btn');
325
326      if (subscribeBtn !== null) {
327        subscribeBtn.addEventListener('click', function(){
328          overlay.style.display = 'block';
329        });
330      }
331
332      if (close !== null) {
333        close.addEventListener('click', function () {
334          overlay.style.display = 'none';
335        });
336      }
337
338      if (overlay !== null) {
339        overlay.addEventListener('click', function (e) {
340          if (e.target.className === 'newsletter-popup__overlay') {
341            this.style.display = 'none';
342          }
343        });
344      }
345
346      forms.forEach(item => {
347        item.addEventListener('submit', e => {
348          e.preventDefault();
349
350          var email = item.querySelector('.js-newsletter-signup-email');
351          var emailAddress = email.value;
352          if (emailAddress) {
353            if (typeof(Storage) !== "undefined") {
354              sessionStorage.setItem("tpei.newsletterSignupEmail", emailAddress);
355            }
356          }
357          form.submit();
358        });
359      });
360    }
361  };
362
363  Drupal.behaviors.newsletterPopupSignupWebform = {
364    attach: function (context, settings) {
365      if (!context.querySelector('form input.formEmail')) {
366        return false;
367      }
368
369      //Get email value from localStorage
370      var dynamicEmail = context.querySelector('form input.formEmail');
371      var storedEmail = sessionStorage.getItem('tpei.newsletterSignupEmail');
372
373      if (dynamicEmail && storedEmail) {
374        dynamicEmail.value = storedEmail;
375      }
376    }
377  };
378
379  // Checking for ad blocker
380  Drupal.behaviors.adCheck = {
381    attach: function (context, settings) {
382      if( window.canRunAds === undefined ){
383        $('.advertisements').hide();
384      }
385    }
386  };
387
388  Drupal.behaviors.activeMenuItem = {
389    attach: function (context, settings) {
390      var lang = $('html').attr('lang');
391      var currentItem = '';
392      var current = location.pathname;
393
394      // Skip if were on the homepage of any lang
395      var homePaths = [
396        '/fr',
397        '/de',
398        '/ja'
399      ];
400
401      if (homePaths.includes(current) || current === '/') {
402        return false;
403      }
404
405      // Break path to check against top level page
406      var currentArr = current.substring(1).split('/');
407
408      // Microsites that require the full mega menu will need to be accounted for here
409      // This is because of the extra arg in the URL
410      if (currentArr[0] === 'industry') {
411        return false;
412      }
413
414      // Build path to check based on lang value
415      if (currentArr[0] !== lang) {
416        currentItem = '/' + currentArr[0];
417      } else {
418        currentItem = '/' + currentArr[0] + '/' + currentArr[1];
419      }
420
421      $('#main-nav li.dropdown a.toggle').each(function(){
422        var $this = $(this);
423        // if the current path is matches this link, make it active
424        if ($this.attr('href')) {
425          if($this.attr('href').indexOf(currentItem) !== -1){
426            $this.addClass('active-item');
427          }
428        }
429      });
430    }
431  };
432
433  Drupal.behaviors.activeGroupMenuItem = {
434    attach: function (context, settings) {
435      var lang = $('html').attr('lang');
436      var currentItem = '';
437      var current = location.pathname;
438
439      // Skip if were on the homepage of any group lang page
440      var homePaths = [
441        '/',
442        '/fr',
443        '/de',
444        '/ja',
445        '/brookvale-activity-park',
446        '/fr/parc-activites-brookvale',
447        '/industry'
448      ];
449
450      if (homePaths.includes(current)) {
451        return false;
452      }
453
454      // Break path to check against top level page
455      var currentArr = current.substring(1).split('/');
456
457      // Build path to check based on lang value
458      if (currentArr[0] !== lang) {
459        currentItem = '/' + currentArr[0] + '/' + currentArr[1];
460      } else {
461        currentItem = '/' + currentArr[0] + '/' + currentArr[1] + '/' + currentArr[2];
462      }
463
464      if (currentArr[0] === 'industry') {
465        // Microsites that require the full mega menu will need to be accounted for here IE. Industry
466        $('#main-nav li.dropdown a.toggle').each(function(){
467          var $this = $(this);
468          // if the current path is matches this link, make it active
469          if ($this.attr('href')) {
470            if($this.attr('href').indexOf(currentItem) !== -1){
471              $this.addClass('active-item');
472            }
473          }
474        });
475      } else {
476        $('#main-nav li a').each(function () {
477          var $this = $(this);
478          // if the current path is matches this link, make it active
479          if ($this.attr('href')) {
480            if($this.attr('href').indexOf(currentItem) !== -1){
481              $this.addClass('active-item');
482            }
483          }
484        });
485      }
486    }
487  };
488
489  // Sliding Popup Buttons
490  Drupal.behaviors.slidingPopupButtons = {
491    attach: function (context, settings) {
492      if (!context.querySelector('.popups a.btn')) {
493        return false;
494      }
495
496      if ($(window).width() >= 1024) {
497        window.addEventListener('scroll', isHeaderSticky);
498      } else {
499        // Mobile
500        window.addEventListener('scroll', isMobileScroll);
501      }
502
503      var btns = document.querySelectorAll('.popups a.btn');
504      var header = document.getElementById("main-nav");
505      var sticky = header.offsetTop + 62;
506
507      // Scroll actions
508      function isHeaderSticky() {
509        if (window.pageYOffset > sticky) {
510          slidePopupBtns('hide', btns);
511        } else {
512          slidePopupBtns('show', btns);
513        }
514      }
515
516      function isMobileScroll() {
517        // If buttons showing, hide when scrolling
518        slidePopupBtns('hide', btns);
519      }
520
521      // Hover actions
522      btns.forEach(item => {
523        if ($(window).width() >= 1024) {
524          item.addEventListener('mouseover', e => {
525            e.preventDefault();
526            // Popup container
527            var itemLeft = item.parentNode.parentNode.style.left;
528            if (itemLeft === '-113px') {
529              slidePopupBtns('show', item, true);
530            }
531          });
532          item.addEventListener('mouseout', e => {
533            e.preventDefault();
534            // Popup container
535            var itemLeft = item.parentNode.parentNode.style.left;
536            if (itemLeft === '113px' || window.pageYOffset > sticky) {
537              slidePopupBtns('hide', item, true);
538            }
539          });
540        } else {
541          // Mobile
542          slidePopupBtns('hide', item, true);
543          item.addEventListener('touchstart', e => {
544            var itemLeft = item.style.left;
545            var parentitemLeft = item.parentNode.parentNode.style.left;
546            if (parentitemLeft === '-113px' && itemLeft !== '113px') {
547              e.preventDefault();
548              slidePopupBtns('show', item, true);
549            }
550          });
551        }
552      });
553    }
554  };
555
556  function slidePopupBtns(position, btns, hover = false) {
557    if (hover === false) {
558      btns.forEach(item => {
559        if (position === 'hide') {
560          // Popups div
561          item.parentNode.parentNode.style.left = '-113px';
562          if (item.id === 'subscribe-btn') {
563            item.style.left = '-6px';
564          }
565        } else {
566          item.parentNode.style.left = '0';
567          item.parentNode.parentNode.style.left = '0';
568        }
569      });
570    } else {
571      if (position === 'show') {
572        btns.style.left = '113px';
573      } else {
574        btns.parentNode.parentNode.style.left = '-113px';
575        if (btns.id === 'subscribe-btn') {
576          btns.style.left = '-6px';
577        }
578      }
579    }
580  }
581
582  // Adding to video element to test if video is playing
583  Object.defineProperty(HTMLMediaElement.prototype, 'playing', {
584    get: function(){
585      return !!(this.currentTime > 0 && !this.paused && !this.ended && this.readyState > 2);
586    }
587  });
588
589  Drupal.behaviors.videoPlayButtons = {
590    attach: function (context, settings) {
591      if (!context.querySelector('video')) {
592        return false;
593      }
594
595      var videoLoaded = debounce(function() {
596        let videos = context.querySelectorAll('.video video[id^="video"]');
597        let addButtons = false;
598
599        // If playing, we are on desktop/device that can play videos
600        if (videos[0].playing) {
601          addButtons = true;
602        }
603
604        videos.forEach(item => {
605          if (addButtons) {
606            var play = item.nextElementSibling.querySelector('.play');
607            var pause = item.nextElementSibling.querySelector('.pause');
608
609            play.addEventListener('click', function (e) {
610              e.preventDefault();
611              item.play();
612              play.style.display = 'none';
613              pause.style.display = 'inline';
614            });
615
616            pause.addEventListener('click', function (e) {
617              e.preventDefault();
618              item.pause();
619              pause.style.display = 'none';
620              play.style.display = 'inline';
621            });
622          } else {
623            item.nextElementSibling.remove();
624          }
625        });
626      }, 100);
627      window.addEventListener('load',videoLoaded);
628    }
629  };
630
631  Drupal.behaviors.addOTcookieSettings = {
632    attach: function () {
633      // Add cooking settings button
634      let legalFooter = document.querySelector('footer.footer .copy .utility ul');
635      let otButton = document.querySelector('#ot-sdk-btn');
636
637      if (legalFooter && !otButton) {
638        legalFooter.children[0].insertAdjacentHTML(
639          'afterend',
640          '<li><button id="ot-sdk-btn" class="ot-sdk-show-settings">Cookie Settings</button></li>'
641        );
642      }
643    }
644  };
645
646})(jQuery, Drupal, Drupal.debounce, once);

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.